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());
}
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);
}
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);
}
}
}
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);
}
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);
}
Aggregations