use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class GridDBClientTest method testInsert.
@Test
public void testInsert() {
HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
// The number of field in container info is 10
for (int i = 0; i < FIELD_COUNT; i++) {
values.put("field" + i, new StringByteIterator("value" + i));
}
Status insertStatus = myClient.insert(TEST_TABLE, DEFAULT_ROW_KEY, values);
assertEquals(insertStatus, Status.OK);
myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, null, result);
assertEquals(result.size(), FIELD_COUNT);
for (int i = 0; i < FIELD_COUNT; i++) {
ByteIterator iter = result.get("field" + i);
byte[] byteArray1 = iter.toArray();
String value = new String(byteArray1);
assertEquals(value, "value" + i);
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class OrientDBClientTest method updateTest.
@Test
public void updateTest() {
String preupdateString = "preupdate";
String user0 = "user0";
String user1 = "user1";
String user2 = "user2";
OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
try (ODatabaseDocumentTx db = pool.acquire()) {
// Manually insert three documents
for (String key : Arrays.asList(user0, user1, user2)) {
ODocument doc = new ODocument(CLASS);
for (int i = 0; i < NUM_FIELDS; i++) {
doc.field(FIELD_PREFIX + i, preupdateString);
}
doc.save();
ODictionary<ORecord> dictionary = db.getDictionary();
dictionary.put(key, doc);
}
}
HashMap<String, ByteIterator> updateMap = new HashMap<>();
for (int i = 0; i < NUM_FIELDS; i++) {
updateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(user1, FIELD_PREFIX + i)));
}
orientDBClient.update(CLASS, user1, updateMap);
try (ODatabaseDocumentTx db = pool.acquire()) {
ODictionary<ORecord> dictionary = db.getDictionary();
// Ensure that user0 record was not changed
ODocument result = dictionary.get(user0);
for (int i = 0; i < NUM_FIELDS; i++) {
assertEquals("Assert first row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
}
// Check that all the columns have expected values for user1 record
result = dictionary.get(user1);
for (int i = 0; i < NUM_FIELDS; i++) {
assertEquals("Assert updated row fields are correct", result.field(FIELD_PREFIX + i), updateMap.get(FIELD_PREFIX + i).toString());
}
// Ensure that user2 record was not changed
result = dictionary.get(user2);
for (int i = 0; i < NUM_FIELDS; i++) {
assertEquals("Assert third row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
}
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class MemcachedClient method fromJson.
protected static void fromJson(String value, Set<String> fields, Map<String, ByteIterator> result) throws IOException {
JsonNode json = MAPPER.readTree(value);
boolean checkFields = fields != null && !fields.isEmpty();
for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.getFields(); jsonFields.hasNext(); ) /* increment in loop body */
{
Map.Entry<String, JsonNode> jsonField = jsonFields.next();
String name = jsonField.getKey();
if (checkFields && !fields.contains(name)) {
continue;
}
JsonNode jsonValue = jsonField.getValue();
if (jsonValue != null && !jsonValue.isNull()) {
result.put(name, new StringByteIterator(jsonValue.asText()));
}
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class InfinispanClient method read.
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
Map<String, String> row;
if (clustered) {
row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
} else {
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
row = cache.get(key);
}
if (row != null) {
result.clear();
if (fields == null || fields.isEmpty()) {
StringByteIterator.putAllAsByteIterators(result, row);
} else {
for (String field : fields) {
result.put(field, new StringByteIterator(row.get(field)));
}
}
}
return Status.OK;
} catch (Exception e) {
LOGGER.error(e);
return Status.ERROR;
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class JdbcDBClientTest method insertRow.
/*
Inserts a row of deterministic values for the given insertKey using the jdbcDBClient.
*/
private HashMap<String, ByteIterator> insertRow(String insertKey) {
HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
for (int i = 0; i < 3; i++) {
insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
}
jdbcDBClient.insert(TABLE_NAME, insertKey, insertMap);
return insertMap;
}
Aggregations