}
private void testLockMigrationDuringPrepare(final Object key) throws Exception {
ControlledRpcManager controlledRpcManager = installControlledRpcManager();
controlledRpcManager.blockBefore(PrepareCommand.class);
final DummyTransactionManager tm = dummyTm(ORIGINATOR_INDEX);
Future<DummyTransaction> f = fork(new Callable<DummyTransaction>() {
@Override
public DummyTransaction call() throws Exception {
tm.begin();
originatorCache.put(key, "value");
DummyTransaction tx = tm.getTransaction();
boolean success = tx.runPrepare();
assertTrue(success);
tm.suspend();
return tx;
}
});
// Allow the tx thread to send the prepare command to the owners
Thread.sleep(2000);
log.trace("Lock transfer happens here");
killCache();
log.trace("Allow the prepare RPC to proceed");
controlledRpcManager.stopBlocking();
// Ensure the prepare finished on the other node
DummyTransaction tx = f.get();
log.tracef("Prepare finished");
checkNewTransactionFails(key);
log.trace("About to commit existing transactions.");
tm.resume(tx);
tx.runCommitTx();
// read the data from the container, just to make sure all replicas are correctly set
checkValue(key, "value");
}