Search in sources :

Example 6 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class ZkStreamTest method testGetActiveTxn.

@Test(timeout = 30000)
public void testGetActiveTxn() throws Exception {
    ZKStoreHelper storeHelper = spy(new ZKStoreHelper(cli, executor));
    ZkOrderedStore orderer = new ZkOrderedStore("txn", storeHelper, executor);
    ZKStream stream = new ZKStream("scope", "stream", storeHelper, executor, orderer);
    final int startingSegmentNumber = 0;
    storeHelper.createZNodeIfNotExist("/store/scope").join();
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
    OperationContext context = new TestOperationContext();
    stream.create(configuration1, System.currentTimeMillis(), startingSegmentNumber, context).join();
    stream.updateState(State.ACTIVE, context).join();
    UUID txId = stream.generateNewTxnId(0, 0L, context).join();
    stream.createTransaction(txId, 1000L, 1000L, context).join();
    String activeTxPath = stream.getActiveTxPath(0, txId.toString());
    // throw DataNotFoundException for txn path
    doReturn(Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, "txn data not found"))).when(storeHelper).getData(eq(activeTxPath), any());
    Map<UUID, ActiveTxnRecord> result = stream.getActiveTxns(context).join();
    // verify that call succeeds and no active txns were found
    assertTrue(result.isEmpty());
    // throw generic exception for txn path
    doReturn(Futures.failedFuture(new RuntimeException())).when(storeHelper).getData(eq(activeTxPath), any());
    ZKStream stream2 = new ZKStream("scope", "stream", storeHelper, executor, orderer);
    // verify that the call fails
    AssertExtensions.assertFutureThrows("", stream2.getActiveTxns(context), e -> Exceptions.unwrap(e) instanceof RuntimeException);
    reset(storeHelper);
    ZKStream stream3 = new ZKStream("scope", "stream", storeHelper, executor, orderer);
    result = stream3.getActiveTxns(context).join();
    assertEquals(1, result.size());
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) TestOperationContext(io.pravega.controller.store.TestOperationContext) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class StreamTest method testZkCreateStream.

@Test(timeout = 10000)
public void testZkCreateStream() throws ExecutionException, InterruptedException {
    ZKStoreHelper zkStoreHelper = new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService());
    ZkOrderedStore orderer = new ZkOrderedStore("txn", zkStoreHelper, executorService());
    ZKStream zkStream = new ZKStream("test1", "test1", zkStoreHelper, executorService(), orderer);
    testStream(zkStream);
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Test(org.junit.Test)

Example 8 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class StreamTest method testConcurrentGetSuccessorScaleZk.

@Test(timeout = 10000)
public void testConcurrentGetSuccessorScaleZk() throws Exception {
    try (final StreamMetadataStore store = new ZKStreamMetadataStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService())) {
        ZKStoreHelper zkStoreHelper = new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService());
        testConcurrentGetSuccessorScale(store, (x, y) -> new ZKStream(x, y, zkStoreHelper, executorService(), orderer));
    }
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Test(org.junit.Test)

Example 9 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class ZKCounterTest method testCounter.

