Class AllInterleavings

  • All Implemented Interfaces:

    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();
            secondId = uniqueId.nextId();
            assertTrue(firstId != secondId);