use of io.pravega.client.segment.impl.Segment 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.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetCurrentSegmentsKeyValueTable.
@Test
public void testGetCurrentSegmentsKeyValueTable() throws Exception {
CompletableFuture<KeyValueTableSegments> kvtSegments;
kvtSegments = controllerClient.getCurrentSegmentsForKeyValueTable("scope1", "kvtable1");
assertTrue(kvtSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "kvtable1", 4), kvtSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "kvtable1", 5), kvtSegments.get().getSegmentForKey(0.6));
kvtSegments = controllerClient.getCurrentSegmentsForKeyValueTable("scope1", "kvtable2");
AssertExtensions.assertFutureThrows("Should throw Exception", kvtSegments, throwable -> true);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testCreateReaderGroup.
@Test
public void testCreateReaderGroup() throws Exception {
CompletableFuture<ReaderGroupConfig> createRGConfig;
final Segment seg0 = new Segment("scope1", "stream1", 0L);
final Segment seg1 = new Segment("scope1", "stream1", 1L);
ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), startStreamCut));
ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), endStreamCut));
ReaderGroupConfig config = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
config = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
createRGConfig = controllerClient.createReaderGroup("scope1", "rg1", config);
assertEquals(createRGConfig.get().getReaderGroupId(), config.getReaderGroupId());
assertEquals(createRGConfig.get().getGeneration(), config.getGeneration());
createRGConfig = controllerClient.createReaderGroup("scope1", "rg2", config);
AssertExtensions.assertFutureThrows("Server should throw exception", createRGConfig, Throwable -> true);
createRGConfig = controllerClient.createReaderGroup("scope1", "rg3", config);
AssertExtensions.assertFutureThrows("Server should throw exception", createRGConfig, throwable -> throwable instanceof IllegalArgumentException);
createRGConfig = controllerClient.createReaderGroup("scope1", "rg4", config);
AssertExtensions.assertFutureThrows("Server should throw exception", createRGConfig, throwable -> throwable instanceof IllegalArgumentException);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class RawClientTest method testHello.
@Test
public void testHello() throws ConnectionFailedException {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
Mockito.verify(connection).send(Mockito.eq(new WireCommands.Hello(0, 0)));
rawClient.close();
Mockito.verify(connection).close();
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class RawClientTest method testReplyWithoutRequest.
@Test
public void testReplyWithoutRequest() {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
@Cleanup RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
UUID id = UUID.randomUUID();
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
DataAppended reply = new DataAppended(requestId, id, 1, 0, -1);
processor.process(reply);
assertFalse(rawClient.isClosed());
}
Aggregations