use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class AbstractStorageEngineTest method testKeyIterationWithSerialization.
@Test
public void testKeyIterationWithSerialization() {
StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
StorageEngine<String, String, String> stringStore = new SerializingStorageEngine<String, String, String>(store, new StringSerializer(), new StringSerializer(), new StringSerializer());
Map<String, String> vals = ImmutableMap.of("a", "a", "b", "b", "c", "c", "d", "d", "e", "e");
for (Map.Entry<String, String> entry : vals.entrySet()) stringStore.put(entry.getKey(), new Versioned<String>(entry.getValue()), null);
ClosableIterator<String> iter = stringStore.keys();
int count = 0;
while (iter.hasNext()) {
String key = iter.next();
assertTrue(vals.containsKey(key));
count++;
}
assertEquals(count, vals.size());
iter.close();
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class AbstractStorageEngineTest method testIterationWithSerialization.
@Test
public void testIterationWithSerialization() {
StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
StorageEngine<String, String, String> stringStore = SerializingStorageEngine.wrap(store, new StringSerializer(), new StringSerializer(), new StringSerializer());
Map<String, String> vals = ImmutableMap.of("a", "a", "b", "b", "c", "c", "d", "d", "e", "e");
for (Map.Entry<String, String> entry : vals.entrySet()) stringStore.put(entry.getKey(), new Versioned<String>(entry.getValue()), null);
ClosableIterator<Pair<String, Versioned<String>>> iter = stringStore.entries();
int count = 0;
while (iter.hasNext()) {
Pair<String, Versioned<String>> keyAndVal = iter.next();
assertTrue(vals.containsKey(keyAndVal.getFirst()));
assertEquals(vals.get(keyAndVal.getFirst()), keyAndVal.getSecond().getValue());
count++;
}
assertEquals(count, vals.size());
iter.close();
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class AbstractStorageEngineTest method testMultiVersionPuts.
@Test
public void testMultiVersionPuts() {
StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
try {
// Insert with concurrent versions
ByteArray key = new ByteArray("mvpKey1".getBytes());
List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1".getBytes(), 1));
vals.add(TestUtils.getVersioned("val2".getBytes(), 2));
vals.add(TestUtils.getVersioned("val3".getBytes(), 3));
List<Versioned<byte[]>> obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Should have all 3 versions stored", 3, store.get(key, null).size());
assertTrue("All concurrent versions expected", TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
List<Versioned<byte[]>> saveVals = vals;
// Insert with some concurrent and some obsolete versions
key = new ByteArray("mvpKey2".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1".getBytes(), 1));
vals.add(TestUtils.getVersioned("val2".getBytes(), 2));
vals.add(TestUtils.getVersioned("val3".getBytes(), 1, 1));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any obsolete versions..", obsoletes.size() == 0);
assertEquals("Should have 2 versions stored, with 1:2 superceding 1:1", 2, store.get(key, null).size());
vals.remove(0);
assertTrue("Should have 2 versions stored, with 1:2 superceding 1:1", TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
// Update of concurrent versions, on top of concurrent versions
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val4".getBytes(), 4));
vals.add(TestUtils.getVersioned("val5".getBytes(), 5));
vals.add(TestUtils.getVersioned("val6".getBytes(), 6));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Should have all 6 versions stored", 6, store.get(key, null).size());
vals.addAll(saveVals);
assertTrue("All 6 concurrent versions expected", TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
saveVals = vals;
// Update of some obsolete versions, on top of concurrent versions
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
// one obsolete version
Versioned<byte[]> obsoleteVersion = TestUtils.getVersioned("val4-obsolete".getBytes(), 4);
vals.add(obsoleteVersion);
// one new concurrent version
vals.add(TestUtils.getVersioned("val7".getBytes(), 7));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should be one version rejected..", obsoletes.size() == 1);
assertEquals("Obsolete's version should be 4:1", obsoleteVersion, obsoletes.get(0));
assertEquals("Should have all 7 versions stored", 7, store.get(key, null).size());
vals.remove(0);
vals.addAll(saveVals);
assertTrue("All 7 concurrent versions expected", TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
// super version, makes all versions obsolete
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1234567".getBytes(), 1, 2, 3, 4, 5, 6, 7));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Exactly one version to be stored", 1, store.get(key, null).size());
assertTrue("Exactly one version to be stored", TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
} catch (UnsupportedOperationException uoe) {
// expected if the storage engine does not support multi version
// puts
System.err.println("Multi version puts not supported in test " + this.getClass().getName());
}
}
use of voldemort.utils.ByteArray 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.utils.ByteArray 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));
}
Aggregations