Search in sources :

Example 1 with UpdateStreamEvent

use of io.pravega.shared.controller.event.UpdateStreamEvent 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 2 with UpdateStreamEvent

use of io.pravega.shared.controller.event.UpdateStreamEvent in project pravega by pravega.

the class StreamMetadataTasksTest method retentionPolicyUpdateTest.

@Test(timeout = 30000)
public void retentionPolicyUpdateTest() throws Exception {
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    String stream = "test";
    final StreamConfiguration noRetentionConfig = StreamConfiguration.builder().scope(SCOPE).streamName(stream).scalingPolicy(policy).build();
    // add stream without retention policy
    streamMetadataTasks.createStreamBody(SCOPE, stream, noRetentionConfig, System.currentTimeMillis()).join();
    String scopedStreamName = String.format("%s/%s", SCOPE, stream);
    // verify that stream is not added to bucket
    assertTrue(!streamStorePartialMock.getStreamsForBucket(0, executor).join().contains(scopedStreamName));
    UpdateStreamTask task = new UpdateStreamTask(streamMetadataTasks, streamStorePartialMock, executor);
    final RetentionPolicy retentionPolicy = RetentionPolicy.builder().retentionType(RetentionPolicy.RetentionType.TIME).retentionParam(Duration.ofMinutes(60).toMillis()).build();
    final StreamConfiguration withRetentionConfig = StreamConfiguration.builder().scope(SCOPE).streamName(stream).scalingPolicy(policy).retentionPolicy(retentionPolicy).build();
    // now update stream with a retention policy
    streamStorePartialMock.startUpdateConfiguration(SCOPE, stream, withRetentionConfig, null, executor).join();
    UpdateStreamEvent update = new UpdateStreamEvent(SCOPE, stream);
    task.execute(update).join();
    // verify that bucket has the stream.
    assertTrue(streamStorePartialMock.getStreamsForBucket(0, executor).join().contains(scopedStreamName));
    // update stream such that stream is updated with null retention policy
    streamStorePartialMock.startUpdateConfiguration(SCOPE, stream, noRetentionConfig, null, executor).join();
    task.execute(update).join();
    // verify that the stream is no longer present in the bucket
    assertTrue(!streamStorePartialMock.getStreamsForBucket(0, executor).join().contains(scopedStreamName));
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Test(org.junit.Test)

Aggregations

StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 UpdateStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask)2 UpdateStreamEvent (io.pravega.shared.controller.event.UpdateStreamEvent)2 Test (org.junit.Test)2 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)1 StoreException (io.pravega.controller.store.stream.StoreException)1 ScaleStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse.ScaleStreamStatus)1 UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1