Search in sources :

Example 1 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class StreamTransactionMetadataTasksTest method failOverTests.

@Test
public void failOverTests() throws CheckpointStoreException, InterruptedException {
    // Create mock writer objects.
    EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
    EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
    EventStreamReader<CommitEvent> commitReader = commitWriter.getReader();
    EventStreamReader<AbortEvent> abortReader = abortWriter.getReader();
    consumer = new ControllerService(streamStore, hostStore, streamMetadataTasks, txnTasks, segmentHelperMock, executor, null);
    // Create test scope and stream.
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(STREAM).scalingPolicy(policy1).build();
    Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, consumer.createScope(SCOPE).join().getStatus());
    Assert.assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamMetadataTasks.createStream(SCOPE, STREAM, configuration1, System.currentTimeMillis()).join());
    // Set up txn task for creating transactions from a failedHost.
    StreamTransactionMetadataTasks failedTxnTasks = new StreamTransactionMetadataTasks(streamStore, hostStore, segmentHelperMock, executor, "failedHost", connectionFactory, false, "");
    failedTxnTasks.initializeStreamWriters("commitStream", new EventStreamWriterMock<>(), "abortStream", new EventStreamWriterMock<>());
    // Create 3 transactions from failedHost.
    VersionedTransactionData tx1 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
    VersionedTransactionData tx2 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
    VersionedTransactionData tx3 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
    // Ping another txn from failedHost.
    UUID txnId = UUID.randomUUID();
    streamStore.createTransaction(SCOPE, STREAM, txnId, 10000, 30000, 30000, null, executor).join();
    PingTxnStatus pingStatus = failedTxnTasks.pingTxn(SCOPE, STREAM, txnId, 10000, null).join();
    VersionedTransactionData tx4 = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
    // Validate versions of all txn
    Assert.assertEquals(0, tx1.getVersion());
    Assert.assertEquals(0, tx2.getVersion());
    Assert.assertEquals(0, tx3.getVersion());
    Assert.assertEquals(1, tx4.getVersion());
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    // Validate the txn index.
    Assert.assertEquals(1, streamStore.listHostsOwningTxn().join().size());
    // Change state of one txn to COMMITTING.
    TxnStatus txnStatus2 = streamStore.sealTransaction(SCOPE, STREAM, tx2.getId(), true, Optional.empty(), null, executor).thenApply(AbstractMap.SimpleEntry::getKey).join();
    Assert.assertEquals(TxnStatus.COMMITTING, txnStatus2);
    // Change state of another txn to ABORTING.
    TxnStatus txnStatus3 = streamStore.sealTransaction(SCOPE, STREAM, tx3.getId(), false, Optional.empty(), null, executor).thenApply(AbstractMap.SimpleEntry::getKey).join();
    Assert.assertEquals(TxnStatus.ABORTING, txnStatus3);
    // Create transaction tasks for sweeping txns from failedHost.
    txnTasks = new StreamTransactionMetadataTasks(streamStore, hostStore, segmentHelperMock, executor, "host", connectionFactory, false, "");
    TxnSweeper txnSweeper = new TxnSweeper(streamStore, txnTasks, 100, executor);
    // Before initializing, txnSweeper.sweepFailedHosts would throw an error
    AssertExtensions.assertThrows("IllegalStateException before initialization", txnSweeper.sweepFailedProcesses(() -> Collections.singleton("host")), ex -> ex instanceof IllegalStateException);
    // Initialize stream writers.
    txnTasks.initializeStreamWriters("commitStream", commitWriter, "abortStream", abortWriter);
    // Validate that txnTasks is ready.
    assertTrue(txnTasks.isReady());
    // Sweep txns that were being managed by failedHost.
    txnSweeper.sweepFailedProcesses(() -> Collections.singleton("host")).join();
    // Validate that sweeping completes correctly.
    Assert.assertEquals(0, streamStore.listHostsOwningTxn().join().size());
    Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx1.getId(), null, executor).join());
    Assert.assertEquals(TxnStatus.COMMITTING, streamStore.transactionStatus(SCOPE, STREAM, tx2.getId(), null, executor).join());
    Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx3.getId(), null, executor).join());
    Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx4.getId(), null, executor).join());
    // Create commit and abort event processors.
    ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
    BlockingQueue<CommitEvent> processedCommitEvents = new LinkedBlockingQueue<>();
    BlockingQueue<AbortEvent> processedAbortEvents = new LinkedBlockingQueue<>();
    createEventProcessor("commitRG", "commitStream", commitReader, commitWriter, () -> new CommitEventProcessor(streamStore, streamMetadataTasks, hostStore, executor, segmentHelperMock, connectionFactory, processedCommitEvents));
    createEventProcessor("abortRG", "abortStream", abortReader, abortWriter, () -> new ConcurrentEventProcessor<>(new AbortRequestHandler(streamStore, streamMetadataTasks, hostStore, executor, segmentHelperMock, connectionFactory, processedAbortEvents), executor));
    // Wait until the commit event is processed and ensure that the txn state is COMMITTED.
    CommitEvent commitEvent = processedCommitEvents.take();
    assertEquals(tx2.getId(), commitEvent.getTxid());
    assertEquals(TxnStatus.COMMITTED, streamStore.transactionStatus(SCOPE, STREAM, tx2.getId(), null, executor).join());
    // Wait until 3 abort events are processed and ensure that the txn state is ABORTED.
    Predicate<AbortEvent> predicate = event -> event.getTxid().equals(tx1.getId()) || event.getTxid().equals(tx3.getId()) || event.getTxid().equals(tx4.getId());
    AbortEvent abortEvent1 = processedAbortEvents.take();
    assertTrue(predicate.test(abortEvent1));
    AbortEvent abortEvent2 = processedAbortEvents.take();
    assertTrue(predicate.test(abortEvent2));
    AbortEvent abortEvent3 = processedAbortEvents.take();
    assertTrue(predicate.test(abortEvent3));
    assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx1.getId(), null, executor).join());
    assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx3.getId(), null, executor).join());
    assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx4.getId(), null, executor).join());
}
Also used : CommitEvent(io.pravega.shared.controller.event.CommitEvent) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) SneakyThrows(lombok.SneakyThrows) AssertExtensions(io.pravega.test.common.AssertExtensions) ReaderGroup(io.pravega.client.stream.ReaderGroup) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) AbortRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.AbortRequestHandler) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) After(org.junit.After) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ExceptionHandler(io.pravega.controller.eventProcessor.ExceptionHandler) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) EventProcessorConfig(io.pravega.controller.eventProcessor.EventProcessorConfig) Predicate(java.util.function.Predicate) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CuratorFramework(org.apache.curator.framework.CuratorFramework) ConcurrentEventProcessor(io.pravega.controller.eventProcessor.impl.ConcurrentEventProcessor) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) TxnStatus(io.pravega.controller.store.stream.TxnStatus) ClientFactory(io.pravega.client.ClientFactory) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) CommitEventProcessor(io.pravega.controller.server.eventProcessor.CommitEventProcessor) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Futures(io.pravega.common.concurrent.Futures) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) EventProcessor(io.pravega.controller.eventProcessor.impl.EventProcessor) CheckpointStoreFactory(io.pravega.controller.store.checkpoint.CheckpointStoreFactory) EventProcessorGroupConfigImpl(io.pravega.controller.eventProcessor.impl.EventProcessorGroupConfigImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AbortEvent(io.pravega.shared.controller.event.AbortEvent) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) TestingServerStarter(io.pravega.test.common.TestingServerStarter) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) Before(org.junit.Before) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Iterator(java.util.Iterator) Assert.assertTrue(org.junit.Assert.assertTrue) EventStreamReader(io.pravega.client.stream.EventStreamReader) Test(org.junit.Test) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) Mockito(org.mockito.Mockito) AbstractMap(java.util.AbstractMap) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) Assert(org.junit.Assert) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ControllerService(io.pravega.controller.server.ControllerService) AbstractMap(java.util.AbstractMap) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CommitEvent(io.pravega.shared.controller.event.CommitEvent) AbortEvent(io.pravega.shared.controller.event.AbortEvent) UUID(java.util.UUID) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CommitEventProcessor(io.pravega.controller.server.eventProcessor.CommitEventProcessor) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) AbortRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.AbortRequestHandler) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 2 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingLeaseTooLarge.

