Search in sources :

Example 11 with ActiveTxnRecord

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

Aggregations

ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)11 UUID (java.util.UUID)8 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Futures (io.pravega.common.concurrent.Futures)4 Version (io.pravega.controller.store.Version)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Preconditions (com.google.common.base.Preconditions)3 CommittingTransactionsRecord (io.pravega.controller.store.stream.records.CommittingTransactionsRecord)3 CompletedTxnRecord (io.pravega.controller.store.stream.records.CompletedTxnRecord)3 EpochRecord (io.pravega.controller.store.stream.records.EpochRecord)3 EpochTransitionRecord (io.pravega.controller.store.stream.records.EpochTransitionRecord)3 HistoryTimeSeries (io.pravega.controller.store.stream.records.HistoryTimeSeries)3 RecordHelper (io.pravega.controller.store.stream.records.RecordHelper)3 RetentionSet (io.pravega.controller.store.stream.records.RetentionSet)3 SealedSegmentsMapShard (io.pravega.controller.store.stream.records.SealedSegmentsMapShard)3 StateRecord (io.pravega.controller.store.stream.records.StateRecord)3 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)3