VMLens lets you unit test multi-threaded, concurrent Java
Simply surround your multi-threaded, concurrent test with a loop iterating over all interleavings:
import com.vmlens.api.AllInterleavings;
public class TestNonVolatileField {
private int j = 0;
@Test
public void testUpdate() throws InterruptedException {
try(AllInterleavings allInterleavings = new AllInterleavings("testNonVolatileField")) {
while (allInterleavings.hasNext()) {
Thread first = new Thread() {
@Override
public void run() {
j++;
}
};
first.start();
j++;
first.join();
}
}
}
}
Got 10 minutes?
Why Unit Tests?
Imagine we had no unit tests. No JUnit or TestNG. This would make refactoring cumbersome. And test-driven design would be impossible. This is the state for concurrent, multi-threaded Java without VMLens.
VMLens lets you write unit tests for concurrent, multi-threaded Java. The same way you write unit tests for normal Java. This allows you to use TDD to write concurrent, multi-threaded Java. And refactor your concurrent code guided by tests.
How does it work?
VMLens runs as a bytecode agent. VMLens traces all synchronization actions and field accesses. This lets VMLens calculate all thread interleavings and find data races.