Search in sources :

Example 66 with Controller

use of io.pravega.client.control.impl.Controller in project pravega by pravega.

the class AppendTest method appendALotOfData.

@Test(timeout = 100000)
public void appendALotOfData() {
    String endpoint = "localhost";
    String scope = "Scope";
    String streamName = "appendALotOfData";
    int port = TestUtils.getAvailableListenPort();
    long heapSize = Runtime.getRuntime().maxMemory();
    long messageSize = Math.min(1024 * 1024, heapSize / 20000);
    ByteBuffer payload = ByteBuffer.allocate((int) messageSize);
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
    @Cleanup("shutdown") InlineExecutor tokenExpiryExecutor = new InlineExecutor();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, tokenExpiryExecutor);
    server.startListening();
    ClientConfig config = ClientConfig.builder().build();
    SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(config);
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(config, clientCF);
    Controller controller = new MockController(endpoint, port, connectionPool, true);
    @Cleanup StreamManagerImpl streamManager = new StreamManagerImpl(controller, connectionPool);
    streamManager.createScope(scope);
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, config);
    streamManager.createStream("Scope", streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
    @Cleanup EventStreamWriter<ByteBuffer> producer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().build());
    @Cleanup RawClient rawClient = new RawClient(new PravegaNodeUri(endpoint, port), connectionPool);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 100; j++) {
            producer.writeEvent(payload.slice());
        }
        producer.flush();
        long requestId = rawClient.getFlow().getNextSequenceNumber();
        String scopedName = new Segment(scope, streamName, 0).getScopedName();
        WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(requestId, scopedName, i * 100L * (payload.remaining() + TYPE_PLUS_LENGTH_SIZE), "");
        Reply reply = rawClient.sendRequest(requestId, request).join();
        assertFalse(reply.toString(), reply.isFailure());
    }
    producer.close();
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) RawClient(io.pravega.client.connection.impl.RawClient) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) ClientConfig(io.pravega.client.ClientConfig) WireCommands(io.pravega.shared.protocol.netty.WireCommands) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) ByteBuffer(java.nio.ByteBuffer) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockController(io.pravega.client.stream.mock.MockController) Reply(io.pravega.shared.protocol.netty.Reply) Test(org.junit.Test)

Example 67 with Controller

use of io.pravega.client.control.impl.Controller in project pravega by pravega.

the class BoundedStreamReaderTest method scaleStream.

private void scaleStream(final String streamName, final Map<Double, Double> keyRanges) throws Exception {
    Stream stream = Stream.of(SCOPE, streamName);
    Controller controller = controllerWrapper.getController();
    assertTrue(controller.scaleStream(stream, Collections.singletonList(0L), keyRanges, executorService()).getFuture().get());
}
Also used : Stream(io.pravega.client.stream.Stream) Controller(io.pravega.client.control.impl.Controller)

Example 68 with Controller

use of io.pravega.client.control.impl.Controller in project pravega by pravega.

the class StreamSeekTest method createStream.

private void createStream(String streamName) throws Exception {
    Controller controller = controllerWrapper.getController();
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    controller.createStream(SCOPE, streamName, config).join();
}
Also used : StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Controller(io.pravega.client.control.impl.Controller)

Example 69 with Controller

use of io.pravega.client.control.impl.Controller in project pravega by pravega.

the class StreamSeekTest method scaleStream.

private void scaleStream(final String streamName, final Map<Double, Double> keyRanges) throws Exception {
    Stream stream = Stream.of(SCOPE, streamName);
    Controller controller = controllerWrapper.getController();
    assertTrue(controller.scaleStream(stream, Collections.singletonList(0L), keyRanges, executorService()).getFuture().get());
}
Also used : Stream(io.pravega.client.stream.Stream) Controller(io.pravega.client.control.impl.Controller)

Example 70 with Controller

use of io.pravega.client.control.impl.Controller in project pravega by pravega.

the class UnreadBytesTest method testUnreadBytesWithEndStreamCuts.

@Test(timeout = 50000)
public void testUnreadBytesWithEndStreamCuts() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
    String streamName = "testUnreadBytesWithEndStreamCuts";
    Controller controller = PRAVEGA.getLocalController();
    controller.createScope("unreadbytes").get();
    controller.createStream("unreadbytes", streamName, config).get();
    @Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope("unreadbytes", ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
    // Write just 2 events to simplify simulating a checkpoint.
    writer.writeEvent("0", "data of size 30").get();
    writer.writeEvent("0", "data of size 30").get();
    String group = "testUnreadBytesWithEndStreamCuts-group";
    @Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope("unreadbytes", ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
    // create a bounded reader group.
    groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("unreadbytes/" + streamName, StreamCut.UNBOUNDED, getStreamCut(streamName, 90L, 0)).build());
    ReaderGroup readerGroup = groupManager.getReaderGroup(group);
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", group, new JavaSerializer<>(), ReaderConfig.builder().build());
    EventRead<String> firstEvent = reader.readNextEvent(15000);
    EventRead<String> secondEvent = reader.readNextEvent(15000);
    assertNotNull(firstEvent);
    assertEquals("data of size 30", firstEvent.getEvent());
    assertNotNull(secondEvent);
    assertEquals("data of size 30", secondEvent.getEvent());
    // trigger a checkpoint.
    CompletableFuture<Checkpoint> chkPointResult = readerGroup.initiateCheckpoint("test", executorService());
    EventRead<String> chkpointEvent = reader.readNextEvent(15000);
    assertEquals("test", chkpointEvent.getCheckpointName());
    EventRead<String> emptyEvent = reader.readNextEvent(100);
    assertEquals(false, emptyEvent.isCheckpoint());
    assertEquals(null, emptyEvent.getEvent());
    chkPointResult.join();
    // Writer events, to ensure 120Bytes are written.
    writer.writeEvent("0", "data of size 30").get();
    writer.writeEvent("0", "data of size 30").get();
    long unreadBytes = readerGroup.getMetrics().unreadBytes();
    // Ensure the endoffset of 90 Bytes is taken into consideration when computing unread
    assertTrue("Unread bvtes: " + unreadBytes, unreadBytes == 30);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ReaderGroup(io.pravega.client.stream.ReaderGroup) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) Checkpoint(io.pravega.client.stream.Checkpoint) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) 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