1818
1919import static org .assertj .core .api .Assertions .assertThat ;
2020import static org .awaitility .Awaitility .waitAtMost ;
21- import static org .junit .jupiter .api .Assertions .fail ;
2221
23- import java .io .IOException ;
2422import java .nio .file .Files ;
2523import java .nio .file .Path ;
2624import java .nio .file .Paths ;
@@ -70,7 +68,7 @@ void testAppender(final LoggerContext ctx, @Named("RollingFile") final RollingFi
7068 private static class RolloverDelay implements RolloverListener {
7169 private final Logger logger = StatusLogger .getLogger ();
7270 private volatile CountDownLatch latch ;
73- private volatile AssertionError assertion ;
71+ private volatile Exception verificationFailure ;
7472
7573 public RolloverDelay (final RollingFileManager manager ) {
7674 latch = new CountDownLatch (1 );
@@ -80,9 +78,9 @@ public RolloverDelay(final RollingFileManager manager) {
8078 public void waitForRollover () {
8179 waitAtMost (5 , TimeUnit .SECONDS )
8280 .alias ("Rollover timeout" )
83- .until (() -> latch .getCount () == 0 || assertion != null );
84- if (assertion != null ) {
85- throw assertion ;
81+ .until (() -> latch .getCount () == 0 || verificationFailure != null );
82+ if (verificationFailure != null ) {
83+ throw new RuntimeException ( verificationFailure ) ;
8684 }
8785 }
8886
@@ -102,16 +100,15 @@ public void rolloverComplete(final String fileName) {
102100 final Path path = Paths .get (fileName );
103101 final Matcher matcher = FILE_PATTERN .matcher (path .getFileName ().toString ());
104102 assertThat (matcher ).as ("Rolled file" ).matches ();
105- try {
103+ waitAtMost ( 2 , TimeUnit . SECONDS ). untilAsserted (() -> {
106104 final List <String > lines = Files .readAllLines (path );
107105 assertThat (lines ).isNotEmpty ();
108106 assertThat (lines .get (0 )).startsWith (matcher .group (1 ));
109- } catch (final IOException ex ) {
110- fail ("Unable to read file " + fileName + ": " + ex .getMessage ());
111- }
107+ });
112108 latch .countDown ();
113- } catch (final AssertionError ex ) {
114- assertion = ex ;
109+ } catch (final Exception ex ) {
110+ verificationFailure =
111+ new RuntimeException ("Rollover completion verification failure for file: " + fileName , ex );
115112 }
116113 }
117114 }
0 commit comments