use of org.rocksdb.FlushOptions in project samza by apache.
the class TestRocksDbKeyValueStoreJava method testIterate.
@Test
public void testIterate() throws Exception {
Config config = new MapConfig();
Options options = new Options();
options.setCreateIfMissing(true);
File dbDir = new File(System.getProperty("java.io.tmpdir") + "/dbStore" + System.currentTimeMillis());
RocksDbKeyValueStore store = new RocksDbKeyValueStore(dbDir, options, config, false, "dbStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("dbStore", new MetricsRegistryMap()));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String prefix = "prefix";
for (int i = 0; i < 100; i++) {
store.put(genKey(outputStream, prefix, i), genValue());
}
byte[] firstKey = genKey(outputStream, prefix, 0);
byte[] lastKey = genKey(outputStream, prefix, 1000);
KeyValueSnapshot<byte[], byte[]> snapshot = store.snapshot(firstKey, lastKey);
// Make sure the cached Iterable won't change when new elements are added
store.put(genKey(outputStream, prefix, 200), genValue());
KeyValueIterator<byte[], byte[]> iterator = snapshot.iterator();
assertTrue(Iterators.size(iterator) == 100);
iterator.close();
List<Integer> keys = new ArrayList<>();
KeyValueIterator<byte[], byte[]> iterator2 = snapshot.iterator();
while (iterator2.hasNext()) {
Entry<byte[], byte[]> entry = iterator2.next();
int key = Ints.fromByteArray(Arrays.copyOfRange(entry.getKey(), prefix.getBytes().length, entry.getKey().length));
keys.add(key);
}
assertEquals(keys, IntStream.rangeClosed(0, 99).boxed().collect(Collectors.toList()));
iterator2.close();
outputStream.close();
snapshot.close();
store.close();
}
use of org.rocksdb.FlushOptions in project beam by apache.
the class SamzaTimerInternalsFactoryTest method createStore.
private KeyValueStore<ByteArray, StateValue<?>> createStore() {
final Options options = new Options();
options.setCreateIfMissing(true);
RocksDbKeyValueStore rocksStore = new RocksDbKeyValueStore(temporaryFolder.getRoot(), options, new MapConfig(), false, "beamStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("beamStore", new MetricsRegistryMap()));
return new SerializedKeyValueStore<>(rocksStore, new ByteArraySerdeFactory.ByteArraySerde(), new StateValueSerdeFactory.StateValueSerde(), new SerializedKeyValueStoreMetrics("beamStore", new MetricsRegistryMap()));
}
Aggregations