use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class HttpStoreTest method testBadUrlOrPort.
public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T> expected) {
ByteArray key = new ByteArray("test".getBytes());
RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, 5000);
HttpStore badUrlHttpStore = new HttpStore("test", url, port, httpClient, requestFormat, false);
try {
badUrlHttpStore.put(key, new Versioned<byte[]>("value".getBytes(), new VectorClock()), null);
} catch (Exception e) {
assertTrue(e.getClass().equals(expected));
}
try {
badUrlHttpStore.get(key, null);
} catch (Exception e) {
assertTrue(e.getClass().equals(expected));
}
try {
badUrlHttpStore.delete(key, new VectorClock());
} catch (Exception e) {
assertTrue(e.getClass().equals(expected));
}
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class VersionedPutPruningTest method testPruningLogic.
@Test
public void testPruningLogic() {
List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
VectorClock clock1 = TestUtils.getClock(0, 2, 1, 3);
VectorClock clock2 = TestUtils.getClock(9, 4);
VectorClock clock3 = TestUtils.getClock(0, 1);
VectorClock clock4 = TestUtils.getClock(8, 0);
vals.add(new Versioned<byte[]>(key, clock1));
vals.add(new Versioned<byte[]>(key, clock2));
vals.add(new Versioned<byte[]>(key, clock3));
vals.add(new Versioned<byte[]>(key, clock4));
MutableBoolean didPrune = new MutableBoolean(false);
List<Versioned<byte[]>> prunedVals = VersionedPutPruneJob.pruneNonReplicaEntries(vals, keyReplicas, didPrune);
assertEquals("Must have pruned some versions", true, didPrune.booleanValue());
assertEquals("Not pruned properly", TestUtils.getClock(0, 1, 2), prunedVals.get(0).getVersion());
assertEquals("Not pruned properly", TestUtils.getClock(), prunedVals.get(1).getVersion());
assertEquals("Not pruned properly", TestUtils.getClock(0, 1), prunedVals.get(2).getVersion());
assertEquals("Not pruned properly", TestUtils.getClock(0), prunedVals.get(3).getVersion());
List<Versioned<byte[]>> resolvedVals = VectorClockUtils.resolveVersions(prunedVals);
assertEquals("Must be exactly one winning version", 1, resolvedVals.size());
assertEquals("Incorrect winning version", TestUtils.getClock(0, 1, 2), resolvedVals.get(0).getVersion());
assertEquals("Incorrect winning version", clock1.getTimestamp(), ((VectorClock) resolvedVals.get(0).getVersion()).getTimestamp());
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class VersionedPutPruningTest method testOnlineBehavior.
@Test
public void testOnlineBehavior() {
long now = System.currentTimeMillis();
// let's assume previous replicas are [4, 5, 0]
VectorClock fetchedClock = TestUtils.getVersionedPutClock(now, 4, 4, 5, 0);
VectorClock onlineClock = TestUtils.getVersionedPutClock(now, 0, 0, 2, 1);
assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock, onlineClock));
// case where key has received writes before the prune job
List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
vals.add(new Versioned<byte[]>(key, fetchedClock));
vals.add(new Versioned<byte[]>(key, onlineClock));
MutableBoolean didPrune = new MutableBoolean();
vals = pruneAndResolve(vals, didPrune);
assertEquals("Must have pruned something", true, didPrune.booleanValue());
assertEquals("Must have one winning version", 1, vals.size());
assertEquals("Must resolve to onlineClock", onlineClock, vals.get(0).getVersion());
// case where key has not received any writes before the prune job
vals = new ArrayList<Versioned<byte[]>>();
vals.add(new Versioned<byte[]>(key, fetchedClock));
didPrune = new MutableBoolean();
vals = pruneAndResolve(vals, didPrune);
assertEquals("Must have pruned something", true, didPrune.booleanValue());
assertEquals("Must have one winning version", 1, vals.size());
assertEquals("Must resolve to [0:ts] clock", TestUtils.getVersionedPutClock(now, -1, 0), vals.get(0).getVersion());
VectorClock nextOnlineClock = TestUtils.getVersionedPutClock(now + Time.MS_PER_SECOND, 0, 0, 2, 1);
assertFalse("Next online write would not result in conflict", Occurred.CONCURRENTLY == VectorClockUtils.compare((VectorClock) vals.get(0).getVersion(), nextOnlineClock));
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class AbstractStoreTest method testNullKeys.
@Test
public void testNullKeys() throws Exception {
Store<K, V, T> store = getStore();
try {
store.put(null, new Versioned<V>(getValue()), null);
fail("Store should not put null keys!");
} catch (IllegalArgumentException e) {
// this is good
}
try {
store.get(null, null);
fail("Store should not get null keys!");
} catch (IllegalArgumentException e) {
// this is good
}
try {
store.getAll(null, null);
fail("Store should not getAll null keys!");
} catch (IllegalArgumentException e) {
// this is good
}
try {
store.getAll(Collections.<K>singleton(null), Collections.<K, T>singletonMap(null, null));
fail("Store should not getAll null keys!");
} catch (IllegalArgumentException e) {
// this is good
}
try {
store.delete(null, new VectorClock());
fail("Store should not delete null keys!");
} catch (IllegalArgumentException e) {
// this is good
}
}
use of voldemort.versioning.VectorClock 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