use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class DebugStreamSegmentsTest method testOutOfSequence.
@Test(timeout = 30000)
public void testOutOfSequence() throws Exception {
// 1. Prepare
createScope(SCOPE);
createStream(STREAM);
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
when(streamFactory.createOutputStreamForSegment(any(), any(), any(), any())).thenReturn(mock(SegmentOutputStream.class));
SegmentSelector selector = new SegmentSelector(Stream.of(SCOPE, STREAM), controllerWrapper.getController(), streamFactory, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
// 2.Create clientFactory.
@Cleanup EventStreamClientFactory clientFactoryInternal = EventStreamClientFactory.withScope("_system", ClientConfig.builder().controllerURI(controllerUri).build());
@Cleanup final Controller controller = controllerWrapper.getController();
Segment[] lastSegments = new Segment[100];
for (int i = 0; i < 10; i++) {
randomScaleUpScaleDown(clientFactoryInternal, controller);
selector.refreshSegmentEventWriters(segment -> {
});
for (int key = 0; key < 100; key++) {
Segment segment = selector.getSegmentForEvent("key-" + key);
if (lastSegments[key] != null) {
int lastEpoch = NameUtils.getEpoch(lastSegments[key].getSegmentId());
int thisEpoch = NameUtils.getEpoch(segment.getSegmentId());
assertTrue(thisEpoch >= lastEpoch);
if (thisEpoch == lastEpoch) {
assertEquals(lastSegments[key], segment);
}
}
lastSegments[key] = segment;
}
}
}
use of io.pravega.client.control.impl.Controller 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.control.impl.Controller in project pravega by pravega.
the class ControllerServiceTest method streamMetadataTest.
@Test(timeout = 40000)
public void streamMetadataTest() throws Exception {
final String scope = "testScope";
final String stream = "testStream";
StreamConfiguration streamConfiguration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
Controller controller = controllerWrapper.getController();
// Create test scope. This operation should succeed.
assertTrue(controller.createScope(scope).join());
// Delete the test scope. This operation should also succeed.
assertTrue(controller.deleteScope(scope).join());
// Try creating a stream. It should fail, since the scope does not exist.
assertFalse(Futures.await(controller.createStream(scope, stream, streamConfiguration)));
// Again create the scope.
assertTrue(controller.createScope(scope).join());
// Try creating the stream again. It should succeed now, since the scope exists.
assertTrue(controller.createStream(scope, stream, streamConfiguration).join());
// Delete test scope. This operation should fail, since it is not empty.
assertFalse(Futures.await(controller.deleteScope(scope)));
// Delete a non-existent scope.
assertFalse(controller.deleteScope("non_existent_scope").get());
// Create a scope with invalid characters. It should fail.
assertFalse(Futures.await(controller.createScope("abc/def")));
// Try creating already existing scope.
assertFalse(controller.createScope(scope).join());
// Try creating stream with invalid characters. It should fail.
assertFalse(Futures.await(controller.createStream(scope, "abc/def", StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build())));
// Try creating already existing stream.
assertFalse(controller.createStream(scope, stream, streamConfiguration).join());
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ControllerServiceTest method streamTagTest.
@Test
public void streamTagTest() {
final String scope = "sc";
final String stream = "st";
final String stream2 = "st2";
Controller controller = controllerWrapper.getController();
controller.createScope(scope).join();
System.out.println("scope created");
// Create Stream with tags t1, t2
StreamConfiguration strCfg = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).tag("t1").tag("t2").build();
controller.createStream(scope, stream, strCfg).join();
assertEquals(Set.of("t1", "t2"), controller.getStreamConfiguration(scope, stream).join().getTags());
// Update stream to have tags t2, t3
StreamConfiguration strCfgNew = strCfg.toBuilder().clearTags().tags(Set.of("t2", "t3")).build();
controller.updateStream(scope, stream, strCfgNew).join();
// Check if the stream tags are infact t2, t3
assertEquals(Set.of("t2", "t3"), controller.getStreamConfiguration(scope, stream).join().getTags());
// List Streams with tag t2. only one stream should be listed
assertEquals(Collections.singletonList(stream), listStreamsForTag(scope, controller, "t2"));
// Create stream2 with tags t1, t2
controller.createStream(scope, stream2, strCfg).join();
// List Streams with tag t2. two stream should be listed
assertEquals(Arrays.asList(stream2, stream), listStreamsForTag(scope, controller, "t2"));
controller.sealStream(scope, stream2).join();
controller.deleteStream(scope, stream2).join();
// List Streams with tag t2. two stream should be listed
assertEquals(Arrays.asList(stream), listStreamsForTag(scope, controller, "t2"));
assertEquals(strCfgNew, controller.getStreamConfiguration(scope, stream).join());
controller.sealStream(scope, stream).join();
controller.deleteStream(scope, stream).join();
assertEquals(Collections.emptyList(), listStreamsForTag(scope, controller, "t2"));
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ReadTest method readConditionalData.
@Test(timeout = 10000)
public void readConditionalData() throws SegmentSealedException, EndOfSegmentException, SegmentTruncatedException {
String endpoint = "localhost";
String scope = "scope";
String stream = "readConditionalData";
int port = TestUtils.getAvailableListenPort();
byte[] testString = "Hello world\n".getBytes();
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
@Cleanup Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
ConditionalOutputStreamFactoryImpl segmentproducerClient = new ConditionalOutputStreamFactoryImpl(controller, connectionPool);
SegmentInputStreamFactoryImpl segmentConsumerClient = new SegmentInputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup ConditionalOutputStream out = segmentproducerClient.createConditionalOutputStream(segment, DelegationTokenProviderFactory.createWithEmptyToken(), EventWriterConfig.builder().build());
assertTrue(out.write(ByteBuffer.wrap(testString), 0));
@Cleanup EventSegmentReader in = segmentConsumerClient.createEventReaderForSegment(segment);
ByteBuffer result = in.read();
assertEquals(ByteBuffer.wrap(testString), result);
assertNull(in.read(100));
assertFalse(out.write(ByteBuffer.wrap(testString), 0));
assertTrue(out.write(ByteBuffer.wrap(testString), testString.length + WireCommands.TYPE_PLUS_LENGTH_SIZE));
result = in.read();
assertEquals(ByteBuffer.wrap(testString), result);
assertNull(in.read(100));
}
Aggregations