@Test(timeout = 30000)
public void testCounter() throws Exception {
    ZKStoreHelper storeHelper = spy(new ZKStoreHelper(cli, executor));
    storeHelper.createZNodeIfNotExist("/store/scope").join();
    ZkInt96Counter zkStore = spy(new ZkInt96Counter(storeHelper));
    // first call should get the new range from store
    Int96 counter = zkStore.getNextCounter().join();
    // verify that the generated counter is from new range
    assertEquals(0, counter.getMsb());
    assertEquals(1L, counter.getLsb());
    assertEquals(zkStore.getCounterForTesting(), counter);
    Int96 limit = zkStore.getLimitForTesting();
    assertEquals(ZkInt96Counter.COUNTER_RANGE, limit.getLsb());
    // update the local counter to the end of the current range (limit - 1)
    zkStore.setCounterAndLimitForTesting(limit.getMsb(), limit.getLsb() - 1, limit.getMsb(), limit.getLsb());
    // now call three getNextCounters concurrently.. first one to execute should increment the counter to limit.
    // other two will result in refresh being called.
    CompletableFuture<Int96> future1 = zkStore.getNextCounter();
    CompletableFuture<Int96> future2 = zkStore.getNextCounter();
    CompletableFuture<Int96> future3 = zkStore.getNextCounter();
    List<Int96> values = Futures.allOfWithResults(Arrays.asList(future1, future2, future3)).join();
    // second and third should result in refresh being called. Verify method call count is 3, twice for now and
    // once for first time when counter is set
    verify(zkStore, times(3)).refreshRangeIfNeeded();
    verify(zkStore, times(2)).getRefreshFuture();
    assertTrue(values.stream().anyMatch(x -> x.compareTo(new Int96(limit.getMsb(), limit.getLsb())) == 0));
    assertTrue(values.stream().anyMatch(x -> x.compareTo(new Int96(0, limit.getLsb() + 1)) == 0));
    assertTrue(values.stream().anyMatch(x -> x.compareTo(new Int96(0, limit.getLsb() + 2)) == 0));
    // verify that counter and limits are increased
    Int96 newCounter = zkStore.getCounterForTesting();
    Int96 newLimit = zkStore.getLimitForTesting();
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 2, newLimit.getLsb());
    assertEquals(0, newLimit.getMsb());
    assertEquals(ZkInt96Counter.COUNTER_RANGE + 2, newCounter.getLsb());
    assertEquals(0, newCounter.getMsb());
    // set range in store to have lsb = Long.Max - 100
    VersionedMetadata<Int96> data = new VersionedMetadata<>(new Int96(0, Long.MAX_VALUE - 100), null);
    doReturn(CompletableFuture.completedFuture(data)).when(storeHelper).getData(eq(ZkInt96Counter.COUNTER_PATH), any());
    // set local limit to {msb, Long.Max - 100}
    zkStore.setCounterAndLimitForTesting(0, Long.MAX_VALUE - 100, 0, Long.MAX_VALUE - 100);
    // now the call to getNextCounter should result in another refresh
    zkStore.getNextCounter().join();
    // verify that post refresh counter and limit have different msb
    Int96 newCounter2 = zkStore.getCounterForTesting();
    Int96 newLimit2 = zkStore.getLimitForTesting();
    assertEquals(1, newLimit2.getMsb());
    assertEquals(ZkInt96Counter.COUNTER_RANGE - 100, newLimit2.getLsb());
    assertEquals(0, newCounter2.getMsb());
    assertEquals(Long.MAX_VALUE - 99, newCounter2.getLsb());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) RetryOneTime(org.apache.curator.retry.RetryOneTime) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Int96(io.pravega.common.lang.Int96) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Futures(io.pravega.common.concurrent.Futures) Assert.assertEquals(org.junit.Assert.assertEquals) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Int96(io.pravega.common.lang.Int96) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Test(org.junit.Test)

Example 10 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class ZkOrderedStoreTest method testSync.

@Test(timeout = 30000)
public void testSync() {
    String test = "test";
    String scope = "test";
    String stream = "test";
    ZKStoreHelper zkStoreHelper = spy(this.zkStoreHelper);
    ZkOrderedStore store = new ZkOrderedStore(test, zkStoreHelper, executor, 1);
    store.addEntity(scope, stream, test + 1, 0L).join();
    store.getEntitiesWithPosition(scope, stream).join();
    verify(zkStoreHelper, times(1)).sync(any());
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Test(org.junit.Test)

Aggregations

ZKStoreHelper (io.pravega.controller.store.ZKStoreHelper)12 Test (org.junit.Test)9 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 TestingServerStarter (io.pravega.test.common.TestingServerStarter)3 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)2 Int96 (io.pravega.common.lang.Int96)2 TestOperationContext (io.pravega.controller.store.TestOperationContext)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 Before (org.junit.Before)2 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)1 Futures (io.pravega.common.concurrent.Futures)1 SegmentHelper (io.pravega.controller.server.SegmentHelper)1 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)1 PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)1 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)1 ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1