use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class GridDBClient method insert.
public Status insert(String table, String key, Map<String, ByteIterator> values) {
try {
Object rowKey = makeRowKey(key);
String containerKey = makeContainerKey(key);
final Container<Object, Row> container = store.getContainer(containerKey);
if (container == null) {
LOGGER.severe("[ERROR]getCollection " + containerKey + " in insert()");
}
Row row = container.createRow();
row.setValue(ROW_KEY_COLUMN_POS, rowKey);
for (int i = 1; i < containerInfo.getColumnCount(); i++) {
ByteIterator byteIterator = values.get(containerInfo.getColumnInfo(i).getName());
Object value = makeValue(byteIterator);
row.setValue(i, value);
}
container.put(row);
} catch (GSException e) {
LOGGER.severe("Exception: " + e.getMessage());
return Status.ERROR;
}
return Status.OK;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class GridDBClientTest method insertToDatabase.
/**
* Insert data to GridbDB database for testing
*/
private void insertToDatabase() {
HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
// The number of field in container info is 10
for (int i = 0; i < FIELD_COUNT; i++) {
values.put(VALUE_COLUMN_NAME_PREFIX + i, new StringByteIterator("value" + i));
}
myClient.insert(TEST_TABLE, DEFAULT_ROW_KEY, values);
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class GridDBClientTest method testReadSingleRow.
@Test
public void testReadSingleRow() {
Set<String> fields = Collections.singleton("field1");
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
insertToDatabase();
Status readStatus = myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, fields, result);
assertEquals(readStatus, Status.OK);
assertNotEquals(result.entrySet(), 0);
for (String key : fields) {
ByteIterator iter = result.get(key);
byte[] byteArray1 = iter.toArray();
String value = new String(byteArray1);
assertEquals(value, "value1");
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class GridDBClientTest method testReadNoExistedRow.
@Test
public void testReadNoExistedRow() {
Set<String> fields = Collections.singleton("field0");
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
insertToDatabase();
Status readStatus = myClient.read(TEST_TABLE, "Missing row", fields, result);
assertEquals(readStatus, Status.ERROR);
assertEquals(result.size(), 0);
}
use of site.ycsb.ByteIterator 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);
}
}
Aggregations