use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class StreamTransactionMetadataTasksTest method partialTxnCreationTest.
@Test(timeout = 10000)
public void partialTxnCreationTest() {
// Create mock writer objects.
EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
// Create transaction tasks.
txnTasks = new StreamTransactionMetadataTasks(streamStore, SegmentHelperMock.getFailingSegmentHelperMock(), executor, "host", new GrpcAuthHelper(this.authEnabled, "secret", 600));
txnTasks.initializeStreamWriters(commitWriter, abortWriter);
// Create ControllerService.
consumer = new ControllerService(kvtStore, kvtMetadataTasks, streamStore, bucketStore, streamMetadataTasks, txnTasks, segmentHelperMock, executor, null, requestTracker);
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
// Create stream and scope
Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, consumer.createScope(SCOPE, 0L).join().getStatus());
Assert.assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamMetadataTasks.createStream(SCOPE, STREAM, configuration1, 0, 0L).join());
// Create partial transaction
final long lease = 10000;
AssertExtensions.assertFutureThrows("Transaction creation fails, although a new txn id gets added to the store", txnTasks.createTxn(SCOPE, STREAM, lease, 0L, 1024 * 1024L), e -> e instanceof RuntimeException);
// Ensure that exactly one transaction is active on the stream.
Set<UUID> txns = streamStore.getActiveTxns(SCOPE, STREAM, null, executor).join().keySet();
assertEquals(1, txns.size());
// Ensure that transaction state is OPEN.
UUID txn1 = txns.stream().findFirst().get();
assertEquals(TxnStatus.OPEN, streamStore.transactionStatus(SCOPE, STREAM, txn1, null, executor).join());
// Ensure that timeout service knows about the transaction.
assertTrue(txnTasks.getTimeoutService().containsTxn(SCOPE, STREAM, txn1));
}
use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class StreamTransactionMetadataTasksTest method txnCreationTest.
@Test(timeout = 10000)
public void txnCreationTest() {
// Create mock writer objects.
EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
StreamMetadataStore streamStoreMock = spy(StreamStoreFactory.createZKStore(zkClient, executor));
// Create transaction tasks.
txnTasks = new StreamTransactionMetadataTasks(streamStoreMock, SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(this.authEnabled, "secret", 600));
txnTasks.initializeStreamWriters(commitWriter, abortWriter);
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
// Create stream and scope
streamStoreMock.createScope(SCOPE, null, executor).join();
streamStoreMock.createStream(SCOPE, STREAM, configuration1, System.currentTimeMillis(), null, executor).join();
streamStoreMock.setState(SCOPE, STREAM, State.ACTIVE, null, executor).join();
// mock streamMetadataStore.generateTxnId should throw excecption first time.
// Note: it should be retried.
// now the id should have been generated
doAnswer(new Answer<CompletableFuture<UUID>>() {
AtomicInteger count = new AtomicInteger(0);
@Override
public CompletableFuture<UUID> answer(InvocationOnMock invocation) throws Throwable {
// first time throw exception.
if (count.getAndIncrement() == 0) {
return Futures.failedFuture(StoreException.create(StoreException.Type.WRITE_CONFLICT, "write conflict on counter update"));
}
// subsequent times call origin method
@SuppressWarnings("unchecked") CompletableFuture<UUID> future = (CompletableFuture<UUID>) invocation.callRealMethod();
return future;
}
}).when(streamStoreMock).generateTransactionId(eq(SCOPE), eq(STREAM), any(), any());
doAnswer(new Answer<CompletableFuture<VersionedTransactionData>>() {
AtomicInteger count = new AtomicInteger(0);
@Override
public CompletableFuture<VersionedTransactionData> answer(InvocationOnMock invocation) throws Throwable {
// first time throw exception.
if (count.getAndIncrement() == 0) {
return Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, "Epoch not found"));
}
// subsequent times call origin method
@SuppressWarnings("unchecked") CompletableFuture<VersionedTransactionData> future = (CompletableFuture<VersionedTransactionData>) invocation.callRealMethod();
return future;
}
}).when(streamStoreMock).createTransaction(any(), any(), any(), anyLong(), anyLong(), any(), any());
Pair<VersionedTransactionData, List<StreamSegmentRecord>> txn = txnTasks.createTxn(SCOPE, STREAM, 10000L, 0L, 1024 * 1024L).join();
// verify that generate transaction id is called 3 times
verify(streamStoreMock, times(3)).generateTransactionId(any(), any(), any(), any());
// verify that create transaction is called 2 times
verify(streamStoreMock, times(2)).createTransaction(any(), any(), any(), anyLong(), anyLong(), any(), any());
// verify that the txn id that is generated is of type ""
UUID txnId = txn.getKey().getId();
assertEquals(0, (int) (txnId.getMostSignificantBits() >> 32));
assertEquals(2, txnId.getLeastSignificantBits());
}
use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class PravegaTablesStoreHelperTest method testNoRetriesOnUpdate.
@Test
public void testNoRetriesOnUpdate() {
SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executor);
GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
PravegaTablesStoreHelper storeHelper = spy(new PravegaTablesStoreHelper(segmentHelper, authHelper, executor, 2));
// region connection dropped
CompletableFuture<Void> connectionDropped = Futures.failedFuture(new WireCommandFailedException(WireCommandType.UPDATE_TABLE_ENTRIES, WireCommandFailedException.Reason.ConnectionDropped));
doAnswer(x -> connectionDropped).when(segmentHelper).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.addNewEntry("table", "key", new byte[0], x -> x, 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
verify(segmentHelper, times(1)).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.updateEntry("table", "key", new byte[0], x -> x, new Version.LongVersion(0L), 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
verify(segmentHelper, times(2)).updateTableEntries(anyString(), any(), anyString(), anyLong());
// endregion
// region connectionfailed
CompletableFuture<Void> connectionFailed = Futures.failedFuture(new WireCommandFailedException(WireCommandType.UPDATE_TABLE_ENTRIES, WireCommandFailedException.Reason.ConnectionFailed));
doAnswer(x -> connectionFailed).when(segmentHelper).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.addNewEntry("table", "key", new byte[0], x -> x, 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
verify(segmentHelper, times(3)).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.updateEntry("table", "key", new byte[0], x -> x, new Version.LongVersion(0L), 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
verify(segmentHelper, times(4)).updateTableEntries(anyString(), any(), anyString(), anyLong());
// endregion
CompletableFuture<Void> unknownHost = Futures.failedFuture(new WireCommandFailedException(WireCommandType.UPDATE_TABLE_ENTRIES, WireCommandFailedException.Reason.UnknownHost));
doAnswer(x -> unknownHost).when(segmentHelper).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.addNewEntry("table", "key", new byte[0], x -> x, 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
// this should be retried. we have configured 2 retries, so 2 retries should happen hence jump from 4 to 6.
verify(segmentHelper, times(6)).updateTableEntries(anyString(), any(), anyString(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.updateEntry("table", "key", new byte[0], x -> x, new Version.LongVersion(0L), 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
verify(segmentHelper, times(8)).updateTableEntries(anyString(), any(), anyString(), anyLong());
}
Aggregations