Search in sources :

Example 6 with Status

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

the class StreamMetadataTasksTest method updateStreamTest.

@Test(timeout = 30000)
public void updateStreamTest() throws Exception {
    assertNotEquals(0, consumer.getCurrentSegments(SCOPE, stream1).get().size());
    WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
    streamMetadataTasks.setRequestEventWriter(requestEventWriter);
    StreamConfiguration streamConfiguration = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(ScalingPolicy.fixed(5)).build();
    StreamProperty<StreamConfiguration> configProp = streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).join();
    assertFalse(configProp.isUpdating());
    // 1. happy day test
    // update.. should succeed
    CompletableFuture<UpdateStreamStatus.Status> updateOperationFuture = streamMetadataTasks.updateStream(SCOPE, stream1, streamConfiguration, null);
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    assertEquals(UpdateStreamStatus.Status.SUCCESS, updateOperationFuture.join());
    configProp = streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).join();
    assertTrue(configProp.getProperty().equals(streamConfiguration));
    streamConfiguration = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(ScalingPolicy.fixed(6)).build();
    // 2. change state to scaling
    streamStorePartialMock.setState(SCOPE, stream1, State.SCALING, null, executor).get();
    // call update should fail without posting the event
    streamMetadataTasks.updateStream(SCOPE, stream1, streamConfiguration, null);
    AtomicBoolean loop = new AtomicBoolean(false);
    Futures.loop(() -> !loop.get(), () -> streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop::set), executor).join();
    // event posted, first step performed. now pick the event for processing
    UpdateStreamTask updateStreamTask = new UpdateStreamTask(streamMetadataTasks, streamStorePartialMock, executor);
    UpdateStreamEvent taken = (UpdateStreamEvent) requestEventWriter.eventQueue.take();
    AssertExtensions.assertThrows("", updateStreamTask.execute(taken), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
    streamStorePartialMock.setState(SCOPE, stream1, State.ACTIVE, null, executor).get();
    // now with state = active, process the same event. it should succeed now.
    assertTrue(Futures.await(updateStreamTask.execute(taken)));
    // 3. multiple back to back updates.
    StreamConfiguration streamConfiguration1 = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(ScalingPolicy.byEventRate(1, 1, 2)).build();
    CompletableFuture<UpdateStreamStatus.Status> updateOperationFuture1 = streamMetadataTasks.updateStream(SCOPE, stream1, streamConfiguration1, null);
    // ensure that previous updatestream has posted the event and set status to updating,
    // only then call second updateStream
    AtomicBoolean loop2 = new AtomicBoolean(false);
    Futures.loop(() -> !loop2.get(), () -> streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop2::set), executor).join();
    configProp = streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).join();
    assertTrue(configProp.getProperty().equals(streamConfiguration1) && configProp.isUpdating());
    StreamConfiguration streamConfiguration2 = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(ScalingPolicy.fixed(7)).build();
    // post the second update request. This should fail here itself as previous one has started.
    CompletableFuture<UpdateStreamStatus.Status> updateOperationFuture2 = streamMetadataTasks.updateStream(SCOPE, stream1, streamConfiguration2, null);
    assertEquals(UpdateStreamStatus.Status.FAILURE, updateOperationFuture2.join());
    // process event
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    // verify that first request for update also completes with success.
    assertEquals(UpdateStreamStatus.Status.SUCCESS, updateOperationFuture1.join());
    configProp = streamStorePartialMock.getConfigurationProperty(SCOPE, stream1, true, null, executor).join();
    assertTrue(configProp.getProperty().equals(streamConfiguration1) && !configProp.isUpdating());
}
Also used : ScaleStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse.ScaleStreamStatus) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 7 with Status

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

the class StreamTransactionMetadataTasksTest method commitAbortTests.

