Search in sources :

Example 36 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ControllerServiceImplTest method createStreamTests.

@Test
public void createStreamTests() {
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final ScalingPolicy policy2 = ScalingPolicy.fixed(3);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(policy1).build();
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM2).scalingPolicy(policy2).build();
    final StreamConfiguration configuration3 = StreamConfiguration.builder().scope("SCOPE3").streamName(STREAM2).scalingPolicy(policy2).build();
    CreateStreamStatus status;
    // region checkStream
    ResultObserver<CreateScopeStatus> result = new ResultObserver<>();
    this.controllerService.createScope(ScopeInfo.newBuilder().setScope(SCOPE1).build(), result);
    Assert.assertEquals(result.get().getStatus(), CreateScopeStatus.Status.SUCCESS);
    ResultObserver<CreateStreamStatus> result1 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result1);
    status = result1.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration2), result2);
    status = result2.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
    // endregion
    // region duplicate create stream
    ResultObserver<CreateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result3);
    status = result3.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.STREAM_EXISTS);
    // endregion
    // create stream for non-existent scope
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration3), result4);
    status = result4.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SCOPE_NOT_FOUND);
    // create stream with invalid stream name "abc/def"
    ResultObserver<CreateStreamStatus> result5 = new ResultObserver<>();
    final StreamConfiguration configuration4 = StreamConfiguration.builder().scope("SCOPE3").streamName("abc/def").scalingPolicy(policy2).build();
    this.controllerService.createStream(ModelHelper.decode(configuration4), result5);
    status = result5.get();
    assertEquals(status.getStatus(), CreateStreamStatus.Status.INVALID_STREAM_NAME);
    // Create stream with an internal stream name.
    ResultObserver<CreateStreamStatus> result6 = new ResultObserver<>();
    final StreamConfiguration configuration6 = StreamConfiguration.builder().scope(SCOPE1).streamName(NameUtils.getInternalNameForStream("abcdef")).scalingPolicy(policy2).build();
    this.controllerService.createStream(ModelHelper.decode(configuration6), result6);
    status = result6.get();
    assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 37 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ControllerServiceImplTest method deleteScopeTests.

@Test
public void deleteScopeTests() {
    CreateScopeStatus createScopeStatus;
    DeleteScopeStatus deleteScopeStatus;
    CreateStreamStatus createStreamStatus;
    // Delete empty scope (containing no streams) SCOPE3
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE3), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    ResultObserver<DeleteScopeStatus> result2 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE3), result2);
    deleteScopeStatus = result2.get();
    assertEquals("Delete Empty scope", DeleteScopeStatus.Status.SUCCESS, deleteScopeStatus.getStatus());
    // To verify that SCOPE3 is infact deleted in above delete call
    ResultObserver<DeleteScopeStatus> result7 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE3), result7);
    deleteScopeStatus = result7.get();
    assertEquals("Verify that Scope3 is infact deleted", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus());
    // Delete Non-empty Scope SCOPE2
    ResultObserver<CreateScopeStatus> result3 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE2), result3);
    createScopeStatus = result3.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE2).streamName(STREAM1).scalingPolicy(policy1).build();
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result4);
    createStreamStatus = result4.get();
    assertEquals(createStreamStatus.getStatus(), CreateStreamStatus.Status.SUCCESS);
    ResultObserver<DeleteScopeStatus> result5 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE2), result5);
    deleteScopeStatus = result5.get();
    assertEquals("Delete non empty scope", DeleteScopeStatus.Status.SCOPE_NOT_EMPTY, deleteScopeStatus.getStatus());
    // Delete Non-existent scope SCOPE3
    ResultObserver<DeleteScopeStatus> result6 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo("SCOPE3"), result6);
    deleteScopeStatus = result6.get();
    assertEquals("Delete non existent scope", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus());
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Test(org.junit.Test)

Example 38 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ControllerServiceTest method setup.

