use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.
the class StreamMetadataTasksTest method truncateStreamTest.
@Test(timeout = 30000)
public void truncateStreamTest() throws Exception {
final ScalingPolicy policy = ScalingPolicy.fixed(2);
final StreamConfiguration configuration = StreamConfiguration.builder().scope(SCOPE).streamName("test").scalingPolicy(policy).build();
streamStorePartialMock.createStream(SCOPE, "test", configuration, System.currentTimeMillis(), null, executor).get();
streamStorePartialMock.setState(SCOPE, "test", State.ACTIVE, null, executor).get();
assertNotEquals(0, consumer.getCurrentSegments(SCOPE, "test").get().size());
WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
streamMetadataTasks.setRequestEventWriter(requestEventWriter);
List<AbstractMap.SimpleEntry<Double, Double>> newRanges = new ArrayList<>();
newRanges.add(new AbstractMap.SimpleEntry<>(0.5, 0.75));
newRanges.add(new AbstractMap.SimpleEntry<>(0.75, 1.0));
ScaleResponse scaleOpResult = streamMetadataTasks.manualScale(SCOPE, "test", Collections.singletonList(1), newRanges, 30, null).get();
assertTrue(scaleOpResult.getStatus().equals(ScaleStreamStatus.STARTED));
ScaleOperationTask scaleTask = new ScaleOperationTask(streamMetadataTasks, streamStorePartialMock, executor);
assertTrue(Futures.await(scaleTask.execute((ScaleOpEvent) requestEventWriter.eventQueue.take())));
// start truncation
StreamProperty<StreamTruncationRecord> truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
assertFalse(truncProp.isUpdating());
// 1. happy day test
// update.. should succeed
Map<Integer, Long> streamCut = new HashMap<>();
streamCut.put(0, 1L);
streamCut.put(1, 11L);
CompletableFuture<UpdateStreamStatus.Status> truncateFuture = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut, null);
assertTrue(Futures.await(processEvent(requestEventWriter)));
assertEquals(UpdateStreamStatus.Status.SUCCESS, truncateFuture.join());
truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut));
assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut));
// 2. change state to scaling
streamStorePartialMock.setState(SCOPE, "test", State.SCALING, null, executor).get();
// call update should fail without posting the event
Map<Integer, Long> streamCut2 = new HashMap<>();
streamCut2.put(0, 1L);
streamCut2.put(2, 1L);
streamCut2.put(3, 1L);
streamMetadataTasks.truncateStream(SCOPE, "test", streamCut2, null);
AtomicBoolean loop = new AtomicBoolean(false);
Futures.loop(() -> !loop.get(), () -> streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop::set), executor).join();
// event posted, first step performed. now pick the event for processing
TruncateStreamTask truncateStreamTask = new TruncateStreamTask(streamMetadataTasks, streamStorePartialMock, executor);
TruncateStreamEvent taken = (TruncateStreamEvent) requestEventWriter.eventQueue.take();
AssertExtensions.assertThrows("", truncateStreamTask.execute(taken), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
streamStorePartialMock.setState(SCOPE, "test", State.ACTIVE, null, executor).get();
// now with state = active, process the same event. it should succeed now.
assertTrue(Futures.await(truncateStreamTask.execute(taken)));
// 3. multiple back to back updates.
Map<Integer, Long> streamCut3 = new HashMap<>();
streamCut3.put(0, 12L);
streamCut3.put(2, 12L);
streamCut3.put(3, 12L);
CompletableFuture<UpdateStreamStatus.Status> truncateOp1 = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut3, 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.getTruncationProperty(SCOPE, "test", true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop2::set), executor).join();
truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut3) && truncProp.isUpdating());
// post the second update request. This should fail here itself as previous one has started.
Map<Integer, Long> streamCut4 = new HashMap<>();
streamCut4.put(0, 14L);
streamCut4.put(2, 14L);
streamCut4.put(3, 14L);
CompletableFuture<UpdateStreamStatus.Status> truncateOpFuture2 = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut4, null);
assertEquals(UpdateStreamStatus.Status.FAILURE, truncateOpFuture2.join());
// process event
assertTrue(Futures.await(processEvent(requestEventWriter)));
// verify that first request for update also completes with success.
assertEquals(UpdateStreamStatus.Status.SUCCESS, truncateOp1.join());
truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut3) && !truncProp.isUpdating());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.
the class TimeoutServiceTest method testCloseUnknownTxn.
@Test(timeout = 5000)
public void testCloseUnknownTxn() {
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
TxnId txnId = convert(txData.getId());
Controller.TxnState state = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
Assert.assertEquals(TxnState.State.OPEN, state.getState());
Controller.TxnStatus.Status status = controllerService.abortTransaction(SCOPE, STREAM, txnId).join().getStatus();
Assert.assertEquals(Controller.TxnStatus.Status.SUCCESS, status);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.
the class TimeoutServiceTest method testTimeoutTaskFailureInvalidVersion.
@Test(timeout = 10000)
public void testTimeoutTaskFailureInvalidVersion() throws InterruptedException {
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
// Submit transaction to TimeoutService with incorrect tx version identifier.
timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion() + 1, LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (1.25 * LEASE + RETRY_DELAY), TimeUnit.MILLISECONDS);
Assert.assertNotNull(result);
Assert.assertTrue(result.isPresent());
Assert.assertEquals(StoreException.WriteConflictException.class, result.get().getClass());
TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
Assert.assertEquals(TxnStatus.OPEN, status);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.
the class StreamMetadataStoreTest method deleteTest.
@Test
public void deleteTest() throws Exception {
final String scope = "ScopeDelete";
final String stream = "StreamDelete";
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();
assertTrue(store.checkStreamExists(scope, stream).join());
store.deleteStream(scope, stream, null, executor).get();
assertFalse(store.checkStreamExists(scope, stream).join());
DeleteScopeStatus status = store.deleteScope(scope).join();
assertEquals(status.getStatus(), DeleteScopeStatus.Status.SUCCESS);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.
the class StreamMetadataTasks method sealStream.
/**
* Seal a stream.
*
* @param scope scope.
* @param stream stream name.
* @param contextOpt optional context
* @return update status.
*/
public CompletableFuture<UpdateStreamStatus.Status> sealStream(String scope, String stream, OperationContext contextOpt) {
final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt;
// 1. post event for seal.
SealStreamEvent event = new SealStreamEvent(scope, stream);
return writeEvent(event).thenCompose(x -> streamMetadataStore.getState(scope, stream, false, context, executor)).thenCompose(state -> {
if (state.equals(State.SEALED)) {
return CompletableFuture.completedFuture(true);
} else {
return streamMetadataStore.setState(scope, stream, State.SEALING, context, executor);
}
}).thenCompose(result -> {
if (result) {
return checkDone(() -> isSealed(scope, stream, context)).thenApply(x -> UpdateStreamStatus.Status.SUCCESS);
} else {
return CompletableFuture.completedFuture(UpdateStreamStatus.Status.FAILURE);
}
}).exceptionally(ex -> {
log.warn("Exception thrown in trying to notify sealed segments {}", ex.getMessage());
return handleUpdateStreamError(ex);
});
}
Aggregations