use of io.pravega.client.admin.StreamManager in project pravega by pravega.
the class TestUtils method createScopeStream.
/**
* Creates the given scope and stream using the given controller instance.
*
* @param controller Controller instance to use to create the Scope and Stream.
* @param scopeName Name of the Scope.
* @param streamName Name of the Stream.
* @param streamConfig Configuration for the Stream to be created.
*/
public static void createScopeStream(Controller controller, String scopeName, String streamName, StreamConfiguration streamConfig) {
ClientConfig clientConfig = ClientConfig.builder().build();
@Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, new SocketConnectionFactoryImpl(clientConfig));
// Don't close the controller.
@SuppressWarnings("resource") StreamManager streamManager = new StreamManagerImpl(controller, cp);
// create scope
Boolean createScopeStatus = streamManager.createScope(scopeName);
log.info("Create scope status {}", createScopeStatus);
// create stream
Boolean createStreamStatus = streamManager.createStream(scopeName, streamName, streamConfig);
log.info("Create stream status {}", createStreamStatus);
}
use of io.pravega.client.admin.StreamManager in project pravega by pravega.
the class TestUtils method deleteScopeStream.
/**
* Deletes the given scope and stream using the given controller instance.
*
* @param controller Controller instance to use to create the Scope and Stream.
* @param scopeName Name of the Scope.
* @param streamName Name of the Stream.
*/
public static void deleteScopeStream(Controller controller, String scopeName, String streamName) {
ClientConfig clientConfig = ClientConfig.builder().build();
@Cleanup ConnectionPool cp = new ConnectionPoolImpl(clientConfig, new SocketConnectionFactoryImpl(clientConfig));
// Don't close the controller.
@SuppressWarnings("resource") StreamManager streamManager = new StreamManagerImpl(controller, cp);
// delete stream
Boolean sealStreamStatus = streamManager.sealStream(scopeName, streamName);
log.info("Seal stream status {}", sealStreamStatus);
Boolean deleteStreamStatus = streamManager.deleteStream(scopeName, streamName);
log.info("Delete stream status {}", deleteStreamStatus);
// create scope
Boolean deleteScopeStatus = streamManager.deleteScope(scopeName);
log.info("Delete scope status {}", deleteScopeStatus);
}
use of io.pravega.client.admin.StreamManager in project pravega by pravega.
the class StreamManagerImplTest method testForceDeleteScope.
@Test(timeout = 10000)
public void testForceDeleteScope() 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 stream3 = "stream3";
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());
streamManager.createStream(scope, stream3, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(3, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream3)));
// mock controller client to throw exceptions when attempting to seal and delete for stream 1.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to seal stream"))).when(mockController).sealStream(scope, stream1);
doAnswer(x -> Futures.failedFuture(new IllegalArgumentException("Stream not sealed"))).when(mockController).deleteStream(scope, stream1);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
// throw invalid stream for stream 2. Delete should happen despite invalid stream exception.
doAnswer(x -> Futures.failedFuture(new InvalidStreamException("Stream does not exist"))).when(mockController).sealStream(scope, stream2);
assertTrue(streamManager.deleteScope(scope, true));
}
use of io.pravega.client.admin.StreamManager in project pravega by pravega.
the class StreamManagerImplTest method testForceDeleteScopeWithKeyValueTables.
@Test(timeout = 10000)
public void testForceDeleteScopeWithKeyValueTables() 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.CreateTableSegment request = (WireCommands.CreateTableSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.CreateTableSegment request = invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.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));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.DeleteTableSegment request = invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.DeleteTableSegment.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);
@Cleanup final KeyValueTableManager keyValueTableManager = new KeyValueTableManagerImpl(mockController, connectionFactory);
String scope = "scope";
String kvt1 = "kvt1";
String kvt2 = "kvt2";
streamManager.createScope(scope);
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(1).primaryKeyLength(1).secondaryKeyLength(1).build();
keyValueTableManager.createKeyValueTable(scope, kvt1, kvtConfig);
keyValueTableManager.createKeyValueTable(scope, kvt2, kvtConfig);
Set<KeyValueTableInfo> keyValueTables = Sets.newHashSet(keyValueTableManager.listKeyValueTables(scope));
assertEquals(2, keyValueTables.size());
assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt1)));
assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt2)));
// mock controller client to throw exceptions when attempting to delete key value table 1.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to delete key value table"))).when(mockController).deleteKeyValueTable(scope, kvt1);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
assertTrue(streamManager.deleteScope(scope, true));
}
use of io.pravega.client.admin.StreamManager 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());
}
Aggregations