use of site.ycsb.DB 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.DB 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.DB in project YCSB by brianfrankcooper.
the class AbstractDBTestCases method testInsertReadUpdate.
/**
* Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#update} .
*/
@Test
public void testInsertReadUpdate() {
DB client = getDB();
final String table = getClass().getSimpleName();
final String id = "update";
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());
}
HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
result = client.update(table, id, updated);
assertThat("Update did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after update, 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) 5)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 6)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 7)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 8)));
assertFalse(iter.hasNext());
}
}
use of site.ycsb.DB in project YCSB by brianfrankcooper.
the class AbstractDBTestCases method testInsertReadUpdateWithUpsert.
/**
* Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#update} .
*/
@Test
public void testInsertReadUpdateWithUpsert() {
Properties props = new Properties();
props.setProperty("mongodb.upsert", "true");
DB client = getDB(props);
final String table = getClass().getSimpleName();
final String id = "updateWithUpsert";
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());
}
HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
result = client.update(table, id, updated);
assertThat("Update did not return success (0).", result, is(Status.OK));
read.clear();
result = client.read(table, id, null, read);
assertThat("Read, after update, 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) 5)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 6)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 7)));
assertTrue(iter.hasNext());
assertThat(iter.nextByte(), is(Byte.valueOf((byte) 8)));
assertFalse(iter.hasNext());
}
}
Aggregations