use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class RepairJobTest method testRepairJob.
@Test
public void testRepairJob() {
// start the servers
setUp();
// Create socket store
storeMap = createSocketStore(storeDefs.get(0));
// Generate random data, populate cluster with it.
HashMap<String, String> testEntries = ServerTestUtils.createRandomKeyValueString(128);
populateData(testEntries);
// create admin client and run repair on all nodes
AdminClient admin = new AdminClient(cluster);
for (int i = 0; i < 9; i++) {
admin.storeMntOps.repairJob(i);
}
// wait for the repair to complete
for (int i = 0; i < 9; i++) {
ServerTestUtils.waitForAsyncOperationOnServer(serverMap.get(i), "Repair", 5000);
}
BaseStoreRoutingPlan storeInstance = new BaseStoreRoutingPlan(cluster, storeDefs.get(0));
for (Entry<String, String> entry : testEntries.entrySet()) {
ByteArray keyBytes = new ByteArray(ByteUtils.getBytes(entry.getKey(), "UTF-8"));
List<Integer> preferenceNodes = storeInstance.getReplicationNodeList(keyBytes.get());
List<Integer> allNodes = new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8));
// Repair job should have deleted the keys on the nodes that
// shouldn't have been
// hosting the key. Go over all these remaining nodes to make sure
// that it's true.
allNodes.removeAll(preferenceNodes);
for (int nodeId : allNodes) {
try {
List<Versioned<byte[]>> retVal = storeMap.get(nodeId).get(keyBytes, null);
assertEquals("Repair did not run properly as it left the key it should have" + " deleted", retVal.isEmpty(), true);
} catch (Exception e) {
// We expect a bunch of invalidmetadata exceptions as we are
// asking for key
// that doesn't belong to the nodes. Hence leaving the catch
// empty.
}
}
// pref list.
for (int nodeId : preferenceNodes) {
try {
List<Versioned<byte[]>> retVal = storeMap.get(nodeId).get(keyBytes, null);
assertEquals("Repair job has deleted keys that it should not have", retVal.isEmpty(), false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
for (Store<ByteArray, byte[], byte[]> store : storeMap.values()) {
store.close();
}
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class StorageServiceTest method testMetadataVersionsInit.
@Test
public void testMetadataVersionsInit() {
Store<ByteArray, byte[], byte[]> versionStore = storeRepository.getLocalStore(SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
Properties props = new Properties();
try {
ByteArray metadataVersionsKey = new ByteArray(SystemStoreConstants.VERSIONS_METADATA_KEY.getBytes());
List<Versioned<byte[]>> versionList = versionStore.get(metadataVersionsKey, null);
if (versionList != null && versionList.size() > 0) {
byte[] versionsByteArray = versionList.get(0).getValue();
if (versionsByteArray != null) {
props.load(new ByteArrayInputStream(versionsByteArray));
} else {
fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
}
} else {
fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
}
// Check if version exists for cluster.xml
if (!props.containsKey(SystemStoreConstants.CLUSTER_VERSION_KEY)) {
fail(SystemStoreConstants.CLUSTER_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
}
// Check if version exists for stores.xml
if (!props.containsKey(SystemStoreConstants.STORES_VERSION_KEY)) {
fail(SystemStoreConstants.STORES_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
}
// Check if version exists for each store
for (StoreDefinition def : storeDefs) {
if (!props.containsKey(def.getName())) {
fail(def.getName() + " store not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
}
}
} catch (Exception e) {
fail("Error in retrieving : " + SystemStoreConstants.VERSIONS_METADATA_KEY + " key from " + SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name() + " store. ");
}
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class FileBackedCachingStorageEngineTest method getKeys.
/*
* Calling getStrings to make it readable (easier debugging)
*/
@Override
public List<ByteArray> getKeys(int numKeys) {
List<String> keyList = getStrings(numKeys, 10);
List<ByteArray> byteArrayKeyList = new ArrayList<ByteArray>();
for (String s : keyList) {
byteArrayKeyList.add(new ByteArray(s.getBytes()));
}
return byteArrayKeyList;
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class FileBackedCachingStorageEngineTest 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());
VectorClock clock = new VectorClock();
for (int i = 0; i < putCount; i++) {
store.put(keys.get(i), new Versioned<byte[]>(values.get(i), clock), null);
clock = clock.incremented(0, System.currentTimeMillis());
}
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);
}
use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class FileBackedCachingStorageEngineTest method testDelete.
@Override
public void testDelete() {
ByteArray key = getKey();
Store<ByteArray, byte[], byte[]> store = getStore();
VectorClock c1 = getClock(1, 1);
byte[] value = getValue();
// can't delete something that isn't there
assertTrue(!store.delete(key, c1));
store.put(key, new Versioned<byte[]>(value, c1), null);
assertEquals(1, store.get(key, null).size());
// now delete that version too
assertTrue("Delete failed!", store.delete(key, c1));
assertEquals(0, store.get(key, null).size());
}
Aggregations