@Test(timeout = 10000)
public void testPingLeaseTooLarge() {
    UUID txnId = UUID.randomUUID();
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    int version = txData.getVersion();
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, SCALE_GRACE_PERIOD + 1);
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, Config.MAX_LEASE_VALUE + 1);
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, Config.MAX_SCALE_GRACE_PERIOD + 1);
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, 10 * LEASE + 1);
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Test(org.junit.Test)

Example 3 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testControllerPingFailureMaxExecutionTimeExceeded.

@Test(timeout = 10000)
public void testControllerPingFailureMaxExecutionTimeExceeded() throws InterruptedException {
    int lease = 10;
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, lease, SCALE_GRACE_PERIOD).thenApply(x -> ModelHelper.decode(x.getKey())).join();
    TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
    PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, 1000 * lease).join();
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
    txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreClient(io.pravega.controller.store.client.StoreClient) RetryOneTime(org.apache.curator.retry.RetryOneTime) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ClientConfig(io.pravega.client.ClientConfig) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) Test(org.junit.Test)

Example 4 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testControllerPingLeaseTooLarge.

@Test(timeout = 10000)
public void testControllerPingLeaseTooLarge() {
    int lease = 10;
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, lease, SCALE_GRACE_PERIOD).thenApply(x -> ModelHelper.decode(x.getKey())).join();
    PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, SCALE_GRACE_PERIOD + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, Config.MAX_LEASE_VALUE + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, Config.MAX_SCALE_GRACE_PERIOD + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, 1000 * lease + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 2 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    txnId = ModelHelper.decode(txData.getId());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, SCALE_GRACE_PERIOD + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, Config.MAX_LEASE_VALUE + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, Config.MAX_SCALE_GRACE_PERIOD + 1).join();
    Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
    pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, 3 * LEASE).join();
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreClient(io.pravega.controller.store.client.StoreClient) RetryOneTime(org.apache.curator.retry.RetryOneTime) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ClientConfig(io.pravega.client.ClientConfig) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Test(org.junit.Test)

