use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.
the class ZKCounterTest method testCounterConcurrentUpdates.
@Test(timeout = 30000)
public void testCounterConcurrentUpdates() {
ZKStoreHelper storeHelper = spy(new ZKStoreHelper(cli, executor));
storeHelper.createZNodeIfNotExist("/store/scope").join();
ZkInt96Counter counter1 = spy(new ZkInt96Counter(storeHelper));
ZkInt96Counter counter2 = spy(new ZkInt96Counter(storeHelper));
ZkInt96Counter counter3 = spy(new ZkInt96Counter(storeHelper));
// first call should get the new range from store
Int96 counter = counter1.getNextCounter().join();
// verify that the generated counter is from new range
assertEquals(0, counter.getMsb());
assertEquals(1L, counter.getLsb());
assertEquals(counter1.getCounterForTesting(), counter);
Int96 limit = counter1.getLimitForTesting();
assertEquals(ZkInt96Counter.COUNTER_RANGE, limit.getLsb());
counter3.getRefreshFuture().join();
assertEquals(ZkInt96Counter.COUNTER_RANGE, counter3.getCounterForTesting().getLsb());
assertEquals(ZkInt96Counter.COUNTER_RANGE * 2, counter3.getLimitForTesting().getLsb());
counter2.getRefreshFuture().join();
assertEquals(ZkInt96Counter.COUNTER_RANGE * 2, counter2.getCounterForTesting().getLsb());
assertEquals(ZkInt96Counter.COUNTER_RANGE * 3, counter2.getLimitForTesting().getLsb());
counter1.getRefreshFuture().join();
assertEquals(ZkInt96Counter.COUNTER_RANGE * 3, counter1.getCounterForTesting().getLsb());
assertEquals(ZkInt96Counter.COUNTER_RANGE * 4, counter1.getLimitForTesting().getLsb());
}
use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.
the class ZKStreamMetadataStoreTest method testCommittedTxnGc.
@Test
public void testCommittedTxnGc() {
String scope = "scopeGC";
String stream = "stream";
store.createScope(scope, null, executor).join();
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
store.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
store.setState(scope, stream, State.ACTIVE, null, executor).join();
ZKStreamMetadataStore zkStore = (ZKStreamMetadataStore) store;
ZKStoreHelper storeHelper = zkStore.getStoreHelper();
UUID txnId = new UUID(0L, 0L);
createAndCommitTxn(txnId, scope, stream).join();
// getTxnStatus
TxnStatus status = store.transactionStatus(scope, stream, txnId, null, executor).join();
assertEquals(TxnStatus.COMMITTED, status);
// verify txns are created in a new batch
List<Integer> batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).collect(Collectors.toList());
assertEquals(1, batches.size());
int firstBatch = batches.get(0);
// create another transaction after introducing a delay greater than gcperiod so that it gets created in a new batch
Futures.delayedFuture(() -> createAndCommitTxn(new UUID(0L, 1L), scope, stream), Duration.ofSeconds(2).toMillis(), executor).join();
// verify that this gets created in a new batch
batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
assertEquals(2, batches.size());
assertTrue(batches.contains(firstBatch));
int secondBatch = batches.stream().max(Integer::compare).get();
assertTrue(secondBatch > firstBatch);
// let one more gc cycle run and verify that these two batches are not cleaned up.
batches = Futures.delayedFuture(() -> storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH), Duration.ofSeconds(2).toMillis(), executor).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
assertEquals(2, batches.size());
// create third transaction after introducing a delay greater than gcperiod so that it gets created in a new batch
Futures.delayedFuture(() -> createAndCommitTxn(new UUID(0L, 2L), scope, stream), Duration.ofSeconds(2).toMillis(), executor).join();
// Verify that a new batch is created here.
batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
int thirdBatch = batches.stream().max(Long::compare).get();
assertTrue(thirdBatch > secondBatch);
// wait for more than TTL, then do another getTxnStatus
status = Futures.delayedFuture(() -> store.transactionStatus(scope, stream, txnId, null, executor), Duration.ofSeconds(2).toMillis(), executor).join();
assertEquals(TxnStatus.UNKNOWN, status);
// verify that only 2 latest batches remain and that firstBatch has been GC'd
batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
assertEquals(2, batches.size());
assertFalse(batches.contains(firstBatch));
assertTrue(batches.contains(secondBatch));
assertTrue(batches.contains(thirdBatch));
}
use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.
the class PravegaTablesStreamTest method setup.
@Override
public void setup() throws Exception {
SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executor);
GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executor);
orderer = new ZkOrderedStore("txnOrderer", new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor), executor);
store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, Duration.ofSeconds(1), authHelper);
}
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));
}
}
Aggregations