use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class BdbStorageEngineTest method testSimultaneousIterationAndModification.
@Test
public void testSimultaneousIterationAndModification() throws Exception {
// start a thread to do modifications
ExecutorService executor = Executors.newFixedThreadPool(2);
final Random rand = new Random();
final AtomicInteger count = new AtomicInteger(0);
final AtomicBoolean keepRunning = new AtomicBoolean(true);
executor.execute(new Runnable() {
public void run() {
while (keepRunning.get()) {
byte[] bytes = Integer.toString(count.getAndIncrement()).getBytes();
store.put(new ByteArray(bytes), Versioned.value(bytes), null);
count.incrementAndGet();
}
}
});
executor.execute(new Runnable() {
public void run() {
while (keepRunning.get()) {
byte[] bytes = Integer.toString(rand.nextInt(count.get())).getBytes();
store.delete(new ByteArray(bytes), new VectorClock());
count.incrementAndGet();
}
}
});
// wait a bit
while (count.get() < 300) continue;
// now simultaneously do iteration
ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> iter = this.store.entries();
while (iter.hasNext()) iter.next();
iter.close();
keepRunning.set(false);
executor.shutdown();
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
}
use of voldemort.versioning.VectorClock 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.VectorClock in project voldemort by voldemort.
the class ConfigurationStorageEngineTest method testDelete.
@Override
public void testDelete() {
String key = getKey();
Store<String, String, String> store = getStore();
VectorClock c1 = getClock(1, 1);
String value = getValue();
// can't delete something that isn't there
assertTrue(!store.delete(key, c1));
store.put(key, new Versioned<String>(value, c1), null);
assertEquals(1, store.get(key, null).size());
// now delete that version too
assertTrue("Delete failed!", store.delete(key, c1));
assertEquals(0, store.get(key, null).size());
}
use of voldemort.versioning.VectorClock 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.VectorClock 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
}
}
}
Aggregations