use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class StreamManagerImplTest method testSealedStream.
@Test(timeout = 10000)
public void testSealedStream() throws ConnectionFailedException {
final String streamName = "stream";
final Stream stream = new StreamImpl(defaultScope, streamName);
// Setup Mocks
ClientConnection connection = mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
doReturn(CompletableFuture.completedFuture(true)).when(mockController).sealStream(defaultScope, streamName);
StreamSegments empty = new StreamSegments(new TreeMap<>());
doReturn(CompletableFuture.completedFuture(empty)).when(mockController).getCurrentSegments(defaultScope, streamName);
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
// Create a StreamManager
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
// Create a scope and stream and seal it.
streamManager.createScope(defaultScope);
streamManager.createStream(defaultScope, streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.sealStream(defaultScope, streamName);
// Fetch StreamInfo
StreamInfo info = streamManager.getStreamInfo(defaultScope, streamName);
// validate results.
assertEquals(defaultScope, info.getScope());
assertEquals(streamName, info.getStreamName());
assertNotNull(info.getTailStreamCut());
assertEquals(stream, info.getTailStreamCut().asImpl().getStream());
assertEquals(0, info.getTailStreamCut().asImpl().getPositions().size());
assertNotNull(info.getHeadStreamCut());
assertEquals(stream, info.getHeadStreamCut().asImpl().getStream());
assertEquals(3, info.getHeadStreamCut().asImpl().getPositions().size());
assertTrue(info.isSealed());
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class ControllerImplTest method testScale.
@Test
public void testScale() throws Exception {
CompletableFuture<Boolean> scaleStream;
StreamImpl stream = new StreamImpl("scope1", "stream1");
scaleStream = controllerClient.scaleStream(stream, new ArrayList<>(), new HashMap<>(), executor).getFuture();
assertTrue(scaleStream.get());
CompletableFuture<StreamSegments> segments = controllerClient.getCurrentSegments("scope1", "stream1");
assertEquals(2, segments.get().getSegments().size());
assertEquals(new Segment("scope1", "stream1", 6), segments.get().getSegmentForKey(0.25));
assertEquals(new Segment("scope1", "stream1", 7), segments.get().getSegmentForKey(0.75));
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("UNKNOWN", "stream2"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
scaleStream = controllerClient.scaleStream(new StreamImpl("scope1", "UNKNOWN"), new ArrayList<>(), new HashMap<>(), executor).getFuture();
AssertExtensions.assertFutureThrows("Should throw Exception", scaleStream, throwable -> true);
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class ControllerImplTest method testGetCurrentSegments.
@Test
public void testGetCurrentSegments() throws Exception {
CompletableFuture<StreamSegments> streamSegments;
streamSegments = controllerClient.getCurrentSegments("scope1", "stream1");
assertTrue(streamSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "stream1", 6), streamSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "stream1", 7), streamSegments.get().getSegmentForKey(0.6));
streamSegments = controllerClient.getCurrentSegments("scope1", "stream2");
AssertExtensions.assertFutureThrows("Should throw Exception", streamSegments, throwable -> true);
streamSegments = controllerClient.getCurrentSegments("scope1", "sealedStream");
assertTrue(streamSegments.get().getNumberOfSegments() == 0);
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class ControllerImplTest method testParallelGetCurrentSegments.
@Test
public void testParallelGetCurrentSegments() throws Exception {
final ExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(10, "testParallelGetCurrentSegments");
Semaphore createCount = new Semaphore(-19);
AtomicBoolean success = new AtomicBoolean(true);
for (int i = 0; i < 10; i++) {
executorService.submit(() -> {
for (int j = 0; j < 2; j++) {
try {
CompletableFuture<StreamSegments> streamSegments;
streamSegments = controllerClient.getCurrentSegments("scope1", "streamparallel");
assertTrue(streamSegments.get().getSegments().size() == 2);
assertEquals(new Segment("scope1", "streamparallel", 0), streamSegments.get().getSegmentForKey(0.2));
assertEquals(new Segment("scope1", "streamparallel", 1), streamSegments.get().getSegmentForKey(0.6));
createCount.release();
} catch (Exception e) {
log.error("Exception when getting segments: {}", e);
// Don't wait for other threads to complete.
success.set(false);
createCount.release(20);
}
}
});
}
createCount.acquire();
ExecutorServiceHelpers.shutdown(executorService);
assertTrue(success.get());
}
use of io.pravega.client.stream.impl.StreamSegments 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();
}
Aggregations