use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class AutoScaleTest method createStream.
/**
* Invoke the createStream method, ensure we are able to create stream.
*
* @throws InterruptedException if interrupted
* @throws URISyntaxException If URI is invalid
* @throws ExecutionException if error in create stream
*/
@Before
public void createStream() throws InterruptedException, ExecutionException {
// create a scope
Controller controller = getController();
Boolean createScopeStatus = controller.createScope(SCOPE).get();
log.debug("create scope status {}", createScopeStatus);
// create a stream
Boolean createStreamStatus = controller.createStream(CONFIG_UP).get();
log.debug("create stream status for scale up stream {}", createStreamStatus);
createStreamStatus = controller.createStream(CONFIG_DOWN).get();
log.debug("create stream status for scaledown stream {}", createStreamStatus);
log.debug("scale down stream starting segments:" + controller.getCurrentSegments(SCOPE, SCALE_DOWN_STREAM_NAME).get().getSegments().size());
Map<Double, Double> keyRanges = new HashMap<>();
keyRanges.put(0.0, 0.5);
keyRanges.put(0.5, 1.0);
Boolean status = controller.scaleStream(new StreamImpl(SCOPE, SCALE_DOWN_STREAM_NAME), Collections.singletonList(0), keyRanges, EXECUTOR_SERVICE).getFuture().get();
assertTrue(status);
createStreamStatus = controller.createStream(CONFIG_TXN).get();
log.debug("create stream status for txn stream {}", createStreamStatus);
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class BucketService method handleStreamRemoved.
private void handleStreamRemoved(StreamNotification notification) {
StreamImpl stream;
log.info("{}: Stream {}/{} removed from bucket {}", serviceType, notification.getScope(), notification.getStream(), bucketId);
stream = new StreamImpl(notification.getScope(), notification.getStream());
synchronized (lock) {
knownStreams.remove(stream);
}
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class StreamManagerImplTest method testStreamInfo.
@Test(timeout = 15000)
public void testStreamInfo() throws Exception {
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 = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true);
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
streamManager.createScope(defaultScope);
streamManager.createStream(defaultScope, streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
// 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(3, info.getTailStreamCut().asImpl().getPositions().size());
assertNotNull(info.getHeadStreamCut());
assertEquals(stream, info.getHeadStreamCut().asImpl().getStream());
assertEquals(3, info.getHeadStreamCut().asImpl().getPositions().size());
assertFalse(info.isSealed());
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class StreamManagerImplTest method testForceDeleteScopeWithReaderGroups.
@Test
public void testForceDeleteScopeWithReaderGroups() throws ConnectionFailedException, DeleteScopeFailedException {
// 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));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.DeleteSegment request = (WireCommands.DeleteSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.DeleteSegment.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
String scope = "scope";
String stream1 = "stream1";
String stream2 = "stream2";
String readerGroup1 = "readerGroup1";
String readerGroup2 = "readerGroup2";
ReaderGroupConfig config1 = ReaderGroupConfig.builder().stream(NameUtils.getScopedStreamName(scope, stream1)).build();
ReaderGroupConfig config2 = ReaderGroupConfig.builder().stream(NameUtils.getScopedStreamName(scope, stream2)).build();
streamManager.createScope(scope);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw exceptions when attempting to get config for reader-group.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to access reader-group config"))).when(mockController).getReaderGroupConfig(scope, readerGroup1);
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw exceptions when attempting to delete the reader-group.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to delete reader-group"))).when(mockController).deleteReaderGroup(scope, readerGroup1, config1.getReaderGroupId());
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw ReaderGroupNotFoundException when attempting to get the config of reader-group.
doAnswer(x -> Futures.failedFuture(new ReaderGroupNotFoundException("Reader-group does not exist"))).when(mockController).getReaderGroupConfig(scope, readerGroup1);
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
assertTrue(streamManager.deleteScope(scope, true));
}
use of io.pravega.client.stream.impl.StreamImpl in project pravega by pravega.
the class ControllerImplTest method testGetStreamCutSuccessors.
@Test
public void testGetStreamCutSuccessors() throws Exception {
StreamCut from = new StreamCutImpl(new StreamImpl("scope1", "stream1"), Collections.emptyMap());
CompletableFuture<StreamSegmentSuccessors> successors = controllerClient.getSuccessors(from);
assertEquals(2, successors.get().getSegments().size());
}
Aggregations