Search in sources :

Example 6 with StateStoreSpec

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))));
    }
}
Also used : StateStoreSpec(org.apache.bookkeeper.statelib.api.StateStoreSpec) Test(org.junit.Test)

Example 7 with StateStoreSpec

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));
}
Also used : StateStoreSpec(org.apache.bookkeeper.statelib.api.StateStoreSpec) Test(org.junit.Test)

Example 8 with StateStoreSpec

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());
}
Also used : StateStoreSpec(org.apache.bookkeeper.statelib.api.StateStoreSpec) Test(org.junit.Test)

Example 9 with StateStoreSpec

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();
}
Also used : StateStoreSpec(org.apache.bookkeeper.statelib.api.StateStoreSpec) File(java.io.File) Before(org.junit.Before)

Example 10 with StateStoreSpec

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;
    });
}
Also used : Path(java.nio.file.Path) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StateStoreSpec(org.apache.bookkeeper.statelib.api.StateStoreSpec) File(java.io.File)

Aggregations

StateStoreSpec (org.apache.bookkeeper.statelib.api.StateStoreSpec)10 Test (org.junit.Test)7 File (java.io.File)2 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 Getter (lombok.Getter)1 Slf4j (lombok.extern.slf4j.Slf4j)1