Stabilizing JEChangeNumberIndexDBTest.testClear().
Here is the failure scenario for this test (with one CPU):
t1 (test thread) t2 (CNIndexDB purge thread)
---------------- ---------------------------
| |
| v
| JEChangeNumberIndexDB
| run()
| trim()
| clear(null) <- entered, but not completed
v
ChangeNumberIndexDB
setPurgeDelay(0);
addRecord(1)
addRecord(2)
addRecord(3)
| |
| +--> executes the clear()
v
getFirstRecord() <- BOOM NullPointerException!
Ensured the CNIndexDB is not trimmed until we explicitly test it:
to do this, ensured the thread is only started when needed by the test.
Also took the occasion to ensure a faster shutdown for the CNIndexDB trimming thread.
JEChangeNumberIndexDB.java:
Ensured we use volatile and AtomicBoolean.
Renamed thread field to trimmingThread.
Extracted method startTrimmingThread().
In trim(), added an AtomicBoolean parameter.
Added methods clear(DN, AtomicBoolean shutdown) and mustShutdown() to ensure faster shutdown.
JEChangelogDB.java:
Called JEChangeNumberIndexDB.startTrimmingThread() after creating the JEChangeNumberIndexDB instance.
JEChangeNumberIndexDBTest.java:
Extracted constants.
In testTrim(), called JEChangeNumberIndexDB.startTrimmingThread().
In testClear(), removed