use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class PravegaTablesStoreHelperTest method testRetriesExhausted.
@Test
public void testRetriesExhausted() {
SegmentHelper segmentHelper = spy(SegmentHelperMock.getSegmentHelperMockForTables(executor));
GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executor, 2);
CompletableFuture<Void> connectionDropped = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.ConnectionDropped));
doAnswer(x -> connectionDropped).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
CompletableFuture<Void> connectionFailed = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.ConnectionFailed));
doAnswer(x -> connectionFailed).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
AssertExtensions.assertFutureThrows("ConnectionFailed", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
CompletableFuture<Void> authFailed = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.AuthFailed));
doAnswer(x -> connectionFailed).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
AssertExtensions.assertFutureThrows("AuthFailed", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
}
use of io.pravega.controller.server.security.auth.GrpcAuthHelper 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.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class StreamTest method testConcurrentGetSuccessorScalePravegaTables.
@Test(timeout = 10000)
public void testConcurrentGetSuccessorScalePravegaTables() throws Exception {
@Cleanup SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executorService());
GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
try (final StreamMetadataStore store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService(), authHelper)) {
testConcurrentGetSuccessorScale(store, (x, y) -> {
PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
PravegaTablesScope scope = new PravegaTablesScope(x, storeHelper);
OperationContext context = getContext();
Futures.exceptionallyExpecting(scope.createScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataExistsException, null).join();
scope.addStreamToScope(y, context).join();
return new PravegaTablesStream(x, y, storeHelper, orderer, () -> 0, scope::getStreamsInScopeTableName, executorService());
});
}
}
use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class StreamMetadataTasksTest method testWorkflowCompletionTimeout.
@Test(timeout = 30000)
public void testWorkflowCompletionTimeout() {
EventHelper helper = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStorePartialMock).getHostTaskIndex());
StreamMetadataTasks streamMetadataTask = new StreamMetadataTasks(streamStorePartialMock, bucketStore, TaskStoreFactory.createZKStore(zkClient, executor), SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(authEnabled, "key", 300), helper);
streamMetadataTask.setCompletionTimeoutMillis(500L);
StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
String completion = "completion";
streamStorePartialMock.createStream(SCOPE, completion, configuration, System.currentTimeMillis(), null, executor).join();
streamStorePartialMock.setState(SCOPE, completion, State.ACTIVE, null, executor).join();
WriterMock requestEventWriter = new WriterMock(streamMetadataTask, executor);
streamMetadataTask.setRequestEventWriter(requestEventWriter);
StreamConfiguration configuration2 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build();
AssertExtensions.assertFutureThrows("update timedout", streamMetadataTask.updateStream(SCOPE, completion, configuration2, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
ControllerEvent event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof UpdateStreamEvent);
VersionedMetadata<StreamConfigurationRecord> configurationRecord = streamStorePartialMock.getConfigurationRecord(SCOPE, completion, null, executor).join();
assertTrue(configurationRecord.getObject().isUpdating());
Map<Long, Long> streamCut = Collections.singletonMap(0L, 0L);
AssertExtensions.assertFutureThrows("truncate timedout", streamMetadataTask.truncateStream(SCOPE, completion, streamCut, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof TruncateStreamEvent);
VersionedMetadata<StreamTruncationRecord> truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, completion, null, executor).join();
assertTrue(truncationRecord.getObject().isUpdating());
AssertExtensions.assertFutureThrows("seal timedout", streamMetadataTask.sealStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof SealStreamEvent);
VersionedMetadata<State> state = streamStorePartialMock.getVersionedState(SCOPE, completion, null, executor).join();
assertEquals(state.getObject(), State.SEALING);
streamStorePartialMock.setState(SCOPE, completion, State.SEALED, null, executor).join();
AssertExtensions.assertFutureThrows("delete timedout", streamMetadataTask.deleteStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof DeleteStreamEvent);
}
use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.
the class StreamTransactionMetadataTasksTest method writerInitializationTest.
@Test(timeout = 10000)
public void writerInitializationTest() throws Exception {
EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
StreamMetadataStore streamStoreMock = spy(StreamStoreFactory.createZKStore(zkClient, executor));
final long leasePeriod = 5000;
// region close before initialize
txnTasks = new StreamTransactionMetadataTasks(streamStoreMock, SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(this.authEnabled, "secret", 300));
CompletableFuture<Void> future = txnTasks.writeCommitEvent(new CommitEvent("scope", "stream", 0));
assertFalse(future.isDone());
txnTasks.close();
AssertExtensions.assertFutureThrows("", future, e -> Exceptions.unwrap(e) instanceof CancellationException);
// endregion
// region test initialize writers with client factory
txnTasks = new StreamTransactionMetadataTasks(streamStoreMock, SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(this.authEnabled, "secret", 300));
future = txnTasks.writeCommitEvent(new CommitEvent("scope", "stream", 0));
EventStreamClientFactory cfMock = mock(EventStreamClientFactory.class);
ControllerEventProcessorConfig eventProcConfigMock = mock(ControllerEventProcessorConfig.class);
String commitStream = "commitStream";
doAnswer(x -> commitStream).when(eventProcConfigMock).getCommitStreamName();
doAnswer(x -> commitWriter).when(cfMock).createEventWriter(eq(commitStream), any(), any());
String abortStream = "abortStream";
doAnswer(x -> abortStream).when(eventProcConfigMock).getAbortStreamName();
doAnswer(x -> abortWriter).when(cfMock).createEventWriter(eq(abortStream), any(), any());
// future should not have completed as we have not initialized the writers.
assertFalse(future.isDone());
// initialize the writers. write future should have completed now.
txnTasks.initializeStreamWriters(cfMock, eventProcConfigMock);
assertTrue(Futures.await(future));
txnTasks.close();
// endregion
// region test method calls and initialize writers with direct writer set up method call
txnTasks = new StreamTransactionMetadataTasks(streamStoreMock, SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(this.authEnabled, "secret", 300));
streamStore.createScope(SCOPE, null, executor).join();
streamStore.createStream(SCOPE, STREAM, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), 1L, null, executor).join();
streamStore.setState(SCOPE, STREAM, State.ACTIVE, null, executor).join();
CompletableFuture<Pair<VersionedTransactionData, List<StreamSegmentRecord>>> createFuture = txnTasks.createTxn(SCOPE, STREAM, leasePeriod, 0L, 0L);
// create and ping transactions should not wait for writer initialization and complete immediately.
createFuture.join();
assertTrue(Futures.await(createFuture));
UUID txnId = createFuture.join().getKey().getId();
CompletableFuture<PingTxnStatus> pingFuture = txnTasks.pingTxn(SCOPE, STREAM, txnId, leasePeriod, 0L);
assertTrue(Futures.await(pingFuture));
CompletableFuture<TxnStatus> commitFuture = txnTasks.commitTxn(SCOPE, STREAM, txnId, 0L);
assertFalse(commitFuture.isDone());
txnTasks.initializeStreamWriters(commitWriter, abortWriter);
assertTrue(Futures.await(commitFuture));
UUID txnId2 = txnTasks.createTxn(SCOPE, STREAM, leasePeriod, 0L, 1024 * 1024L).join().getKey().getId();
assertTrue(Futures.await(txnTasks.abortTxn(SCOPE, STREAM, txnId2, null, 0L)));
}
Aggregations