logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: [3/5] logging-log4j2 git commit: fix spuriously failing tests
Date Tue, 23 Feb 2016 18:20:12 GMT
I'm not sure how these Rules work and in which order they execute...
Perhaps there is a better way to address this than what I did.

On Wed, Feb 24, 2016 at 3:14 AM, Gary Gregory <garydgregory@gmail.com>
wrote:

> Should we use a LoggerContextRule here?
>
> Gary
> ---------- Forwarded message ----------
> From: <rpopma@apache.org>
> Date: Feb 23, 2016 9:48 AM
> Subject: [3/5] logging-log4j2 git commit: fix spuriously failing tests
> To: <commits@logging.apache.org>
> Cc:
>
> fix spuriously failing tests
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/047565e8
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/047565e8
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/047565e8
>>
>> Branch: refs/heads/master
>> Commit: 047565e8928b0c9893c25ee92ffdf48dbcd6965c
>> Parents: 5fea6c4
>> Author: rpopma <rpopma@apache.org>
>> Authored: Wed Feb 24 02:46:04 2016 +0900
>> Committer: rpopma <rpopma@apache.org>
>> Committed: Wed Feb 24 02:46:04 2016 +0900
>>
>> ----------------------------------------------------------------------
>>  .../routing/PropertiesRoutingAppenderTest.java       |  1 +
>>  .../core/appender/routing/RoutingAppenderTest.java   |  1 +
>>  .../routing/RoutingAppenderWithPurgingTest.java      | 13 +++++++------
>>  .../appender/routing/RoutingDefaultAppenderTest.java |  1 +
>>  .../org/apache/logging/log4j/junit/CleanFiles.java   | 15 +++++++++++----
>>  5 files changed, 21 insertions(+), 10 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/047565e8/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/PropertiesRoutingAppenderTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/PropertiesRoutingAppenderTest.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/PropertiesRoutingAppenderTest.java
>> index 81910fc..a02a9d1 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/PropertiesRoutingAppenderTest.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/PropertiesRoutingAppenderTest.java
>> @@ -58,6 +58,7 @@ public class PropertiesRoutingAppenderTest {
>>      @After
>>      public void tearDown() throws Exception {
>>          this.app.clear();
>> +        this.init.getContext().stop();
>>      }
>>
>>      @Test
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/047565e8/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
>> index 6f1613a..85f704e 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
>> @@ -57,6 +57,7 @@ public class RoutingAppenderTest {
>>      @After
>>      public void tearDown() throws Exception {
>>          this.app.clear();
>> +        this.init.getContext().stop();
>>      }
>>
>>      @Test
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/047565e8/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java
>> index 49ffabe..9920690 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java
>> @@ -43,7 +43,7 @@ public class RoutingAppenderWithPurgingTest {
>>      private static final String MANUAL_LOG_FILE1 =
>> "target/routing-purge-manual/routingtest-1.log";
>>      private static final String MANUAL_LOG_FILE2 =
>> "target/routing-purge-manual/routingtest-2.log";
>>      private static final String MANUAL_LOG_FILE3 =
>> "target/routing-purge-manual/routingtest-3.log";
>> -
>> +
>>
>>      private ListAppender app;
>>      private RoutingAppender routingAppenderIdle;
>> @@ -54,9 +54,9 @@ public class RoutingAppenderWithPurgingTest {
>>      public LoggerContextRule init = new LoggerContextRule(CONFIG);
>>
>>      @Rule
>> -    public CleanFiles files = new CleanFiles(IDLE_LOG_FILE1,
>> IDLE_LOG_FILE2, IDLE_LOG_FILE3,
>> +    public CleanFiles files = new CleanFiles(IDLE_LOG_FILE1,
>> IDLE_LOG_FILE2, IDLE_LOG_FILE3,
>>                 MANUAL_LOG_FILE1, MANUAL_LOG_FILE2, MANUAL_LOG_FILE3);
>> -
>> +
>>
>>      @Before
>>      public void setUp() throws Exception {
>> @@ -70,6 +70,7 @@ public class RoutingAppenderWithPurgingTest {
>>      @After
>>      public void tearDown() throws Exception {
>>          this.app.clear();
>> +        this.init.getContext().stop();
>>      }
>>
>>      @Test(timeout = 5000)
>> @@ -85,7 +86,7 @@ public class RoutingAppenderWithPurgingTest {
>>          EventLogger.logEvent(msg);
>>          String[] files = {IDLE_LOG_FILE1, IDLE_LOG_FILE2,
>> IDLE_LOG_FILE3, MANUAL_LOG_FILE1, MANUAL_LOG_FILE2, MANUAL_LOG_FILE3};
>>          assertFileExistance(files);
>> -
>> +
>>          assertEquals("Incorrect number of appenders with
>> IdlePurgePolicy.", 3, routingAppenderIdle.getAppenders().size());
>>          assertEquals("Incorrect number of appenders with IdlePurgePolicy
>> with HangingAppender.",
>>                  3,
>> routingAppenderIdleWithHangingAppender.getAppenders().size());
>> @@ -96,7 +97,7 @@ public class RoutingAppenderWithPurgingTest {
>>
>>          assertEquals("Incorrect number of appenders with
>> IdlePurgePolicy.", 1, routingAppenderIdle.getAppenders().size());
>>          assertEquals("Incorrect number of appenders with manual purge.",
>> 3, routingAppenderManual.getAppenders().size());
>> -
>> +
>>          routingAppenderManual.deleteAppender("1");
>>          routingAppenderManual.deleteAppender("2");
>>          routingAppenderManual.deleteAppender("3");
>> @@ -104,7 +105,7 @@ public class RoutingAppenderWithPurgingTest {
>>          assertEquals("Incorrect number of appenders with
>> IdlePurgePolicy.", 1, routingAppenderIdle.getAppenders().size());
>>          assertEquals("Incorrect number of appenders with manual purge.",
>> 0, routingAppenderManual.getAppenders().size());
>>      }
>> -
>> +
>>      private void assertFileExistance(String... files) {
>>         for (String file : files) {
>>                         assertTrue("File should exist - " + file + " file
>> ", new File(file).exists());
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/047565e8/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java
>> index a84460c..44d52e0 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingDefaultAppenderTest.java
>> @@ -56,6 +56,7 @@ public class RoutingDefaultAppenderTest {
>>          if (app != null) {
>>              app.clear();
>>          }
>> +        this.init.getContext().stop();
>>      }
>>
>>      @Test
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/047565e8/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
>> index 36386af..6713aea 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
>> @@ -31,6 +31,7 @@ import static org.junit.Assert.*;
>>   * A JUnit test rule to automatically delete certain files after a test
>> is run.
>>   */
>>  public class CleanFiles extends ExternalResource {
>> +    private static final int MAX_TRIES = 10;
>>      private final List<File> files;
>>
>>      public CleanFiles(final File... files) {
>> @@ -46,11 +47,17 @@ public class CleanFiles extends ExternalResource {
>>
>>      private void clean() {
>>          for (final File file : files) {
>> -            if (file.exists()) {
>> +            for (int i = 0; i < MAX_TRIES; i++) {
>> +                if (file.exists()) {
>> +                    try {
>> +
>> FileSystems.getDefault().provider().delete(file.toPath());
>> +                    } catch (IOException e) {
>> +                        fail(e.toString());
>> +                    }
>> +                }
>>                  try {
>> -
>> FileSystems.getDefault().provider().delete(file.toPath());
>> -                } catch (IOException e) {
>> -                    fail(e.toString());
>> +                    Thread.sleep(200);
>> +                } catch (InterruptedException e) {
>>                  }
>>              }
>>          }
>>
>>

Mime
View raw message