Search in sources :

Example 16 with RocksDBException

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();
}
Also used : HashMap(java.util.HashMap) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException) RocksDBException(org.rocksdb.RocksDBException) IntegerSerdeFactory(org.apache.samza.serializers.IntegerSerdeFactory) Test(org.junit.Test)

Aggregations

RocksDBException (org.rocksdb.RocksDBException)16 IOException (java.io.IOException)8 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)6 PersistenceFailureException (voldemort.store.PersistenceFailureException)4 Versioned (voldemort.versioning.Versioned)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayInputStreamWithPos (org.apache.flink.core.memory.ByteArrayInputStreamWithPos)3 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)2 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)2 Map (java.util.Map)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 DataOutputViewStreamWrapper (org.apache.flink.core.memory.DataOutputViewStreamWrapper)1 RegisteredBackendStateMetaInfo (org.apache.flink.runtime.state.RegisteredBackendStateMetaInfo)1 SamzaException (org.apache.samza.SamzaException)1 Config (org.apache.samza.config.Config)1 MapConfig (org.apache.samza.config.MapConfig)1 IntegerSerdeFactory (org.apache.samza.serializers.IntegerSerdeFactory)1