@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void commitAbortTests() {
    // Create mock writer objects.
    final List<CompletableFuture<Void>> commitWriterResponses = getWriteResultSequence(5);
    final List<CompletableFuture<Void>> abortWriterResponses = getWriteResultSequence(5);
    EventStreamWriter<CommitEvent> commitWriter = Mockito.mock(EventStreamWriter.class);
    Mockito.when(commitWriter.writeEvent(anyString(), any())).thenAnswer(new SequenceAnswer<>(commitWriterResponses));
    EventStreamWriter<AbortEvent> abortWriter = Mockito.mock(EventStreamWriter.class);
    Mockito.when(abortWriter.writeEvent(anyString(), any())).thenAnswer(new SequenceAnswer<>(abortWriterResponses));
    // Create transaction tasks.
    txnTasks = new StreamTransactionMetadataTasks(streamStore, hostStore, segmentHelperMock, executor, "host", connectionFactory, false, "");
    txnTasks.initializeStreamWriters("commitStream", commitWriter, "abortStream", abortWriter);
    // Create ControllerService.
    consumer = new ControllerService(streamStore, hostStore, streamMetadataTasks, txnTasks, segmentHelperMock, executor, null);
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(STREAM).scalingPolicy(policy1).build();
    // Create stream and scope
    Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, consumer.createScope(SCOPE).join().getStatus());
    Assert.assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamMetadataTasks.createStream(SCOPE, STREAM, configuration1, 0).join());
    // Create 2 transactions
    final long lease = 5000;
    final long scaleGracePeriod = 10000;
    VersionedTransactionData txData1 = txnTasks.createTxn(SCOPE, STREAM, lease, scaleGracePeriod, null).join().getKey();
    VersionedTransactionData txData2 = txnTasks.createTxn(SCOPE, STREAM, lease, scaleGracePeriod, null).join().getKey();
    // Commit the first one
    TxnStatus status = txnTasks.commitTxn(SCOPE, STREAM, txData1.getId(), null).join();
    Assert.assertEquals(TxnStatus.COMMITTING, status);
    // Abort the second one
    status = txnTasks.abortTxn(SCOPE, STREAM, txData2.getId(), txData2.getVersion(), null).join();
    Assert.assertEquals(TxnStatus.ABORTING, status);
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) ControllerService(io.pravega.controller.server.ControllerService) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CommitEvent(io.pravega.shared.controller.event.CommitEvent) AbortEvent(io.pravega.shared.controller.event.AbortEvent) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 8 with Status

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

the class TimeoutServiceTest method testPingSuccess.

@Test(timeout = 10000)
public void testPingSuccess() throws InterruptedException {
    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());
    Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE);
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.8 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.ABORTING, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 9 with Status

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

the class TimeoutServiceTest method testControllerPingFailureDisconnected.

@Test(timeout = 10000)
public void testControllerPingFailureDisconnected() throws InterruptedException {
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, SCALE_GRACE_PERIOD).thenApply(x -> ModelHelper.decode(x.getKey())).join();
    Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    TxnState status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, status.getState());
    // Stop timeoutService, and then try pinging the transaction.
    timeoutService.stopAsync();
    PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE).join();
    Assert.assertEquals(PingTxnStatus.Status.DISCONNECTED, pingStatus.getStatus());
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    // Check that the transaction status is still open, since timeoutService has been stopped.
    status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, status.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 10 with Status

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

the class TimeoutServiceTest method testPingFailureMaxExecutionTimeExceeded.

@Test(timeout = 10000)
public void testPingFailureMaxExecutionTimeExceeded() throws InterruptedException {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 2 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    // 3 * LEASE > 2 * LEASE
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), 3 * LEASE);
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)11 TxnStatus (io.pravega.controller.store.stream.TxnStatus)10 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)10 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)6 UUID (java.util.UUID)6 StoreException (io.pravega.controller.store.stream.StoreException)5 UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Futures (io.pravega.common.concurrent.Futures)3 SegmentHelper (io.pravega.controller.server.SegmentHelper)3 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)3 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)3 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 TimeUnit (java.util.concurrent.TimeUnit)3 Slf4j (lombok.extern.slf4j.Slf4j)3