From f03c73b1b65bcb56647534ae22d96ec271a36f35 Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Wed, 13 Jan 2016 15:49:42 +0000 Subject: [PATCH 1/7] Remove LogTooLongException Remove uncaught exception, write a test case, fail silently like other libraries --- .../java/com/logentries/net/AsyncLogger.java | 2 +- .../logentries/net/LogTooLongException.java | 7 ------- .../com/logentries/net/AsyncLoggerTest.java | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) delete mode 100644 src/main/java/com/logentries/net/LogTooLongException.java diff --git a/src/main/java/com/logentries/net/AsyncLogger.java b/src/main/java/com/logentries/net/AsyncLogger.java index d767297..3b6f6f9 100644 --- a/src/main/java/com/logentries/net/AsyncLogger.java +++ b/src/main/java/com/logentries/net/AsyncLogger.java @@ -419,7 +419,7 @@ public void addLineToQueue(String line) { } private void addLineToQueue (String line, int limit) { - if (limit == 0) { throw new LogTooLongException(); } + if (limit == 0) { return; } //// Check credentials only if logs are sent to LE directly. // Check that we have all parameters set and socket appender running. diff --git a/src/main/java/com/logentries/net/LogTooLongException.java b/src/main/java/com/logentries/net/LogTooLongException.java deleted file mode 100644 index 80bbf8a..0000000 --- a/src/main/java/com/logentries/net/LogTooLongException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.logentries.net; - -/** - * Thrown when a log + timestamps etc. is longer than {@link com.logentries.net.AsyncLogger#LOG_LENGTH_LIMIT} chars. - */ -public class LogTooLongException extends RuntimeException { -} diff --git a/src/test/java/com/logentries/net/AsyncLoggerTest.java b/src/test/java/com/logentries/net/AsyncLoggerTest.java index 61ac859..b829d7c 100644 --- a/src/test/java/com/logentries/net/AsyncLoggerTest.java +++ b/src/test/java/com/logentries/net/AsyncLoggerTest.java @@ -1,6 +1,9 @@ package com.logentries.net; import org.junit.Test; + +import java.util.Random; + import static org.junit.Assert.*; public class AsyncLoggerTest { @@ -17,6 +20,21 @@ public void testGetAndSetToken() } @Test + public void testOversizeMessage() + { + AsyncLogger async = new AsyncLogger(); + char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); + StringBuilder sb = new StringBuilder(); + Random random = new Random(); + for (int i = 0; i < 2100000; i++) { + char c = chars[random.nextInt(chars.length)]; + sb.append(c); + } + String output = sb.toString(); + async.addLineToQueue(output); + } + + @Test public void testGetAndSetHttpPut() { AsyncLogger async = new AsyncLogger(); From 85ac2bddda96e8ba8186f50b44758b54f8a7636e Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Thu, 23 Jun 2016 17:06:13 +0100 Subject: [PATCH 2/7] increase vm heap size --- pom.xml | 8 ++++++ .../java/com/logentries/net/AsyncLogger.java | 28 ++++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 08d0b7d..92ade63 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,14 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + -Xms1024m -Xmx2048m + + diff --git a/src/main/java/com/logentries/net/AsyncLogger.java b/src/main/java/com/logentries/net/AsyncLogger.java index 3b6f6f9..5676b05 100644 --- a/src/main/java/com/logentries/net/AsyncLogger.java +++ b/src/main/java/com/logentries/net/AsyncLogger.java @@ -270,8 +270,8 @@ public int getDataHubPort() { * * @param logHostName */ - public void setLogHostName(boolean logHostName) { - this.logHostName = logHostName; + public void setLogHostName(boolean logHostName) { + this.logHostName = logHostName; } /** @@ -279,8 +279,8 @@ public void setLogHostName(boolean logHostName) { * * @return logHostName switch value */ - public boolean getLogHostName() { - return this.logHostName; + public boolean getLogHostName() { + return this.logHostName; } /** @@ -288,8 +288,8 @@ public boolean getLogHostName() { * * @param hostName */ - public void setHostName(String hostName) { - this.hostName = hostName; + public void setHostName(String hostName) { + this.hostName = hostName; } /** @@ -297,8 +297,8 @@ public void setHostName(String hostName) { * * @return Host name field value */ - public String getHostName() { - return this.hostName; + public String getHostName() { + return this.hostName; } /** @@ -306,8 +306,8 @@ public String getHostName() { * * @param logID */ - public void setLogID(String logID) { - this.logID = logID; + public void setLogID(String logID) { + this.logID = logID; } /** @@ -315,8 +315,8 @@ public void setLogID(String logID) { * * @return logID field value */ - public String getLogID() { - return this.logID; + public String getLogID() { + return this.logID; } /** @@ -419,7 +419,9 @@ public void addLineToQueue(String line) { } private void addLineToQueue (String line, int limit) { - if (limit == 0) { return; } + if (limit == 0) { + dbg("Message longer than " + RECURSION_LIMIT); + return; } //// Check credentials only if logs are sent to LE directly. // Check that we have all parameters set and socket appender running. From 0c637b1adef1478a3cf69a869944523008c3b00b Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Thu, 23 Jun 2016 17:20:38 +0100 Subject: [PATCH 3/7] shutdown VM --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 92ade63..a5e7205 100644 --- a/pom.xml +++ b/pom.xml @@ -75,9 +75,11 @@ org.apache.maven.plugins maven-surefire-plugin + 2.19.1 -Xms1024m -Xmx2048m + kill From ddd643376f17ee9429d2d8b7ffef5f3cf0509463 Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Thu, 23 Jun 2016 17:35:01 +0100 Subject: [PATCH 4/7] remove "kill" --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index a5e7205..fed9f7a 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,6 @@ -Xms1024m -Xmx2048m - kill From 353a87ecbb4a325672d32f97bdfb7e8a8edf6eea Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Fri, 24 Jun 2016 11:33:07 +0100 Subject: [PATCH 5/7] travis workaround test --- .travis.yml | 3 +++ pom.xml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6fbc77b..bbfdc37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,6 @@ jdk: - openjdk7 - oraclejdk7 - oraclejdk8 +before_install: + # override default MAVEN_OPTS + - echo "MAVEN_OPTS='-Xms1g -Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc \ No newline at end of file diff --git a/pom.xml b/pom.xml index fed9f7a..2c9c01c 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ 2.19.1 - -Xms1024m -Xmx2048m + ${surefire.jvm.params} From a939b56afa0a0c771f1d5466324b54f852937e73 Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Fri, 24 Jun 2016 11:44:54 +0100 Subject: [PATCH 6/7] travis workaround --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 2c9c01c..99e0212 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ 2.19.1 + 1 ${surefire.jvm.params} From e77b9067d4037a05833a5d257b0727bec85cf937 Mon Sep 17 00:00:00 2001 From: Ardi Mehist Date: Fri, 24 Jun 2016 11:59:42 +0100 Subject: [PATCH 7/7] travis --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bbfdc37..26af1df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,9 @@ jdk: - oraclejdk8 before_install: # override default MAVEN_OPTS - - echo "MAVEN_OPTS='-Xms1g -Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc \ No newline at end of file + - echo "MAVEN_OPTS='-Xms1g -Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc + # Fix OpenJDK buffer overflow + - cat /etc/hosts # optionally check the content *before* + - sudo hostname "$(hostname | cut -c1-63)" + - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts + - cat /etc/hosts # optionally check the content *after* \ No newline at end of file