use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class AbstractStorageEngineTest method testTruncate.
@Test
public void testTruncate() throws Exception {
StorageEngine<ByteArray, byte[], byte[]> engine = getStorageEngine();
Versioned<byte[]> v1 = new Versioned<byte[]>(new byte[] { 1 });
Versioned<byte[]> v2 = new Versioned<byte[]>(new byte[] { 2 });
Versioned<byte[]> v3 = new Versioned<byte[]>(new byte[] { 3 });
ByteArray key1 = new ByteArray((byte) 3);
ByteArray key2 = new ByteArray((byte) 4);
ByteArray key3 = new ByteArray((byte) 5);
engine.put(key1, v1, null);
engine.put(key2, v2, null);
engine.put(key3, v3, null);
engine.truncate();
ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> it = null;
try {
it = engine.entries();
while (it.hasNext()) {
fail("There shouldn't be any entries in this store.");
}
} finally {
if (it != null) {
it.close();
}
}
// Verify that the store is still useable after the truncate.
assertEquals(0, engine.get(key1, null).size());
engine.put(key1, v1, null);
assertEquals(1, engine.get(key1, null).size());
}
use of voldemort.versioning.Versioned 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.versioning.Versioned 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.versioning.Versioned 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.versioning.Versioned in project voldemort by voldemort.
the class AbstractStoreTest method testDelete.
@Test
public void testDelete() throws Exception {
K key = getKey();
Store<K, V, T> store = getStore();
VectorClock c1 = getClock(1, 1);
VectorClock c2 = getClock(1, 2);
V value = getValue();
// can't delete something that isn't there
assertTrue(!store.delete(key, c1));
// put two conflicting versions, then delete one
Versioned<V> v1 = new Versioned<V>(value, c1);
Versioned<V> v2 = new Versioned<V>(value, c2);
store.put(key, v1, null);
store.put(key, v2, null);
assertTrue("Delete failed!", store.delete(key, v1.getVersion()));
List<Versioned<V>> found = store.get(key, null);
// check that there is a single remaining version, namely the
// non-deleted
assertValueEquals(v2.getValue(), found);
assertEquals(v2.getVersion(), found.get(0).getVersion());
// now delete that version too
assertTrue("Delete failed!", store.delete(key, c2));
assertEquals(0, store.get(key, null).size());
}
Aggregations