use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method scanReadTest.
@Test
public void scanReadTest() {
Assume.assumeTrue(haveDb);
try {
for (int z = 0; z < SCAN_RECORD_COUNT; z++) {
// Create some test data
final String insertKey = SCAN_KEY_PREFIX + z;
// 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("Data for " + SCAN_KEY_PREFIX + z + " element " + i));
}
voltClient.insert(TABLE_NAME, insertKey, insertMap);
}
final String firstInsertKey = SCAN_KEY_PREFIX + 0;
final String lastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 1);
final String beyondLastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT + 1);
final String oneHundredFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
final String fiftyFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
// test non existent records
singleScanReadTest(NON_EXISTENT_KEY, 1000, 0, NON_EXISTENT_KEY);
// test single record
singleScanReadTest(firstInsertKey, 1, 1, firstInsertKey);
// test scan of SCAN_RECORD_COUNT records
singleScanReadTest(firstInsertKey, SCAN_RECORD_COUNT, SCAN_RECORD_COUNT, lastInsertKey);
// test single record in middle
singleScanReadTest(oneHundredFromEndInsertKey, 1, 1, oneHundredFromEndInsertKey);
// test request of 100 starting 50 from end.
singleScanReadTest(fiftyFromEndInsertKey, 100, 50, lastInsertKey);
// test request of 100 starting beyond the end
singleScanReadTest(beyondLastInsertKey, 100, 0, lastInsertKey);
} catch (Exception e) {
e.printStackTrace();
fail("Failed scanReadTest");
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method insert_404.
@Test
public void insert_404() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.insert(null, ABSENT_RESOURCE, data);
assertEquals(Status.NOT_FOUND, status);
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method update_500.
@Test
public void update_500() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.update(null, INVALID_RESOURCE, data);
assertEquals(Status.ERROR, status);
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class GoogleDatastoreClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
LookupRequest.Builder lookupRequest = LookupRequest.newBuilder();
lookupRequest.addKeys(buildPrimaryKey(table, key));
lookupRequest.getReadOptionsBuilder().setReadConsistency(this.readConsistency);
// Note above, datastore lookupRequest always reads the entire entity, it
// does not support reading a subset of "fields" (properties) of an entity.
logger.debug("Built lookup request as: " + lookupRequest.toString());
LookupResponse response = null;
try {
response = datastore.lookup(lookupRequest.build());
} catch (DatastoreException exception) {
logger.error(String.format("Datastore Exception when reading (%s): %s %s", exception.getMessage(), exception.getMethodName(), exception.getCode()));
// will bubble up to the user as part of the YCSB Status "name".
return new Status("ERROR-" + exception.getCode(), exception.getMessage());
}
if (response.getFoundCount() == 0) {
return new Status("ERROR-404", "Not Found, key is: " + key);
} else if (response.getFoundCount() > 1) {
// entity back. Unexpected State.
return Status.UNEXPECTED_STATE;
}
Entity entity = response.getFound(0).getEntity();
logger.debug("Read entity: " + entity.toString());
Map<String, Value> properties = entity.getProperties();
Set<String> propertiesToReturn = (fields == null ? properties.keySet() : fields);
for (String name : propertiesToReturn) {
if (properties.containsKey(name)) {
result.put(name, new StringByteIterator(properties.get(name).getStringValue()));
}
}
return Status.OK;
}
use of site.ycsb.StringByteIterator 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);
}
Aggregations