@Before
public void setup() throws ExecutionException, InterruptedException {
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final ScalingPolicy policy2 = ScalingPolicy.fixed(3);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(policy1).build();
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(SCOPE).streamName(stream2).scalingPolicy(policy2).build();
    // createScope
    streamStore.createScope(SCOPE).get();
    // region createStream
    startTs = System.currentTimeMillis();
    OperationContext context = streamStore.createContext(SCOPE, stream1);
    streamStore.createStream(SCOPE, stream1, configuration1, startTs, context, executor).get();
    streamStore.setState(SCOPE, stream1, State.ACTIVE, context, executor);
    OperationContext context2 = streamStore.createContext(SCOPE, stream2);
    streamStore.createStream(SCOPE, stream2, configuration2, startTs, context2, executor).get();
    streamStore.setState(SCOPE, stream2, State.ACTIVE, context2, executor);
    // endregion
    // region scaleSegments
    SimpleEntry<Double, Double> segment1 = new SimpleEntry<>(0.5, 0.75);
    SimpleEntry<Double, Double> segment2 = new SimpleEntry<>(0.75, 1.0);
    List<Integer> sealedSegments = Collections.singletonList(1);
    scaleTs = System.currentTimeMillis();
    StartScaleResponse startScaleResponse = streamStore.startScale(SCOPE, stream1, sealedSegments, Arrays.asList(segment1, segment2), startTs + 20, false, null, executor).get();
    List<Segment> segmentCreated = startScaleResponse.getSegmentsCreated();
    streamStore.setState(SCOPE, stream1, State.SCALING, null, executor).get();
    streamStore.scaleNewSegmentsCreated(SCOPE, stream1, sealedSegments, segmentCreated, startScaleResponse.getActiveEpoch(), scaleTs, null, executor).get();
    streamStore.scaleSegmentsSealed(SCOPE, stream1, sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), segmentCreated, startScaleResponse.getActiveEpoch(), scaleTs, null, executor).get();
    SimpleEntry<Double, Double> segment3 = new SimpleEntry<>(0.0, 0.5);
    SimpleEntry<Double, Double> segment4 = new SimpleEntry<>(0.5, 0.75);
    SimpleEntry<Double, Double> segment5 = new SimpleEntry<>(0.75, 1.0);
    sealedSegments = Arrays.asList(0, 1, 2);
    startScaleResponse = streamStore.startScale(SCOPE, stream2, sealedSegments, Arrays.asList(segment3, segment4, segment5), startTs + 20, false, null, executor).get();
    segmentCreated = startScaleResponse.getSegmentsCreated();
    streamStore.setState(SCOPE, stream2, State.SCALING, null, executor).get();
    streamStore.scaleNewSegmentsCreated(SCOPE, stream2, sealedSegments, segmentCreated, startScaleResponse.getActiveEpoch(), scaleTs, null, executor).get();
    streamStore.scaleSegmentsSealed(SCOPE, stream2, sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), segmentCreated, startScaleResponse.getActiveEpoch(), scaleTs, null, executor).get();
// endregion
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) OperationContext(io.pravega.controller.store.stream.OperationContext) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) Arrays(java.util.Arrays) SegmentHelper(io.pravega.controller.server.SegmentHelper) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Map(java.util.Map) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Segment(io.pravega.controller.store.stream.Segment) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) Before(org.junit.Before) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StartScaleResponse(io.pravega.controller.store.stream.StartScaleResponse) Test(org.junit.Test) State(io.pravega.controller.store.stream.tables.State) Collectors(java.util.stream.Collectors) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) SimpleEntry(java.util.AbstractMap.SimpleEntry) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StartScaleResponse(io.pravega.controller.store.stream.StartScaleResponse) Segment(io.pravega.controller.store.stream.Segment) Before(org.junit.Before)

Example 39 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class StreamMetadataStoreTest method truncationTest.

