Class AllInterleavings

  • All Implemented Interfaces:
    AutoCloseable

    public class AllInterleavings
    extends Object
    implements AutoCloseable
    The class AllInterleavings let you test all thread interleavings for your test. Enclose your test in a while loop to iterate through all thread interleavings like in the following example:
    
     try (AllInterleavings allInterleavings = 
        new AllInterleavings("ConcurrencyTestUniqueId");) {
        while (allInterleavings.hasNext()) {
            firstId  = 0L;
            secondId = 0L;
            UniqueId uniqueId = new UniqueId();
            Thread first = new Thread(() -> {
                firstId = uniqueId.nextId();
            });
            first.start();
            secondId = uniqueId.nextId();
            first.join();
            assertTrue(firstId != secondId);
        }
      }