use of io.pravega.client.stream.impl.TxnSegments in project pravega by pravega.
the class ControllerImplTest method testDeadline.
@Test
public void testDeadline() {
@Cleanup final ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).credentials(new DefaultCredentials("1111_aaaa", "admin")).trustStore(SecurityConfigDefaults.TLS_CA_CERT_PATH).build()).timeoutMillis(200).retryAttempts(1).build(), executor);
Predicate<Throwable> deadlinePredicate = e -> {
Throwable unwrapped = Exceptions.unwrap(e);
if (unwrapped instanceof RetriesExhaustedException) {
unwrapped = Exceptions.unwrap(unwrapped.getCause());
}
StatusRuntimeException exception = (StatusRuntimeException) unwrapped;
Status.Code code = exception.getStatus().getCode();
return code.equals(Status.Code.DEADLINE_EXCEEDED);
};
String deadline = "deadline";
// region scope
CompletableFuture<Boolean> scopeFuture = controller.createScope(deadline);
AssertExtensions.assertFutureThrows("", scopeFuture, deadlinePredicate);
CompletableFuture<Boolean> deleteScopeFuture = controller.deleteScope(deadline);
AssertExtensions.assertFutureThrows("", deleteScopeFuture, deadlinePredicate);
CompletableFuture<Void> listFuture = controller.listStreams(deadline).collectRemaining(x -> true);
AssertExtensions.assertFutureThrows("", listFuture, deadlinePredicate);
CompletableFuture<Void> listWithTagFuture = controller.listStreamsForTag(deadline, "tx").collectRemaining(x -> true);
AssertExtensions.assertFutureThrows("", listWithTagFuture, deadlinePredicate);
CompletableFuture<StreamConfiguration> getStreamCfgFuture = controller.getStreamConfiguration(deadline, deadline);
AssertExtensions.assertFutureThrows("", getStreamCfgFuture, deadlinePredicate);
// endregion
CompletableFuture<String> tokenFuture = controller.getOrRefreshDelegationTokenFor(deadline, deadline, AccessOperation.ANY);
AssertExtensions.assertFutureThrows("", tokenFuture, deadlinePredicate);
// region stream
CompletableFuture<Boolean> createStreamFuture = controller.createStream(deadline, deadline, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
AssertExtensions.assertFutureThrows("", createStreamFuture, deadlinePredicate);
Stream stream = Stream.of(deadline, deadline);
CompletableFuture<PravegaNodeUri> getEndpointFuture = controller.getEndpointForSegment(NameUtils.getQualifiedStreamSegmentName(deadline, deadline, 0L));
AssertExtensions.assertFutureThrows("", getEndpointFuture, deadlinePredicate);
CompletableFuture<StreamSegments> getSegmentFuture = controller.getCurrentSegments(deadline, deadline);
AssertExtensions.assertFutureThrows("", getSegmentFuture, deadlinePredicate);
CompletableFuture<Map<Segment, Long>> getSegmentsAtTimeFuture = controller.getSegmentsAtTime(stream, 0L);
AssertExtensions.assertFutureThrows("", getSegmentsAtTimeFuture, deadlinePredicate);
CompletableFuture<StreamSegments> currentSegmentsFuture = controller.getCurrentSegments(deadline, deadline);
AssertExtensions.assertFutureThrows("", currentSegmentsFuture, deadlinePredicate);
Segment segment = new Segment(deadline, deadline, 0L);
CompletableFuture<Boolean> isSegmentOpenFuture = controller.isSegmentOpen(segment);
AssertExtensions.assertFutureThrows("", isSegmentOpenFuture, deadlinePredicate);
CompletableFuture<StreamSegmentsWithPredecessors> successorFuture = controller.getSuccessors(segment);
AssertExtensions.assertFutureThrows("", successorFuture, deadlinePredicate);
StreamCut streamCut = new StreamCutImpl(stream, Collections.emptyMap());
CompletableFuture<StreamSegmentSuccessors> streamCutFuture = controller.getSegments(streamCut, streamCut);
AssertExtensions.assertFutureThrows("", streamCutFuture, deadlinePredicate);
CompletableFuture<StreamSegmentSuccessors> streamcutSuccessorsFuture = controller.getSuccessors(streamCut);
AssertExtensions.assertFutureThrows("", streamcutSuccessorsFuture, deadlinePredicate);
CompletableFuture<Boolean> updateFuture = controller.updateStream(deadline, deadline, StreamConfiguration.builder().build());
AssertExtensions.assertFutureThrows("", updateFuture, deadlinePredicate);
CompletableFuture<Boolean> scaleFuture = controller.scaleStream(stream, Collections.emptyList(), Collections.emptyMap(), executor).getFuture();
AssertExtensions.assertFutureThrows("", scaleFuture, deadlinePredicate);
CompletableFuture<Boolean> scaleStatusFuture = controller.checkScaleStatus(stream, 0);
AssertExtensions.assertFutureThrows("", scaleStatusFuture, deadlinePredicate);
CompletableFuture<Boolean> truncateFuture = controller.truncateStream(deadline, deadline, new StreamCutImpl(Stream.of(deadline, deadline), Collections.emptyMap()));
AssertExtensions.assertFutureThrows("", truncateFuture, deadlinePredicate);
CompletableFuture<Boolean> sealFuture = controller.sealStream(deadline, deadline);
AssertExtensions.assertFutureThrows("", sealFuture, deadlinePredicate);
CompletableFuture<Boolean> deleteFuture = controller.deleteStream(deadline, deadline);
AssertExtensions.assertFutureThrows("", deleteFuture, deadlinePredicate);
// endregion
// region transaction
CompletableFuture<TxnSegments> createtxnFuture = controller.createTransaction(stream, 100L);
AssertExtensions.assertFutureThrows("", createtxnFuture, deadlinePredicate);
CompletableFuture<Transaction.PingStatus> pingTxnFuture = controller.pingTransaction(stream, UUID.randomUUID(), 100L);
AssertExtensions.assertFutureThrows("", pingTxnFuture, deadlinePredicate);
CompletableFuture<Void> abortFuture = controller.abortTransaction(stream, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", abortFuture, deadlinePredicate);
CompletableFuture<Void> commitFuture = controller.commitTransaction(stream, "", 0L, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", commitFuture, deadlinePredicate);
CompletableFuture<Transaction.Status> txnStatusFuture = controller.checkTransactionStatus(stream, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", txnStatusFuture, deadlinePredicate);
// endregion
// region writer mark
CompletableFuture<Void> writerPosFuture = controller.noteTimestampFromWriter("deadline", stream, 0L, mock(WriterPosition.class));
AssertExtensions.assertFutureThrows("", writerPosFuture, deadlinePredicate);
CompletableFuture<Void> removeWriterFuture = controller.removeWriter("deadline", stream);
AssertExtensions.assertFutureThrows("", removeWriterFuture, deadlinePredicate);
// endregion
// verify that a stub level deadline is not set and that the stub can still make successful calls for which we
// have mocked successful responses.
controller.createScope("scope1").join();
}
use of io.pravega.client.stream.impl.TxnSegments in project pravega by pravega.
the class MockController method createTransaction.
@Override
public CompletableFuture<TxnSegments> createTransaction(final Stream stream, final long lease) {
UUID txId = UUID.randomUUID();
List<CompletableFuture<Void>> futures = new ArrayList<>();
StreamSegments currentSegments = getCurrentSegments(stream);
for (Segment segment : currentSegments.getSegments()) {
futures.add(createSegmentTx(txId, segment));
}
return Futures.allOf(futures).thenApply(v -> new TxnSegments(currentSegments, txId));
}
use of io.pravega.client.stream.impl.TxnSegments in project pravega by pravega.
the class ScaleTest method main.
public static void main(String[] args) throws Exception {
try {
@Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
TableStore tableStore = serviceBuilder.createTableStoreService();
int port = Config.SERVICE_PORT;
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, serviceBuilder.getLowPriorityExecutor());
server.startListening();
// Create controller object for testing against a separate controller report.
@Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port);
Controller controller = controllerWrapper.getController();
final String scope = "scope";
controllerWrapper.getControllerService().createScope(scope, 0L).get();
final String streamName = "stream1";
final StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
Stream stream = new StreamImpl(scope, streamName);
log.info("Creating stream {}/{}", scope, streamName);
if (!controller.createStream(scope, streamName, config).get()) {
log.error("Stream already existed, exiting");
return;
}
// Test 1: scale stream: split one segment into two
log.info("Scaling stream {}/{}, splitting one segment into two", scope, streamName);
Map<Double, Double> map = new HashMap<>();
map.put(0.0, 0.5);
map.put(0.5, 1.0);
if (!controller.scaleStream(stream, Collections.singletonList(0L), map, executor).getFuture().get()) {
log.error("Scale stream: splitting segment into two failed, exiting");
return;
}
// Test 2: scale stream: merge two segments into one
log.info("Scaling stream {}/{}, merging two segments into one", scope, streamName);
CompletableFuture<Boolean> scaleResponseFuture = controller.scaleStream(stream, Arrays.asList(1L, 2L), Collections.singletonMap(0.0, 1.0), executor).getFuture();
if (!scaleResponseFuture.get()) {
log.error("Scale stream: merging two segments into one failed, exiting");
return;
}
// Test 3: create a transaction, and try scale operation, it should fail with precondition check failure
CompletableFuture<TxnSegments> txnFuture = controller.createTransaction(stream, 5000);
TxnSegments transaction = txnFuture.get();
if (transaction == null) {
log.error("Create transaction failed, exiting");
return;
}
log.info("Scaling stream {}/{}, splitting one segment into two, while transaction is ongoing", scope, streamName);
scaleResponseFuture = controller.scaleStream(stream, Collections.singletonList(3L), map, executor).getFuture();
CompletableFuture<Boolean> future = scaleResponseFuture.whenComplete((r, e) -> {
if (e != null) {
log.error("Failed: scale with ongoing transaction.", e);
} else if (getAndHandleExceptions(controller.checkTransactionStatus(stream, transaction.getTxnId()), RuntimeException::new) != Transaction.Status.OPEN) {
log.info("Success: scale with ongoing transaction.");
} else {
log.error("Failed: scale with ongoing transaction.");
}
});
CompletableFuture<Void> statusFuture = controller.abortTransaction(stream, transaction.getTxnId());
statusFuture.get();
future.get();
log.info("All scaling test PASSED");
ExecutorServiceHelpers.shutdown(executor);
System.exit(0);
} catch (Throwable t) {
log.error("test failed with {}", t);
System.exit(-1);
}
}
use of io.pravega.client.stream.impl.TxnSegments in project pravega by pravega.
the class ControllerBootstrapTest method bootstrapTest.
@Test(timeout = 20000)
public void bootstrapTest() throws Exception {
Controller controller = controllerWrapper.getController();
// Now start Pravega service.
serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
store = serviceBuilder.createStreamSegmentService();
tableStore = serviceBuilder.createTableStoreService();
server = new PravegaConnectionListener(false, servicePort, store, tableStore, serviceBuilder.getLowPriorityExecutor());
server.startListening();
// Create test scope. This operation should succeed.
Boolean scopeStatus = controller.createScope(SCOPE).join();
Assert.assertEquals(true, scopeStatus);
// Try creating a stream. It should not complete until Pravega host has started.
// After Pravega host starts, stream should be successfully created.
StreamConfiguration streamConfiguration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
CompletableFuture<Boolean> streamStatus = controller.createStream(SCOPE, STREAM, streamConfiguration);
Assert.assertTrue(!streamStatus.isDone());
// Ensure that create stream succeeds.
Boolean status = streamStatus.join();
Assert.assertEquals(true, status);
// Now create transaction should succeed.
CompletableFuture<TxnSegments> txIdFuture = controller.createTransaction(new StreamImpl(SCOPE, STREAM), 10000);
TxnSegments id = txIdFuture.join();
Assert.assertNotNull(id);
controllerWrapper.awaitRunning();
}
use of io.pravega.client.stream.impl.TxnSegments in project pravega by pravega.
the class ControllerImpl method convert.
private TxnSegments convert(CreateTxnResponse response) {
NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
for (SegmentRange r : response.getActiveSegmentsList()) {
Preconditions.checkState(r.getMinKey() <= r.getMaxKey());
rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
}
StreamSegments segments = new StreamSegments(rangeMap);
return new TxnSegments(segments, encode(response.getTxnId()));
}
Aggregations