use of io.pravega.controller.store.stream.records.ActiveTxnRecord 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());
}
Aggregations