Search in sources :

Example 71 with Controller

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;
        }
    }
}
Also used : SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) SegmentSelector(io.pravega.client.stream.impl.SegmentSelector) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 72 with Controller

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();
}
Also used : TxnSegments(io.pravega.client.stream.impl.TxnSegments) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Controller(io.pravega.client.control.impl.Controller) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Test(org.junit.Test)

Example 73 with Controller

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());
}
Also used : StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Controller(io.pravega.client.control.impl.Controller) Test(org.junit.Test)

Example 74 with Controller

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"));
}
Also used : StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Controller(io.pravega.client.control.impl.Controller) Test(org.junit.Test)

Example 75 with Controller

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));
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ConditionalOutputStream(io.pravega.client.segment.impl.ConditionalOutputStream) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ConditionalOutputStreamFactoryImpl(io.pravega.client.segment.impl.ConditionalOutputStreamFactoryImpl) EventSegmentReader(io.pravega.client.segment.impl.EventSegmentReader) MockController(io.pravega.client.stream.mock.MockController) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) Test(org.junit.Test)

Aggregations

Controller (io.pravega.client.control.impl.Controller)120 Test (org.junit.Test)95 Cleanup (lombok.Cleanup)81 Segment (io.pravega.client.segment.impl.Segment)53 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)50 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)47 Stream (io.pravega.client.stream.Stream)37 CompletableFuture (java.util.concurrent.CompletableFuture)35 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)34 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)33 HashMap (java.util.HashMap)29 ClientConfig (io.pravega.client.ClientConfig)28 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)28 StreamImpl (io.pravega.client.stream.impl.StreamImpl)25 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)24 Slf4j (lombok.extern.slf4j.Slf4j)24 Before (org.junit.Before)23 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)22 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)21 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)21