Repository: tomee Updated Branches: refs/heads/master 45cb0ee73 -> a369b8c6e
retry assertion in order to make sure we give enough time for the system to act accordingly (create or remove file) Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a369b8c6 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a369b8c6 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a369b8c6 Branch: refs/heads/master Commit: a369b8c6e4f36ecdcd73f1505dc1aee6d6397ce7 Parents: 45cb0ee Author: Thiago Veronezi <[email protected]> Authored: Fri Nov 20 17:49:55 2015 -0500 Committer: Thiago Veronezi <[email protected]> Committed: Fri Nov 20 17:49:55 2015 -0500 ---------------------------------------------------------------------- .../jul/handler/rotating/ArchivingTest.java | 31 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/a369b8c6/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java index 4ca4778..b36d008 100644 --- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java +++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java @@ -27,6 +27,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -95,8 +96,12 @@ public class ArchivingTest { handler.close(); final File logGzip = new File("target/ArchivingTest-" + format + "/logs/archives/test.2015-09-01.0.log." + format); - assertTrue(logGzip.getAbsolutePath(), logGzip.isFile()); - + withRetry(5, 1, new Runnable() { + @Override + public void run() { + assertTrue(logGzip.getAbsolutePath(), logGzip.isFile()); + } + }); // note: size depends on the date so just use a > min if ("gzip".equals(format)) { try (final GZIPInputStream gis = new GZIPInputStream(new FileInputStream("target/ArchivingTest-gzip/logs/archives/test.2015-09-01.0.log.gzip"))) { @@ -181,8 +186,28 @@ public class ArchivingTest { } handler.publish(new LogRecord(Level.INFO, string10chars)); // will trigger the purging handler.close(); + withRetry(5, 1, new Runnable() { + @Override + public void run() { + assertFalse(logArchive.getAbsolutePath() + " was purged", logArchive.exists()); + } + }); + } - assertFalse(logArchive.getAbsolutePath() + " was purged", logArchive.exists()); + private void withRetry(int countDown, long timeout, Runnable assertCallback) { + try { + assertCallback.run(); + } catch (AssertionError e) { + if (countDown < 1) { + throw e; + } + try { + TimeUnit.SECONDS.sleep(timeout); + } catch (InterruptedException e1) { + Thread.interrupted(); + } + withRetry(--countDown, timeout, assertCallback); + } } private static void clean(final String base) {
