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);
}
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());
}
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
}
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)));
}
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)));
}
Aggregations