assertFalse("Should not have seen any empty results", returnedEmpty.get());
}
@Test(timeout = 30000)
public void testGetAndLock() throws Exception {
final ByteArray key = new ByteArray("getAndLock".getBytes());
final byte[] valueBytes = "bar".getBytes();
store.put(key, new Versioned<byte[]>(valueBytes), null);
KeyLockHandle<byte[]> handle = store.getAndLock(key);
// get will block and timeout
try {
store.get(key, null);
fail("get(..) should have blocked and timedout");
} catch(PersistenceFailureException pfe) {
// expected
assertTrue("Should have had a LockTimeoutException",
pfe.getCause() instanceof LockTimeoutException);
}
// let go of the key lock
store.releaseLock(handle);
// get should not block, since the lock has been released
List<Versioned<byte[]>> vals = store.get(key, null);
assertEquals("Should read back the version previously written", 1, vals.size());
assertEquals("Should read back the version previously written",
new ByteArray(valueBytes),
new ByteArray(vals.get(0).getValue()));
}