use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class RiakUtils method createResultHashMap.
/**
* Function that retrieves all the fields searched within a read or scan operation and puts them in the result
* HashMap.
*
* @param fields The list of fields to read, or null for all of them.
* @param response A Vector of HashMaps, where each HashMap is a set field/value pairs for one record.
* @param resultHashMap The HashMap to return as result.
*/
static void createResultHashMap(Set<String> fields, FetchValue.Response response, HashMap<String, ByteIterator> resultHashMap) {
// If everything went fine, then a result must be given. Such an object is a hash table containing the (field,
// value) pairs based on the requested fields. Note that in a read operation, ONLY ONE OBJECT IS RETRIEVED!
// The following line retrieves the previously serialized table which was store with an insert transaction.
byte[] responseFieldsAndValues = response.getValues().get(0).getValue().getValue();
// Deserialize the stored response table.
HashMap<String, ByteIterator> deserializedTable = new HashMap<>();
deserializeTable(responseFieldsAndValues, deserializedTable);
// If only specific fields are requested, then only these should be put in the result object!
if (fields != null) {
// Populate the HashMap to provide as result.
for (Object field : fields.toArray()) {
// Comparison between a requested field and the ones retrieved. If they're equal (i.e. the get() operation
// DOES NOT return a null value), then proceed to store the pair in the resultHashMap.
ByteIterator value = deserializedTable.get(field);
if (value != null) {
resultHashMap.put((String) field, value);
}
}
} else {
// If, instead, no field is specified, then all those retrieved must be provided as result.
for (String field : deserializedTable.keySet()) {
resultHashMap.put(field, deserializedTable.get(field));
}
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method insertAndReadTest.
@Test
public void insertAndReadTest() {
Assume.assumeTrue(haveDb);
try {
// Create some test data
final String insertKey = INSERT_TEST_KEY;
final Set<String> columns = getColumnNameMap();
// Insert row
HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
for (int i = 0; i < NUM_FIELDS; i++) {
insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
}
voltClient.insert(TABLE_NAME, insertKey, insertMap);
// Create a object to put retrieved row in...
Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
// Read row...
Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
if (!s.equals(Status.OK)) {
fail("Didn't get OK on read.");
}
if (!compareContents(insertMap, testResult)) {
fail("Returned data not the same as inserted data");
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed insertTest");
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method insertDeleteAndReadTest.
@Test
public void insertDeleteAndReadTest() {
Assume.assumeTrue(haveDb);
try {
// Create some test data
final String insertKey = INSERT_DELETE_AND_READ_TEST_KEY;
final Set<String> columns = getColumnNameMap();
// Insert row
HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
for (int i = 0; i < NUM_FIELDS; i++) {
insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
}
voltClient.insert(TABLE_NAME, insertKey, insertMap);
// Create a object to put retrieved row in...
Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
// Read row...
Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
if (!s.equals(Status.OK)) {
fail("Didn't get OK on read.");
}
if (!compareContents(insertMap, testResult)) {
fail("Returned data not the same as inserted data");
}
voltClient.delete(TABLE_NAME, insertKey);
// Create another object to put retrieved row in...
Map<String, ByteIterator> testResultAfterDelete = new HashMap<String, ByteIterator>();
// Read row...
voltClient.read(TABLE_NAME, insertKey, columns, testResultAfterDelete);
if (testResultAfterDelete.size() > 0) {
fail("testResultAfterDelete has value.");
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed insertDeleteAndReadTest");
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method compareContents.
private boolean compareContents(HashMap<String, ByteIterator> inMsg, Map<String, ByteIterator> outMsg) {
if (inMsg == null) {
return false;
}
if (outMsg == null) {
return false;
}
if (inMsg.size() != outMsg.size()) {
return false;
}
@SuppressWarnings("rawtypes") Iterator it = inMsg.entrySet().iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes") Map.Entry pair = (Map.Entry) it.next();
String key = (String) pair.getKey();
ByteIterator inPayload = inMsg.get(key);
inPayload.reset();
ByteIterator outPayload = outMsg.get(key);
outPayload.reset();
if (inPayload.bytesLeft() != outPayload.bytesLeft()) {
return false;
}
while (inPayload.hasNext()) {
byte inByte = inPayload.nextByte();
byte outByte = outPayload.nextByte();
if (inByte != outByte) {
return false;
}
}
it.remove();
}
return true;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method singleScanReadTest.
private void singleScanReadTest(String startKey, int requestedCount, int expectedCount, String lastKey) {
Assume.assumeTrue(haveDb);
try {
final Set<String> columns = getColumnNameMap();
// Create a object to put retrieved row in...
Vector<HashMap<String, ByteIterator>> testResult = new Vector<HashMap<String, ByteIterator>>();
// Read row...
Status s = voltClient.scan(TABLE_NAME, startKey, expectedCount, columns, testResult);
if (!s.equals(Status.OK)) {
fail("Didn't get OK on read.");
}
if (testResult.size() != expectedCount) {
fail("Failed singleScanReadTest " + startKey + " " + expectedCount + " " + lastKey);
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed singleScanReadTest " + startKey + ". Asked for " + requestedCount + ", expected " + expectedCount + " lastkey=" + lastKey);
}
}
Aggregations