@Test
public void truncationTest() throws Exception {
    final String scope = "ScopeTruncate";
    final String stream = "ScopeTruncate";
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
    long start = System.currentTimeMillis();
    store.createScope(scope).get();
    store.createStream(scope, stream, configuration, start, null, executor).get();
    store.setState(scope, stream, State.ACTIVE, null, executor).get();
    Map<Integer, Long> truncation = new HashMap<>();
    truncation.put(0, 0L);
    truncation.put(1, 0L);
    assertTrue(Futures.await(store.startTruncation(scope, stream, truncation, null, executor)));
    StreamProperty<StreamTruncationRecord> truncationProperty = store.getTruncationProperty(scope, stream, true, null, executor).join();
    assertTrue(truncationProperty.isUpdating());
    Map<Integer, Long> truncation2 = new HashMap<>();
    truncation2.put(0, 0L);
    truncation2.put(1, 0L);
    assertFalse(Futures.await(store.startTruncation(scope, stream, truncation2, null, executor)));
    assertTrue(Futures.await(store.completeTruncation(scope, stream, null, executor)));
    truncationProperty = store.getTruncationProperty(scope, stream, true, null, executor).join();
    assertEquals(truncation, truncationProperty.getProperty().getStreamCut());
    assertTrue(truncationProperty.getProperty().getCutEpochMap().size() == 2);
    Map<Integer, Long> truncation3 = new HashMap<>();
    truncation3.put(0, 0L);
    truncation3.put(1, 0L);
    assertTrue(Futures.await(store.startTruncation(scope, stream, truncation3, null, executor)));
    assertTrue(Futures.await(store.completeUpdateConfiguration(scope, stream, null, executor)));
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamTruncationRecord(io.pravega.controller.store.stream.tables.StreamTruncationRecord) HashMap(java.util.HashMap) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 40 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class StreamMetadataStoreTest method updateTest.

@Test
public void updateTest() throws Exception {
    final String scope = "ScopeUpdate";
    final String stream = "StreamUpdate";
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
    long start = System.currentTimeMillis();
    store.createScope(scope).get();
    store.createStream(scope, stream, configuration, start, null, executor).get();
    store.setState(scope, stream, State.ACTIVE, null, executor).get();
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
    StreamProperty<StreamConfiguration> configProperty = store.getConfigurationProperty(scope, stream, true, null, executor).join();
    assertFalse(configProperty.isUpdating());
    // run update configuration multiple times
    assertTrue(Futures.await(store.startUpdateConfiguration(scope, stream, configuration2, null, executor)));
    configProperty = store.getConfigurationProperty(scope, stream, true, null, executor).join();
    assertTrue(configProperty.isUpdating());
    final StreamConfiguration configuration3 = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
    assertFalse(Futures.await(store.startUpdateConfiguration(scope, stream, configuration3, null, executor)));
    assertTrue(Futures.await(store.completeUpdateConfiguration(scope, stream, null, executor)));
    configProperty = store.getConfigurationProperty(scope, stream, true, null, executor).join();
    assertEquals(configuration2, configProperty.getProperty());
    assertTrue(Futures.await(store.startUpdateConfiguration(scope, stream, configuration3, null, executor)));
    assertTrue(Futures.await(store.completeUpdateConfiguration(scope, stream, null, executor)));
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Aggregations

ScalingPolicy (io.pravega.client.stream.ScalingPolicy)47 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)44 Test (org.junit.Test)42 Before (org.junit.Before)16 TestingServerStarter (io.pravega.test.common.TestingServerStarter)15 Executors (java.util.concurrent.Executors)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 After (org.junit.After)15 Assert.assertEquals (org.junit.Assert.assertEquals)15 TestingServer (org.apache.curator.test.TestingServer)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13 HashMap (java.util.HashMap)13 List (java.util.List)13 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)12 Map (java.util.Map)12 UUID (java.util.UUID)12 AbstractMap (java.util.AbstractMap)11 ExecutionException (java.util.concurrent.ExecutionException)11