use of org.apache.bookkeeper.statelib.api.StateStoreSpec in project bookkeeper by apache.
the class TestRocksdbKVAsyncStore method testBasicOps.
@Test
public void testBasicOps() throws Exception {
this.streamName = "test-basic-ops";
StateStoreSpec spec = initSpec(streamName);
result(store.init(spec));
// normal put
{
assertNull(result(store.get(getKey(0))));
result(store.put(getKey(0), getValue(0)));
assertArrayEquals(getValue(0), result(store.get(getKey(0))));
}
// putIfAbsent
{
// failure case
assertArrayEquals(getValue(0), result(store.putIfAbsent(getKey(0), getValue(99))));
assertArrayEquals(getValue(0), result(store.get(getKey(0))));
// success case
byte[] key1 = getKey(1);
assertNull(result(store.putIfAbsent(key1, getValue(1))));
assertArrayEquals(getValue(1), result(store.get(key1)));
}
// delete(k)
{
// key not found
assertNull(result(store.delete(getKey(99))));
// key exists
int key = 0;
assertArrayEquals(getValue(key), result(store.get(getKey(key))));
assertArrayEquals(getValue(key), result(store.delete(getKey(key))));
assertNull(result(store.get(getKey(key))));
}
}
use of org.apache.bookkeeper.statelib.api.StateStoreSpec in project bookkeeper by apache.
the class TestRocksdbKVAsyncStore method testInitMissingStreamName.
@Test(expected = NullPointerException.class)
public void testInitMissingStreamName() throws Exception {
this.streamName = "test-init-missing-stream-name";
StateStoreSpec spec = StateStoreSpec.builder().name(streamName).keyCoder(ByteArrayCoder.of()).valCoder(ByteArrayCoder.of()).localStateStoreDir(tempDir).build();
result(store.init(spec));
}
use of org.apache.bookkeeper.statelib.api.StateStoreSpec in project bookkeeper by apache.
the class TestMVCCAsyncBytesStoreImpl method testInit.
@Test
public void testInit() throws Exception {
this.streamName = "test-init";
StateStoreSpec spec = initSpec(streamName);
result(store.init(spec));
assertTrue(store.ownWriteScheduler());
assertFalse(store.ownReadScheduler());
assertEquals(streamName, store.name());
}
use of org.apache.bookkeeper.statelib.api.StateStoreSpec in project bookkeeper by apache.
the class MVCCAsyncStoreTestBase method setUp.
@Before
public void setUp() throws Exception {
scheduler = OrderedScheduler.newSchedulerBuilder().name("test-root-range-store").numThreads(1).build();
namespace = mockNamespace();
File localStateDir = testDir.newFolder(name.getMethodName());
StateStoreSpec spec = StateStoreSpec.builder().name(name.getMethodName()).keyCoder(ByteArrayCoder.of()).valCoder(ByteArrayCoder.of()).localStateStoreDir(localStateDir).stream(name.getMethodName()).writeIOScheduler(scheduler.chooseThread()).readIOScheduler(scheduler.chooseThread()).checkpointIOScheduler(null).build();
store = StateStores.mvccKvBytesStoreSupplier(() -> namespace).get();
FutureUtils.result(store.init(spec));
doSetup();
}
use of org.apache.bookkeeper.statelib.api.StateStoreSpec in project bookkeeper by apache.
the class MVCCStoreFactoryImpl method newStore.
CompletableFuture<MVCCAsyncStore<byte[], byte[]>> newStore(long scId, long streamId, long rangeId) {
synchronized (this) {
if (closed) {
return FutureUtils.exception(new ObjectClosedException("MVCCStoreFactory"));
}
}
MVCCAsyncStore<byte[], byte[]> store = storeSupplier.get();
File targetDir = chooseLocalStoreDir(streamId);
// used for store ranges
Path rangeStorePath = Paths.get(targetDir.getAbsolutePath(), "ranges", normalizedName(scId), normalizedName(streamId), normalizedName(rangeId));
String storeName = String.format("%s/%s/%s", normalizedName(scId), normalizedName(streamId), normalizedName(rangeId));
// build a spec
StateStoreSpec spec = StateStoreSpec.builder().name(storeName).keyCoder(ByteArrayCoder.of()).valCoder(ByteArrayCoder.of()).localStateStoreDir(rangeStorePath.toFile()).stream(streamName(scId, streamId, rangeId)).writeIOScheduler(chooseWriteIOExecutor(streamId)).readIOScheduler(chooseReadIOExecutor(streamId)).checkpointStore(checkpointStore).checkpointDuration(Duration.ofMinutes(15)).checkpointIOScheduler(chooseCheckpointIOExecutor(streamId)).isReadonly(serveReadOnlyTable).build();
return store.init(spec).thenApply(ignored -> {
addStore(scId, streamId, rangeId, store);
return store;
});
}
Aggregations