@@ -112,24 +112,27 @@ public void testCachedBytesReadsAndWrites() {
112
112
113
113
final long cachedBytesWriteCount = TestUtils .numberOfRanges (length , rangeSize .getBytes ());
114
114
115
- assertThat (inputStats .getCachedBytesWritten (), notNullValue ());
116
- assertThat (inputStats .getCachedBytesWritten ().total (), equalTo (length ));
117
- assertThat (inputStats .getCachedBytesWritten ().count (), equalTo (cachedBytesWriteCount ));
118
- assertThat (inputStats .getCachedBytesWritten ().min (), greaterThan (0L ));
119
- assertThat (
120
- inputStats .getCachedBytesWritten ().max (),
121
- (length < rangeSize .getBytes ()) ? equalTo (length ) : equalTo (rangeSize .getBytes ())
122
- );
123
- assertThat (
124
- inputStats .getCachedBytesWritten ().totalNanoseconds (),
125
- allOf (
126
- // each read takes at least FAKE_CLOCK_ADVANCE_NANOS time
127
- greaterThanOrEqualTo (FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount ),
128
-
129
- // worst case: we start all reads before finishing any of them
130
- lessThanOrEqualTo (FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount )
131
- )
132
- );
115
+ // cache writes are executed in a different thread pool and can take some time to be processed
116
+ assertBusy (() -> {
117
+ assertThat (inputStats .getCachedBytesWritten (), notNullValue ());
118
+ assertThat (inputStats .getCachedBytesWritten ().total (), equalTo (length ));
119
+ assertThat (inputStats .getCachedBytesWritten ().count (), equalTo (cachedBytesWriteCount ));
120
+ assertThat (inputStats .getCachedBytesWritten ().min (), greaterThan (0L ));
121
+ assertThat (
122
+ inputStats .getCachedBytesWritten ().max (),
123
+ (length < rangeSize .getBytes ()) ? equalTo (length ) : equalTo (rangeSize .getBytes ())
124
+ );
125
+ assertThat (
126
+ inputStats .getCachedBytesWritten ().totalNanoseconds (),
127
+ allOf (
128
+ // each read takes at least FAKE_CLOCK_ADVANCE_NANOS time
129
+ greaterThanOrEqualTo (FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount ),
130
+
131
+ // worst case: we start all reads before finishing any of them
132
+ lessThanOrEqualTo (FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount )
133
+ )
134
+ );
135
+ });
133
136
134
137
assertThat (inputStats .getCachedBytesRead (), notNullValue ());
135
138
assertThat (inputStats .getCachedBytesRead ().total (), greaterThanOrEqualTo (length ));
@@ -146,7 +149,7 @@ public void testCachedBytesReadsAndWrites() {
146
149
assertCounter (inputStats .getOptimizedBytesRead (), 0L , 0L , 0L , 0L );
147
150
assertThat (inputStats .getOptimizedBytesRead ().totalNanoseconds (), equalTo (0L ));
148
151
149
- } catch (IOException e ) {
152
+ } catch (Exception e ) {
150
153
throw new AssertionError (e );
151
154
}
152
155
});
@@ -337,15 +340,17 @@ public void testReadBytesContiguously() {
337
340
}
338
341
}
339
342
340
- // cache file has been written in a single chunk
341
- assertCounter (inputStats .getCachedBytesWritten (), input .length (), 1L , input .length (), input .length ());
342
- assertThat (inputStats .getCachedBytesWritten ().totalNanoseconds (), equalTo (FAKE_CLOCK_ADVANCE_NANOS ));
343
+ // cache file has been written in a single chunk in a different thread pool and can take some time to be processed
344
+ assertBusy (() -> {
345
+ assertCounter (inputStats .getCachedBytesWritten (), input .length (), 1L , input .length (), input .length ());
346
+ assertThat (inputStats .getCachedBytesWritten ().totalNanoseconds (), equalTo (FAKE_CLOCK_ADVANCE_NANOS ));
347
+ });
343
348
344
349
assertCounter (inputStats .getNonContiguousReads (), 0L , 0L , 0L , 0L );
345
350
assertCounter (inputStats .getDirectBytesRead (), 0L , 0L , 0L , 0L );
346
351
assertThat (inputStats .getDirectBytesRead ().totalNanoseconds (), equalTo (0L ));
347
352
348
- } catch (IOException e ) {
353
+ } catch (Exception e ) {
349
354
throw new AssertionError (e );
350
355
}
351
356
});
0 commit comments