Search in sources :

Example 46 with VectorClock

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));
    }
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) HttpParams(org.apache.http.params.HttpParams) RequestFormat(voldemort.client.protocol.RequestFormat) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 47 with VectorClock

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());
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 48 with VectorClock

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));
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 49 with VectorClock

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
    }
}
Also used : VectorClock(voldemort.versioning.VectorClock) Test(org.junit.Test)

Example 50 with VectorClock

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());
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) Test(org.junit.Test)

Aggregations

VectorClock (voldemort.versioning.VectorClock)162 Versioned (voldemort.versioning.Versioned)73 Test (org.junit.Test)65 ByteArray (voldemort.utils.ByteArray)65 ArrayList (java.util.ArrayList)33 IOException (java.io.IOException)25 VoldemortException (voldemort.VoldemortException)24 List (java.util.List)22 HashMap (java.util.HashMap)21 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)21 Version (voldemort.versioning.Version)16 Node (voldemort.cluster.Node)15 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)11 StoreDefinition (voldemort.store.StoreDefinition)11 AdminClient (voldemort.client.protocol.admin.AdminClient)10 VoldemortServer (voldemort.server.VoldemortServer)10 Pair (voldemort.utils.Pair)10 ClockEntry (voldemort.versioning.ClockEntry)10 File (java.io.File)8 Map (java.util.Map)8