* Starts writer thread and waits for it to start the insert.
*/
private void startInsert(final int keyVal, final int dataVal)
throws DatabaseException, InterruptedException {
LockStats origStats = env.getLockStats(null);
insertFinished = false;
writerThread = new JUnitThread("Writer") {
public void testBody()
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
IntegerBinding.intToEntry(keyVal, key);
IntegerBinding.intToEntry(dataVal, data);
Transaction writerTxn = env.beginTransaction(null, txnConfig);
if (dups) {
status = db.putNoDupData(writerTxn, key, data);
} else {
status = db.putNoOverwrite(writerTxn, key, data);
}
assertEquals(OperationStatus.SUCCESS, status);
writerTxn.commitNoSync();
insertFinished = true;
}
};
writerThread.start();
long startTime = System.currentTimeMillis();
while (true) {
/* Give some time to the writer thread. */
Thread.yield();
Thread.sleep(10);
if (System.currentTimeMillis() - startTime > MAX_INSERT_MILLIS) {
fail("Timeout doing insert");
}
if (txnSerializable) {
/* Wait for the insert to block. */
LockStats stats = env.getLockStats(null);
if (stats.getNWaiters() > origStats.getNWaiters()) {
break;
}
} else {
/* Wait for the operation to complete. */