Example 5 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class ControllerImplTest method setup.

@Before
public void setup() throws IOException {
    // Setup test server generating different success and failure responses.
    testServerImpl = new ControllerServiceImplBase() {

        @Override
        public void createStream(StreamConfig request, StreamObserver<CreateStreamStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1") || request.getStreamInfo().getStream().equals("stream8")) {
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SCOPE_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.STREAM_EXISTS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream5")) {
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.INVALID_STREAM_NAME).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("streamparallel")) {
                // Simulating delay in sending response.
                Exceptions.handleInterrupted(() -> Thread.sleep(500));
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("streamdelayed")) {
                // Simulating delay in sending response. This is used for the keepalive test,
                // where response time > 30 seconds is required to simulate a failure.
                Exceptions.handleInterrupted(() -> Thread.sleep(40000));
                responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("streamretryfailure")) {
                responseObserver.onError(Status.UNKNOWN.withDescription("Transport error").asRuntimeException());
            } else if (request.getStreamInfo().getStream().equals("streamretrysuccess")) {
                if (retryAttempts.incrementAndGet() > 3) {
                    responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
                    responseObserver.onCompleted();
                } else {
                    responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
                }
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void updateStream(StreamConfig request, StreamObserver<UpdateStreamStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream5")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.UNRECOGNIZED).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void truncateStream(Controller.StreamCut request, StreamObserver<UpdateStreamStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream5")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.UNRECOGNIZED).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void sealStream(StreamInfo request, StreamObserver<UpdateStreamStatus> responseObserver) {
            if (request.getStream().equals("stream1")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream2")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream3")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream4")) {
                responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void deleteStream(StreamInfo request, StreamObserver<DeleteStreamStatus> responseObserver) {
            if (request.getStream().equals("stream1")) {
                responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream2")) {
                responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream3")) {
                responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream4")) {
                responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.STREAM_NOT_SEALED).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void getCurrentSegments(StreamInfo request, StreamObserver<SegmentRanges> responseObserver) {
            if (request.getStream().equals("stream1")) {
                responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream1", 6, 0.0, 0.4)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream1", 7, 0.4, 1.0)).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("stream8")) {
                responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream8", 9, 0.0, 0.5)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream8", 10, 0.5, 1.0)).build());
                responseObserver.onCompleted();
            } else if (request.getStream().equals("streamparallel")) {
                Exceptions.handleInterrupted(() -> Thread.sleep(500));
                responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "streamparallel", 0, 0.0, 0.4)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "streamparallel", 1, 0.4, 1.0)).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void getSegments(GetSegmentsRequest request, StreamObserver<SegmentsAtTime> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                SegmentId segment1 = ModelHelper.createSegmentId("scope1", "stream1", 0);
                SegmentId segment2 = ModelHelper.createSegmentId("scope1", "stream1", 1);
                responseObserver.onNext(SegmentsAtTime.newBuilder().addSegments(SegmentLocation.newBuilder().setSegmentId(segment1).setOffset(10).build()).addSegments(SegmentLocation.newBuilder().setSegmentId(segment2).setOffset(20).build()).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream8")) {
                SegmentId segment1 = ModelHelper.createSegmentId("scope1", "stream8", 0);
                SegmentId segment2 = ModelHelper.createSegmentId("scope1", "stream8", 1);
                SegmentId segment3 = ModelHelper.createSegmentId("scope1", "stream8", 2);
                responseObserver.onNext(SegmentsAtTime.newBuilder().addSegments(SegmentLocation.newBuilder().setSegmentId(segment1).setOffset(10).build()).addSegments(SegmentLocation.newBuilder().setSegmentId(segment2).setOffset(20).build()).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void getSegmentsImmediatlyFollowing(SegmentId request, StreamObserver<SuccessorResponse> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                Map<SegmentId, Pair<Double, Double>> result = new HashMap<>();
                if (request.getSegmentNumber() == 0) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 2), Pair.of(0.0, 0.25));
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 3), Pair.of(0.25, 0.5));
                } else if (request.getSegmentNumber() == 1) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 4), Pair.of(0.5, 0.75));
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 5), Pair.of(0.75, 1.0));
                } else if (request.getSegmentNumber() == 2 || request.getSegmentNumber() == 3) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 6), Pair.of(0.0, 0.5));
                } else if (request.getSegmentNumber() == 4 || request.getSegmentNumber() == 5) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream1", 7), Pair.of(0.5, 0.25));
                }
                val builder = SuccessorResponse.newBuilder();
                for (Entry<SegmentId, Pair<Double, Double>> entry : result.entrySet()) {
                    builder.addSegments(SuccessorResponse.SegmentEntry.newBuilder().setSegment(Controller.SegmentRange.newBuilder().setSegmentId(entry.getKey()).setMinKey(entry.getValue().getLeft()).setMaxKey(entry.getValue().getRight()).build()).addValue(10 * entry.getKey().getSegmentNumber()).build());
                }
                responseObserver.onNext(builder.build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream8")) {
                Map<SegmentId, Pair<Double, Double>> result = new HashMap<>();
                if (request.getSegmentNumber() == 0) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 3), Pair.of(0.0, 0.2));
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 4), Pair.of(0.2, 0.33));
                } else if (request.getSegmentNumber() == 1) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 5), Pair.of(0.33, 0.5));
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 6), Pair.of(0.5, 0.66));
                } else if (request.getSegmentNumber() == 2) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 7), Pair.of(0.66, 0.8));
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 8), Pair.of(0.8, 1.0));
                } else if (request.getSegmentNumber() == 3 || request.getSegmentNumber() == 4 || request.getSegmentNumber() == 5) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 9), Pair.of(0.0, 0.5));
                } else if (request.getSegmentNumber() == 6 || request.getSegmentNumber() == 7 || request.getSegmentNumber() == 8) {
                    result.put(ModelHelper.createSegmentId("scope1", "stream8", 10), Pair.of(0.5, 1.0));
                }
                val builder = SuccessorResponse.newBuilder();
                for (Entry<SegmentId, Pair<Double, Double>> entry : result.entrySet()) {
                    builder.addSegments(SuccessorResponse.SegmentEntry.newBuilder().setSegment(Controller.SegmentRange.newBuilder().setSegmentId(entry.getKey()).setMinKey(entry.getValue().getLeft()).setMaxKey(entry.getValue().getRight()).build()).addValue(10 * entry.getKey().getSegmentNumber()).build());
                }
                responseObserver.onNext(builder.build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void scale(ScaleRequest request, StreamObserver<ScaleResponse> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(ScaleResponse.newBuilder().setStatus(ScaleResponse.ScaleStreamStatus.STARTED).addSegments(ModelHelper.createSegmentRange("scope1", "stream1", 0, 0.0, 0.5)).addSegments(ModelHelper.createSegmentRange("scope1", "stream1", 1, 0.5, 1.0)).setEpoch(0).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void checkScale(ScaleStatusRequest request, StreamObserver<ScaleStatusResponse> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(ScaleStatusResponse.newBuilder().setStatus(ScaleStatusResponse.ScaleStatus.SUCCESS).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost").setPort(SERVICE_PORT).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void isSegmentValid(SegmentId request, StreamObserver<SegmentValidityResponse> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(SegmentValidityResponse.newBuilder().setResponse(true).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(SegmentValidityResponse.newBuilder().setResponse(false).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void createTransaction(CreateTxnRequest request, StreamObserver<Controller.CreateTxnResponse> responseObserver) {
            Controller.CreateTxnResponse.Builder builder = Controller.CreateTxnResponse.newBuilder();
            if (request.getStreamInfo().getStream().equals("stream1")) {
                builder.setTxnId(TxnId.newBuilder().setHighBits(11L).setLowBits(22L).build());
                builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 0, 0.0, 0.5));
                builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 1, 0.5, 1.0));
                responseObserver.onNext(builder.build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream2", 0, 0.0, 1.0));
                builder.setTxnId(TxnId.newBuilder().setHighBits(33L).setLowBits(44L).build());
                responseObserver.onNext(builder.build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void commitTransaction(TxnRequest request, StreamObserver<Controller.TxnStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.TRANSACTION_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void abortTransaction(TxnRequest request, StreamObserver<Controller.TxnStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.STREAM_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.TRANSACTION_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void pingTransaction(PingTxnRequest request, StreamObserver<PingTxnStatus> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void checkTransactionState(TxnRequest request, StreamObserver<TxnState> responseObserver) {
            if (request.getStreamInfo().getStream().equals("stream1")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.OPEN).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream2")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.UNKNOWN).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream3")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTING).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream4")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTED).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream5")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTING).build());
                responseObserver.onCompleted();
            } else if (request.getStreamInfo().getStream().equals("stream6")) {
                responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTED).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void createScope(ScopeInfo request, StreamObserver<CreateScopeStatus> responseObserver) {
            if (request.getScope().equals("scope1")) {
                responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope2")) {
                responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope3")) {
                responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.INVALID_SCOPE_NAME).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope4")) {
                responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }

        @Override
        public void getDelegationToken(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo request, io.grpc.stub.StreamObserver<io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken> responseObserver) {
            responseObserver.onNext(Controller.DelegationToken.newBuilder().setDelegationToken("token").build());
            responseObserver.onCompleted();
        }

        @Override
        public void deleteScope(ScopeInfo request, StreamObserver<DeleteScopeStatus> responseObserver) {
            if (request.getScope().equals("scope1")) {
                responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope2")) {
                responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.FAILURE).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope3")) {
                responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build());
                responseObserver.onCompleted();
            } else if (request.getScope().equals("scope4")) {
                responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
            }
        }
    };
    serverPort = TestUtils.getAvailableListenPort();
    serverBuilder = NettyServerBuilder.forPort(serverPort).addService(testServerImpl);
    if (testSecure) {
        serverBuilder = serverBuilder.useTransportSecurity(new File("../config/cert.pem"), new File("../config/key.pem"));
        creds = new DefaultCredentials("1111_aaaa", "admin");
    }
    testGRPCServer = serverBuilder.build().start();
    executor = Executors.newSingleThreadScheduledExecutor();
    controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).credentials(new DefaultCredentials("1111_aaaa", "admin")).trustStore("../config/cert.pem").build()).retryAttempts(1).build(), executor);
}
Also used : ScaleStatusRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest) HashMap(java.util.HashMap) NettyServerBuilder(io.grpc.netty.NettyServerBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) PingTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) TxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) SuccessorResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse) ScaleRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest) lombok.val(lombok.val) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) PingTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) GetSegmentsRequest(io.pravega.controller.stream.api.grpc.v1.Controller.GetSegmentsRequest) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) SegmentsAtTime(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentsAtTime) SegmentValidityResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentValidityResponse) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Entry(java.util.Map.Entry) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) Pair(org.apache.commons.lang3.tuple.Pair) ControllerServiceImplBase(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceImplBase) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) StreamConfig(io.pravega.controller.stream.api.grpc.v1.Controller.StreamConfig) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) ScopeInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Before(org.junit.Before)

Aggregations

PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)11 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)10 Test (org.junit.Test)10 TxnStatus (io.pravega.controller.store.stream.TxnStatus)9 UUID (java.util.UUID)8 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)7 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)6 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)6 SegmentHelperMock (io.pravega.controller.mocks.SegmentHelperMock)6 ControllerService (io.pravega.controller.server.ControllerService)6 SegmentHelper (io.pravega.controller.server.SegmentHelper)6 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)6 HostStoreFactory (io.pravega.controller.store.host.HostStoreFactory)6 HostMonitorConfigImpl (io.pravega.controller.store.host.impl.HostMonitorConfigImpl)6 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)6 StreamStoreFactory (io.pravega.controller.store.stream.StreamStoreFactory)6 TaskMetadataStore (io.pravega.controller.store.task.TaskMetadataStore)6 TaskStoreFactory (io.pravega.controller.store.task.TaskStoreFactory)6 TxnState (io.pravega.controller.stream.api.grpc.v1.Controller.TxnState)6