Search in sources :

Example 91 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RestClientTest method testGetWithDefault.

@Override
@Test
public void testGetWithDefault() {
    assertEquals("GET of missing key should return default.", new Versioned<String>("v"), client.get("k", new Versioned<String>("v")));
    assertEquals("null should be an acceptable default value.", null, client.getValue("k", null));
    client.put("k", "v");
    VectorClock expectedVC = new VectorClock().incremented(nodeId, time.getMilliseconds());
    assertEquals("If there is a value for k, get(k) should return it.", "v", client.get("k", new Versioned<String>("v2")).getValue());
    assertNotNull(client.get("k").getVersion());
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) Test(org.junit.Test)

Example 92 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RestServerAPITest method testGetAll.

/**
     * Basic getall test
     */
@Test
public void testGetAll() {
    logger.info("\n\n********************  Testing Get All *******************\n\n");
    VectorClock vectorClock1 = new VectorClock();
    vectorClock1.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    ByteArray key2 = new ByteArray("key2".getBytes());
    Versioned<byte[]> value2 = new Versioned<byte[]>("value2".getBytes(), vectorClock1);
    store.put(key2, value2, null);
    vectorClock1 = new VectorClock();
    vectorClock1.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    ByteArray key3 = new ByteArray("key3".getBytes());
    Versioned<byte[]> value3 = new Versioned<byte[]>("value3".getBytes(), vectorClock1);
    store.put(key3, value3, null);
    Map<ByteArray, List<Versioned<byte[]>>> input = new HashMap<ByteArray, List<Versioned<byte[]>>>();
    List<Versioned<byte[]>> valuesList2 = new ArrayList<Versioned<byte[]>>();
    valuesList2.add(value2);
    input.put(key2, valuesList2);
    List<Versioned<byte[]>> valuesList3 = new ArrayList<Versioned<byte[]>>();
    valuesList3.add(value3);
    input.put(key3, valuesList3);
    Map<ByteArray, List<Versioned<byte[]>>> output = store.getAll(input.keySet(), null);
    assertEquals(input, output);
    // cleanup specific to this test case
    deleteCreatedKeys(key2);
    deleteCreatedKeys(key3);
}
Also used : Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) ByteArray(voldemort.utils.ByteArray) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 93 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RestServerAPITest method testRecursiveDeleteOnSameKeyWithTwoVersions.

/**
     * test delete on a k with v1,v2 recursively to see if the key is completely
     * deleted
     */
@Test
public void testRecursiveDeleteOnSameKeyWithTwoVersions() {
    logger.info("\n\n********************  Testing recursive Delete on a key with two versions *******************\n\n");
    store.put(key, value, null);
    List<Versioned<byte[]>> resultList, previousResultList;
    resultList = store.get(key, null);
    VectorClock vectorClock2 = new VectorClock();
    vectorClock2.incrementVersion(voldemortConfig.getNodeId() + 1, System.currentTimeMillis());
    Versioned<byte[]> value2 = new Versioned<byte[]>("value32".getBytes(), vectorClock2);
    store.put(key, value2, null);
    previousResultList = resultList;
    resultList = store.get(key, null);
    if (resultList.size() != previousResultList.size() + 1) {
        fail("Failed to add another version");
    } else {
        previousResultList = resultList;
        store.delete(key, value.getVersion());
        resultList = store.get(key, null);
        if (resultList.size() != previousResultList.size() - 1) {
            fail("Delete failed");
        } else {
            previousResultList = resultList;
            store.delete(key, value2.getVersion());
            resultList = store.get(key, null);
            assertTrue(resultList.size() == previousResultList.size() - 1);
        }
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) Test(org.junit.Test)

Example 94 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RestServerAPITest method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() {
    voldemortConfig = VoldemortConfig.loadFromVoldemortHome("config/single_node_rest_server/");
    key = new ByteArray("key1".getBytes());
    vectorClock = new VectorClock();
    vectorClock.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    value = new Versioned<byte[]>("value1".getBytes(), vectorClock);
    server = new VoldemortServer(voldemortConfig);
    if (!server.isStarted())
        server.start();
    logger.info("********************Starting REST Server********************");
    restClientConfig = new RESTClientConfig();
    restClientConfig.setHttpBootstrapURL("http://localhost:8085").setTimeoutMs(1500, TimeUnit.MILLISECONDS).setMaxR2ConnectionPoolSize(100);
    clientFactory = new HttpClientFactory();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize()));
    transportClient = clientFactory.getClient(properties);
    r2store = new R2Store("test", restClientConfig.getHttpBootstrapURL(), "2", transportClient, restClientConfig, 0);
    store = r2store;
    deleteCreatedKeys(key);
}
Also used : RESTClientConfig(voldemort.restclient.RESTClientConfig) HashMap(java.util.HashMap) VectorClock(voldemort.versioning.VectorClock) R2Store(voldemort.restclient.R2Store) ByteArray(voldemort.utils.ByteArray) VoldemortServer(voldemort.server.VoldemortServer) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) BeforeClass(org.junit.BeforeClass)

Example 95 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RestServiceR2StoreTest method testGetAll.

@Override
@Test
public void testGetAll() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    int putCount = 10;
    List<ByteArray> keys = getKeys(putCount);
    List<byte[]> values = getValues(putCount);
    assertEquals(putCount, values.size());
    for (int i = 0; i < putCount; i++) {
        VectorClock vc = getClock(0, 0);
        store.put(keys.get(i), new Versioned<byte[]>(values.get(i), vc), null);
    }
    int countForGet = putCount / 2;
    List<ByteArray> keysForGet = keys.subList(0, countForGet);
    List<byte[]> valuesForGet = values.subList(0, countForGet);
    Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keysForGet, null);
    assertGetAllValues(keysForGet, valuesForGet, result);
}
Also used : VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) List(java.util.List) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) 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