use of org.rocksdb.RocksDBException in project samza by apache.
the class TestRocksDbKeyValueReader method testReadCorrectDbValue.
@Test
public void testReadCorrectDbValue() throws RocksDBException {
HashMap<String, String> map = new HashMap<String, String>();
map.put("stores." + DB_NAME + ".factory", "mockFactory");
map.put("stores." + DB_NAME + ".key.serde", "string");
map.put("stores." + DB_NAME + ".msg.serde", "string");
Config config = new MapConfig(map);
RocksDbKeyValueReader reader = new RocksDbKeyValueReader(DB_NAME, dirPath.toString(), config);
assertEquals("this is string", reader.get("testString"));
// should throw exception if the input is in other type
boolean throwClassCastException = false;
try {
reader.get(123);
} catch (Exception e) {
if (e instanceof ClassCastException) {
throwClassCastException = true;
}
}
assertTrue(throwClassCastException);
reader.stop();
// test with customized serde
map.put("serializers.registry.mock.class", IntegerSerdeFactory.class.getCanonicalName());
map.put("stores." + DB_NAME + ".key.serde", "mock");
map.put("stores." + DB_NAME + ".msg.serde", "mock");
config = new MapConfig(map);
reader = new RocksDbKeyValueReader(DB_NAME, dirPath.toString(), config);
assertEquals(456, reader.get(123));
assertNull(reader.get(789));
reader.stop();
}
Aggregations