use of site.ycsb.Status 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());
}
}
use of site.ycsb.Status in project YCSB by brianfrankcooper.
the class RocksDBClientTest method insertUpdateAndRead.
@Test
public void insertUpdateAndRead() throws Exception {
final Map<String, ByteIterator> newValues = new HashMap<>(NUM_RECORDS);
final Status insertResult = instance.insert(MOCK_TABLE, MOCK_KEY2, MOCK_DATA);
assertEquals(Status.OK, insertResult);
for (int i = 0; i < NUM_RECORDS; i++) {
newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
}
final Status result = instance.update(MOCK_TABLE, MOCK_KEY2, newValues);
assertEquals(Status.OK, result);
// validate that the values changed
final Map<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
instance.read(MOCK_TABLE, MOCK_KEY2, MOCK_DATA.keySet(), resultParam);
for (int i = 0; i < NUM_RECORDS; i++) {
assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
}
}
use of site.ycsb.Status in project YCSB by brianfrankcooper.
the class RocksDBClientTest method insertAndScan.
@Test
public void insertAndScan() throws Exception {
final Status insertResult = instance.insert(MOCK_TABLE, MOCK_KEY3, MOCK_DATA);
assertEquals(Status.OK, insertResult);
final Set<String> fields = MOCK_DATA.keySet();
final Vector<HashMap<String, ByteIterator>> resultParam = new Vector<>(NUM_RECORDS);
final Status result = instance.scan(MOCK_TABLE, MOCK_KEY3, NUM_RECORDS, fields, resultParam);
assertEquals(Status.OK, result);
}
use of site.ycsb.Status in project YCSB by brianfrankcooper.
the class RocksDBClientTest method insertAndRead.
@Test
public void insertAndRead() throws Exception {
final Status insertResult = instance.insert(MOCK_TABLE, MOCK_KEY0, MOCK_DATA);
assertEquals(Status.OK, insertResult);
final Set<String> fields = MOCK_DATA.keySet();
final Map<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
final Status readResult = instance.read(MOCK_TABLE, MOCK_KEY0, fields, resultParam);
assertEquals(Status.OK, readResult);
}
use of site.ycsb.Status in project YCSB by brianfrankcooper.
the class IgniteClientTestBase method scanNotImplemented.
@Test
public void scanNotImplemented() {
cluster.cache(DEFAULT_CACHE_NAME).clear();
final String key = "key";
final Map<String, String> input = new HashMap<>();
input.put("field0", "value1");
input.put("field1", "value2");
final Status status = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
assertThat(status, is(Status.OK));
assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
final Vector<HashMap<String, ByteIterator>> results = new Vector<>();
final Status scan = client.scan(DEFAULT_CACHE_NAME, key, 1, null, results);
assertThat(scan, is(Status.NOT_IMPLEMENTED));
}
Aggregations