use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class BdbStorageEngineTest method testPutAndLock.
@Test(timeout = 30000)
public void testPutAndLock() throws Exception {
final ByteArray key = new ByteArray("putAndLock".getBytes());
final byte[] valueBytes = "Lion".getBytes();
store.put(key, new Versioned<byte[]>(valueBytes), null);
// begin the read-modify-write cycle
KeyLockHandle<byte[]> handle = store.getAndLock(key);
// put will block and timeout
try {
store.put(key, new Versioned<byte[]>("Mountain Lion".getBytes()), null);
fail("put(..) should have blocked and timedout");
} catch (PersistenceFailureException pfe) {
// expected
assertTrue("Should have had a LockTimeoutException", pfe.getCause() instanceof LockTimeoutException);
}
// end the read-modify-write cycle
handle.setValues(Lists.newArrayList(new Versioned<byte[]>("Mavericks".getBytes())));
store.putAndUnlock(key, handle);
// get should not block, and read out Mavericks
List<Versioned<byte[]>> vals = store.get(key, null);
assertEquals("Exactly one version", 1, vals.size());
assertEquals("Should read back the version written by putAndUnlock", "Mavericks", new String(vals.get(0).getValue()));
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class BdbStorageEngineTest method testConcurrentReadAndPut.
@Test
public void testConcurrentReadAndPut() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(10);
final CountDownLatch latch = new CountDownLatch(10);
final AtomicBoolean returnedEmpty = new AtomicBoolean(false);
final byte[] keyBytes = "foo".getBytes();
final byte[] valueBytes = "bar".getBytes();
store.put(new ByteArray(keyBytes), new Versioned<byte[]>(valueBytes), null);
for (int i = 0; i < 10; i++) {
executor.submit(new Runnable() {
public void run() {
try {
for (int j = 0; j < 1000 && !returnedEmpty.get(); j++) {
List<Versioned<byte[]>> vals = store.get(new ByteArray(keyBytes), null);
if (vals.size() == 0 && j > 1)
returnedEmpty.set(true);
else {
VectorClock v = (VectorClock) vals.get(0).getVersion();
v.incrementVersion(0, System.currentTimeMillis());
try {
store.put(new ByteArray(keyBytes), new Versioned<byte[]>(valueBytes, v), null);
} catch (ObsoleteVersionException e) {
// Ignore these
}
}
}
} finally {
latch.countDown();
}
}
});
}
latch.await();
assertFalse("Should not have seen any empty results", returnedEmpty.get());
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MetadataStoreTest method testSimpleGetAndPut.
@Test
public void testSimpleGetAndPut() {
for (int i = 0; i <= TEST_RUNS; i++) {
ByteArray key = getValidKey();
VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key), clock.incremented(0, 1));
metadataStore.put(key, value, null);
checkValues(value, metadataStore.get(key, null), key);
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MetadataStoreTest method testObsoletePut.
@Test
public void testObsoletePut() {
for (int i = 0; i <= TEST_RUNS; i++) {
ByteArray key = getValidKey();
VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key), clock.incremented(0, 1));
try {
metadataStore.put(key, value, null);
assertTrue(true);
metadataStore.put(key, value, null);
fail();
} catch (ObsoleteVersionException e) {
// expected ObsoleteVersionException
}
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class MetadataStoreTest method testSynchronousPut.
@Test
public void testSynchronousPut() {
for (int i = 0; i <= TEST_RUNS; i++) {
ByteArray key = getValidKey();
VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
Versioned<byte[]> value1 = new Versioned<byte[]>(getValidValue(key), clock.incremented(1, 1));
Versioned<byte[]> value2 = new Versioned<byte[]>(getValidValue(key), clock.incremented(2, 1));
metadataStore.put(key, value1, null);
metadataStore.put(key, value2, null);
assertEquals("Only one metadata value should return", 1, metadataStore.get(key, null).size());
checkValues(value2, metadataStore.get(key, null), key);
}
}
Aggregations