use of site.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AbstractDBTestCases method testScan.
/**
* Test method for {@link DB#scan}.
*/
@Test
public void testScan() {
final DB client = getDB();
final String table = getClass().getSimpleName();
// Insert a bunch of documents.
for (int i = 0; i < 100; ++i) {
HashMap<String, ByteIterator> inserted = new HashMap<String, ByteIterator>();
inserted.put("a", new ByteArrayByteIterator(new byte[] { (byte) (i & 0xFF), (byte) (i >> 8 & 0xFF), (byte) (i >> 16 & 0xFF), (byte) (i >> 24 & 0xFF) }));
Status result = client.insert(table, padded(i), inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
}
Set<String> keys = Collections.singleton("a");
Vector<HashMap<String, ByteIterator>> results = new Vector<HashMap<String, ByteIterator>>();
Status result = client.scan(table, "00050", 5, null, results);
assertThat("Read did not return success (0).", result, is(Status.OK));
assertThat(results.size(), is(5));
for (int i = 0; i < 5; ++i) {
Map<String, ByteIterator> read = results.get(i);
for (String key : keys) {
ByteIterator iter = read.get(key);
assertThat("Did not read the inserted field: " + key, iter, notNullValue());
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) ((i + 50) & 0xFF))));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) ((i + 50) >> 8 & 0xFF))));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) ((i + 50) >> 16 & 0xFF))));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) ((i + 50) >> 24 & 0xFF))));
assertFalse(iter.hasNext());
}
}
}
use of site.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AbstractDBTestCases method testInsertReadDelete.
/**
* Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#delete} .
*/
@Test
public void testInsertReadDelete() {
final DB client = getDB();
final String table = getClass().getSimpleName();
final String id = "delete";
HashMap<String, ByteIterator> inserted = new HashMap<String, ByteIterator>();
inserted.put("a", new ByteArrayByteIterator(new byte[] { 1, 2, 3, 4 }));
Status result = client.insert(table, id, inserted);
assertThat("Insert did not return success (0).", result, is(Status.OK));
HashMap<String, ByteIterator> read = new HashMap<String, ByteIterator>();
Set<String> keys = Collections.singleton("a");
result = client.read(table, id, keys, read);
assertThat("Read did not return success (0).", result, is(Status.OK));
for (String key : keys) {
ByteIterator iter = read.get(key);
assertThat("Did not read the inserted field: " + key, iter, notNullValue());
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 1)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 2)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 3)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 4)));
assertFalse(iter.hasNext());
}
result = client.delete(table, id);
assertThat("Delete did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after delete, did not return not found (1).", result, is(Status.NOT_FOUND));
assertThat("Found the deleted fields.", read.size(), is(0));
result = client.delete(table, id);
assertThat("Delete did not return not found (1).", result, is(Status.NOT_FOUND));
}
use of site.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
setTable(table);
final GetRequest get = new GetRequest(lastTableBytes, key.getBytes(), columnFamilyBytes);
if (fields != null) {
get.qualifiers(getQualifierList(fields));
}
try {
if (debug) {
System.out.println("Doing read from HBase columnfamily " + Bytes.pretty(columnFamilyBytes));
System.out.println("Doing read for key: " + key);
}
final ArrayList<KeyValue> row = client.get(get).join(joinTimeout);
if (row == null || row.isEmpty()) {
return Status.NOT_FOUND;
}
// got something so populate the results
for (final KeyValue column : row) {
result.put(new String(column.qualifier()), // be GC'd.
new ByteArrayByteIterator(column.value()));
if (debug) {
System.out.println("Result for field: " + Bytes.pretty(column.qualifier()) + " is: " + Bytes.pretty(column.value()));
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Thread interrupted");
Thread.currentThread().interrupt();
} catch (Exception e) {
System.err.println("Failure reading from row with key " + key + ": " + e.getMessage());
return Status.ERROR;
}
return Status.ERROR;
}
use of site.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
setTable(table);
final Scanner scanner = client.newScanner(lastTableBytes);
scanner.setFamily(columnFamilyBytes);
scanner.setStartKey(startkey.getBytes(UTF8_CHARSET));
// No end key... *sniff*
if (fields != null) {
scanner.setQualifiers(getQualifierList(fields));
}
// no filters? *sniff*
ArrayList<ArrayList<KeyValue>> rows = null;
try {
int numResults = 0;
while ((rows = scanner.nextRows().join(joinTimeout)) != null) {
for (final ArrayList<KeyValue> row : rows) {
final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(row.size());
for (final KeyValue column : row) {
rowResult.put(new String(column.qualifier()), // be GC'd.
new ByteArrayByteIterator(column.value()));
if (debug) {
System.out.println("Got scan result for key: " + Bytes.pretty(column.key()));
}
}
result.add(rowResult);
numResults++;
if (numResults >= recordcount) {
// if hit recordcount, bail out
break;
}
}
}
scanner.close().join(joinTimeout);
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Thread interrupted");
Thread.currentThread().interrupt();
} catch (Exception e) {
System.err.println("Failure reading from row with key " + startkey + ": " + e.getMessage());
return Status.ERROR;
}
return Status.ERROR;
}
use of site.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AzureClient method readEntity.
private Status readEntity(String key, Map<String, ByteIterator> result) {
try {
// firstly, retrieve the entity to be deleted
TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, DynamicTableEntity.class);
DynamicTableEntity entity = cloudTable.execute(retrieveOp).getResultAsType();
HashMap<String, EntityProperty> properties = entity.getProperties();
for (Entry<String, EntityProperty> entry : properties.entrySet()) {
String fieldName = entry.getKey();
ByteIterator fieldVal = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
result.put(fieldName, fieldVal);
}
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
Aggregations