4646import java .util .concurrent .TimeUnit ;
4747import java .util .concurrent .atomic .AtomicInteger ;
4848import java .util .function .Predicate ;
49+ import java .util .stream .Stream ;
4950
5051import org .apache .logging .log4j .LogManager ;
5152import org .apache .logging .log4j .Logger ;
5253import org .awaitility .Awaitility ;
5354import org .junit .jupiter .api .AfterEach ;
5455import org .junit .jupiter .api .BeforeAll ;
5556import org .junit .jupiter .api .BeforeEach ;
56- import org .junit .jupiter .api .RepeatedTest ;
57- import org .junit .jupiter .api .Test ;
5857import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
58+ import org .junit .jupiter .params .ParameterizedTest ;
59+ import org .junit .jupiter .params .provider .EnumSource ;
60+ import org .junit .jupiter .params .provider .MethodSource ;
5961
6062class TortureTests {
6163
@@ -141,17 +143,18 @@ Set<Path> stop() throws InterruptedException {
141143
142144 private static final int THREADS = 4 ;
143145
144- @ Test
145- void pressureOnFSShouldNotMissNewFilesAnything () throws InterruptedException , IOException {
146+ @ ParameterizedTest
147+ @ EnumSource (names = { "ALL" , "DIRTY" })
148+ void pressureOnFSShouldNotMissNewFilesAnything (OnOverflow whichFiles ) throws InterruptedException , IOException {
146149 final var root = testDir .getTestDirectory ();
147150 var pool = Executors .newFixedThreadPool (Runtime .getRuntime ().availableProcessors () * 4 );
148151
149152 var io = new IOGenerator (THREADS , root , pool );
150153
151-
152154 var seenCreates = ConcurrentHashMap .<Path >newKeySet ();
153155 var watchConfig = Watcher .watch (testDir .getTestDirectory (), WatchScope .PATH_AND_ALL_DESCENDANTS )
154156 .withExecutor (pool )
157+ .approximate (whichFiles )
155158 .on (ev -> {
156159 var fullPath = ev .calculateFullPath ();
157160 switch (ev .getKind ()) {
@@ -206,8 +209,14 @@ void pressureOnFSShouldNotMissNewFilesAnything() throws InterruptedException, IO
206209
207210 private final int TORTURE_REGISTRATION_THREADS = THREADS * 500 ;
208211
209- @ RepeatedTest (failureThreshold =1 , value = 20 )
210- void manyRegistrationsForSamePath () throws InterruptedException , IOException {
212+ static Stream <OnOverflow > manyRegistrationsForSamePathSource () {
213+ OnOverflow [] values = { OnOverflow .ALL , OnOverflow .DIRTY };
214+ return TestHelper .streamOf (values , 5 );
215+ }
216+
217+ @ ParameterizedTest
218+ @ MethodSource ("manyRegistrationsForSamePathSource" )
219+ void manyRegistrationsForSamePath (OnOverflow whichFiles ) throws InterruptedException , IOException {
211220 var startRegistering = new Semaphore (0 );
212221 var startedWatching = new Semaphore (0 );
213222 var startDeregistring = new Semaphore (0 );
@@ -220,6 +229,7 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException {
220229 try {
221230 var watcher = Watcher
222231 .watch (testDir .getTestDirectory (), WatchScope .PATH_AND_CHILDREN )
232+ .approximate (whichFiles )
223233 .on (e -> seen .add (e .calculateFullPath ()));
224234 startRegistering .acquire ();
225235 try (var c = watcher .start ()) {
@@ -263,8 +273,14 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException {
263273 }
264274 }
265275
266- @ RepeatedTest (failureThreshold =1 , value = 20 )
267- void manyRegisterAndUnregisterSameTime () throws InterruptedException , IOException {
276+ static Stream <OnOverflow > manyRegisterAndUnregisterSameTimeSource () {
277+ OnOverflow [] values = { OnOverflow .ALL , OnOverflow .DIRTY };
278+ return TestHelper .streamOf (values , 5 );
279+ }
280+
281+ @ ParameterizedTest
282+ @ MethodSource ("manyRegisterAndUnregisterSameTimeSource" )
283+ void manyRegisterAndUnregisterSameTime (OnOverflow whichFiles ) throws InterruptedException , IOException {
268284 var startRegistering = new Semaphore (0 );
269285 var startedWatching = new Semaphore (0 );
270286 var stopAll = new Semaphore (0 );
@@ -286,6 +302,7 @@ void manyRegisterAndUnregisterSameTime() throws InterruptedException, IOExceptio
286302 for (int k = 0 ; k < 1000 ; k ++) {
287303 var watcher = Watcher
288304 .watch (testDir .getTestDirectory (), WatchScope .PATH_AND_CHILDREN )
305+ .approximate (whichFiles )
289306 .on (e -> {
290307 if (e .calculateFullPath ().equals (target )) {
291308 seen .add (id );
@@ -328,13 +345,13 @@ void manyRegisterAndUnregisterSameTime() throws InterruptedException, IOExceptio
328345 finally {
329346 stopAll .release (amountOfWatchersActive );
330347 }
331-
332348 }
333349
334- @ Test
350+ @ ParameterizedTest
351+ @ EnumSource (names = { "ALL" , "DIRTY" })
335352 //Deletes can race the filesystem, so you might miss a few files in a dir, if that dir is already deleted
336353 @ EnabledIfEnvironmentVariable (named ="TORTURE_DELETE" , matches ="true" )
337- void pressureOnFSShouldNotMissDeletes () throws InterruptedException , IOException {
354+ void pressureOnFSShouldNotMissDeletes (OnOverflow whichFiles ) throws InterruptedException , IOException {
338355 final var root = testDir .getTestDirectory ();
339356 var pool = Executors .newCachedThreadPool ();
340357
@@ -350,6 +367,7 @@ void pressureOnFSShouldNotMissDeletes() throws InterruptedException, IOException
350367 final var happened = new Semaphore (0 );
351368 var watchConfig = Watcher .watch (testDir .getTestDirectory (), WatchScope .PATH_AND_ALL_DESCENDANTS )
352369 .withExecutor (pool )
370+ .approximate (whichFiles )
353371 .on (ev -> {
354372 events .getAndIncrement ();
355373 happened .release ();
@@ -393,8 +411,6 @@ void pressureOnFSShouldNotMissDeletes() throws InterruptedException, IOException
393411 }
394412 }
395413
396-
397-
398414 private void waitForStable (final AtomicInteger events , final Semaphore happened ) throws InterruptedException {
399415 int lastEventCount = events .get ();
400416 int stableCount = 0 ;
0 commit comments