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());
}
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);
}
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));
}
}
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());
}
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());
}
Aggregations