use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.
the class StreamMetadataTasksTest method testWorkflowCompletionTimeout.
@Test(timeout = 30000)
public void testWorkflowCompletionTimeout() {
EventHelper helper = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStorePartialMock).getHostTaskIndex());
StreamMetadataTasks streamMetadataTask = new StreamMetadataTasks(streamStorePartialMock, bucketStore, TaskStoreFactory.createZKStore(zkClient, executor), SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(authEnabled, "key", 300), helper);
streamMetadataTask.setCompletionTimeoutMillis(500L);
StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
String completion = "completion";
streamStorePartialMock.createStream(SCOPE, completion, configuration, System.currentTimeMillis(), null, executor).join();
streamStorePartialMock.setState(SCOPE, completion, State.ACTIVE, null, executor).join();
WriterMock requestEventWriter = new WriterMock(streamMetadataTask, executor);
streamMetadataTask.setRequestEventWriter(requestEventWriter);
StreamConfiguration configuration2 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build();
AssertExtensions.assertFutureThrows("update timedout", streamMetadataTask.updateStream(SCOPE, completion, configuration2, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
ControllerEvent event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof UpdateStreamEvent);
VersionedMetadata<StreamConfigurationRecord> configurationRecord = streamStorePartialMock.getConfigurationRecord(SCOPE, completion, null, executor).join();
assertTrue(configurationRecord.getObject().isUpdating());
Map<Long, Long> streamCut = Collections.singletonMap(0L, 0L);
AssertExtensions.assertFutureThrows("truncate timedout", streamMetadataTask.truncateStream(SCOPE, completion, streamCut, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof TruncateStreamEvent);
VersionedMetadata<StreamTruncationRecord> truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, completion, null, executor).join();
assertTrue(truncationRecord.getObject().isUpdating());
AssertExtensions.assertFutureThrows("seal timedout", streamMetadataTask.sealStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof SealStreamEvent);
VersionedMetadata<State> state = streamStorePartialMock.getVersionedState(SCOPE, completion, null, executor).join();
assertEquals(state.getObject(), State.SEALING);
streamStorePartialMock.setState(SCOPE, completion, State.SEALED, null, executor).join();
AssertExtensions.assertFutureThrows("delete timedout", streamMetadataTask.deleteStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
event = requestEventWriter.eventQueue.poll();
assertTrue(event instanceof DeleteStreamEvent);
}
use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.
the class InMemoryStream method checkStreamExists.
@Override
CompletableFuture<CreateStreamResponse> checkStreamExists(StreamConfiguration configuration, long timestamp, final int startingSegmentNumber, OperationContext context) {
CompletableFuture<CreateStreamResponse> result = new CompletableFuture<>();
final long time;
final StreamConfigurationRecord config;
final VersionedMetadata<StateRecord> currentState;
synchronized (lock) {
time = creationTime.get();
config = this.configuration == null ? null : this.configuration.getObject();
currentState = this.state;
}
if (time != Long.MIN_VALUE) {
if (config != null) {
handleStreamMetadataExists(timestamp, result, time, startingSegmentNumber, config.getStreamConfiguration(), currentState, context);
} else {
result.complete(new CreateStreamResponse(CreateStreamResponse.CreateStatus.NEW, configuration, time, startingSegmentNumber));
}
} else {
result.complete(new CreateStreamResponse(CreateStreamResponse.CreateStatus.NEW, configuration, timestamp, startingSegmentNumber));
}
return result;
}
use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.
the class RequestHandlersTest method concurrentUpdateStream.
// concurrent update stream
@SuppressWarnings("unchecked")
@Test(timeout = 300000)
public void concurrentUpdateStream() throws Exception {
String stream = "update";
StreamMetadataStore streamStore1 = getStore();
StreamMetadataStore streamStore1Spied = spy(getStore());
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(1, 2, 1)).build();
streamStore1.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
streamStore1.setState(scope, stream, State.ACTIVE, null, executor).join();
StreamMetadataStore streamStore2 = getStore();
UpdateStreamTask requestHandler1 = new UpdateStreamTask(streamMetadataTasks, streamStore1Spied, bucketStore, executor);
UpdateStreamTask requestHandler2 = new UpdateStreamTask(streamMetadataTasks, streamStore2, bucketStore, executor);
CompletableFuture<Void> wait = new CompletableFuture<>();
CompletableFuture<Void> signal = new CompletableFuture<>();
streamStore1.startUpdateConfiguration(scope, stream, config, null, executor).join();
UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
doAnswer(x -> {
signal.complete(null);
wait.join();
return streamStore1.completeUpdateConfiguration(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4));
}).when(streamStore1Spied).completeUpdateConfiguration(anyString(), anyString(), any(), any(), any());
CompletableFuture<Void> future1 = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler1.execute(event), executor);
signal.join();
requestHandler2.execute(event).join();
wait.complete(null);
AssertExtensions.assertSuppliedFutureThrows("first update job should fail", () -> future1, e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
// validate rolling txn done
VersionedMetadata<StreamConfigurationRecord> versioned = streamStore1.getConfigurationRecord(scope, stream, null, executor).join();
assertFalse(versioned.getObject().isUpdating());
assertEquals(2, getVersionNumber(versioned.getVersion()));
assertEquals(State.ACTIVE, streamStore1.getState(scope, stream, true, null, executor).join());
streamStore1.close();
streamStore2.close();
}
use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.
the class RequestHandlersTest method idempotentUpdatePartialScaleCompleted.
@Test(timeout = 300000)
public void idempotentUpdatePartialScaleCompleted() throws Exception {
String stream = "update2";
StreamMetadataStore streamStore1 = getStore();
StreamMetadataStore streamStore1Spied = spy(getStore());
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
streamStore1.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
streamStore1.setState(scope, stream, State.ACTIVE, null, executor).join();
StreamMetadataStore streamStore2 = getStore();
UpdateStreamTask requestHandler1 = new UpdateStreamTask(streamMetadataTasks, streamStore1Spied, bucketStore, executor);
UpdateStreamTask requestHandler2 = new UpdateStreamTask(streamMetadataTasks, streamStore2, bucketStore, executor);
CompletableFuture<Void> wait = new CompletableFuture<>();
CompletableFuture<Void> signal = new CompletableFuture<>();
config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(2)).build();
streamStore1.startUpdateConfiguration(scope, stream, config, null, executor).join();
UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
// make this wait at reset epoch transition. this has already changed the state to updating. both executions are
// performing the same update.
doAnswer(x -> {
signal.complete(null);
wait.join();
return streamStore1.scaleSegmentsSealed(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4), x.getArgument(5));
}).when(streamStore1Spied).scaleSegmentsSealed(anyString(), anyString(), any(), any(), any(), any());
CompletableFuture<Void> future1 = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler1.execute(event), executor);
signal.join();
requestHandler2.execute(event).join();
wait.complete(null);
AssertExtensions.assertSuppliedFutureThrows("first update job should fail", () -> future1, e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
VersionedMetadata<StreamConfigurationRecord> versioned = streamStore1.getConfigurationRecord(scope, stream, null, executor).join();
assertFalse(versioned.getObject().isUpdating());
assertEquals(2, getVersionNumber(versioned.getVersion()));
assertEquals(State.ACTIVE, streamStore1.getState(scope, stream, true, null, executor).join());
assertEquals(1, streamStore1.getActiveEpoch(scope, stream, null, true, executor).join().getEpoch());
// repeat the above experiment with complete scale step also having been performed.
streamStore1.close();
streamStore2.close();
}
use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.
the class RequestHandlersTest method updateSealedStream.
@SuppressWarnings("unchecked")
@Test(timeout = 300000)
public void updateSealedStream() throws Exception {
String stream = "updateSealed";
StreamMetadataStore streamStore = getStore();
StreamMetadataStore streamStoreSpied = spy(getStore());
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(1, 2, 1)).build();
streamStore.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
streamStore.setState(scope, stream, State.ACTIVE, null, executor).join();
streamStore.setState(scope, stream, State.SEALED, null, executor).join();
UpdateStreamTask requestHandler = new UpdateStreamTask(streamMetadataTasks, streamStoreSpied, bucketStore, executor);
CompletableFuture<Void> wait = new CompletableFuture<>();
CompletableFuture<Void> signal = new CompletableFuture<>();
streamStore.startUpdateConfiguration(scope, stream, config, null, executor).join();
UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
doAnswer(x -> {
signal.complete(null);
wait.join();
return streamStore.completeUpdateConfiguration(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4));
}).when(streamStoreSpied).completeUpdateConfiguration(anyString(), anyString(), any(), any(), any());
CompletableFuture<Void> future = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler.execute(event), executor);
signal.join();
wait.complete(null);
AssertExtensions.assertSuppliedFutureThrows("Updating sealed stream job should fail", () -> future, e -> Exceptions.unwrap(e) instanceof UnsupportedOperationException);
// validate
VersionedMetadata<StreamConfigurationRecord> versioned = streamStore.getConfigurationRecord(scope, stream, null, executor).join();
assertFalse(versioned.getObject().isUpdating());
assertEquals(2, getVersionNumber(versioned.getVersion()));
assertEquals(State.SEALED, streamStore.getState(scope, stream, true, null, executor).join());
streamStore.close();
}
Aggregations