Search in sources :

Example 1 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class ServiceStarter method start.

// endregion
// region Service Operation
public void start() throws Exception {
    Exceptions.checkNotClosed(this.closed, this);
    log.info("Initializing metrics provider ...");
    MetricsProvider.initialize(builderConfig.getConfig(MetricsConfig::builder));
    statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.start();
    log.info("Initializing ZooKeeper Client ...");
    this.zkClient = createZKClient();
    log.info("Initializing Service Builder ...");
    this.serviceBuilder.initialize();
    log.info("Creating StreamSegmentService ...");
    StreamSegmentStore service = this.serviceBuilder.createStreamSegmentService();
    log.info("Creating Segment Stats recorder ...");
    segmentStatsFactory = new SegmentStatsFactory();
    SegmentStatsRecorder statsRecorder = segmentStatsFactory.createSegmentStatsRecorder(service, builderConfig.getConfig(AutoScalerConfig::builder));
    TokenVerifierImpl tokenVerifier = new TokenVerifierImpl(builderConfig.getConfig(AutoScalerConfig::builder));
    this.listener = new PravegaConnectionListener(this.serviceConfig.isEnableTls(), this.serviceConfig.getListeningIPAddress(), this.serviceConfig.getListeningPort(), service, statsRecorder, tokenVerifier, this.serviceConfig.getCertFile(), this.serviceConfig.getKeyFile());
    this.listener.startListening();
    log.info("PravegaConnectionListener started successfully.");
    log.info("StreamSegmentService started.");
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) SegmentStatsFactory(io.pravega.segmentstore.server.host.stat.SegmentStatsFactory) TokenVerifierImpl(io.pravega.segmentstore.server.host.delegationtoken.TokenVerifierImpl) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)

Example 2 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class ReadFromDeletedStreamTest method testDeletedAndRecreatedStream.

@Test(timeout = 30000)
public void testDeletedAndRecreatedStream() throws Exception {
    @Cleanup MockStreamManager streamManager = new MockStreamManager("test", "localhost", Config.SERVICE_PORT);
    ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, "localhost", 12345, store, null, null, null, null);
    server.startListening();
    streamManager.createScope("test");
    streamManager.createStream("test", "test", CONFIG);
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    // Mocking pravega service by putting scale up and scale down requests for the stream
    @Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().build());
    test.writeEvent("0", "foo").get();
    streamManager.deleteStream("test", "test");
    AssertExtensions.assertThrows(NoSuchSegmentException.class, () -> test.writeEvent("0", "foo").get());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Example 3 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class ReadTest method readThroughStreamClient.

@Test
public void readThroughStreamClient() throws ReinitializationRequiredException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerName = "reader";
    String readerGroup = "group";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world\n";
    String scope = "Scope1";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
    MockClientFactory clientFactory = streamManager.getClientFactory();
    ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().stream(Stream.of(scope, streamName)).build();
    streamManager.createScope(scope);
    streamManager.createStream(scope, streamName, null);
    streamManager.createReaderGroup(readerGroup, groupConfig);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
    producer.writeEvent(testString);
    producer.flush();
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build());
    String read = reader.readNextEvent(5000).getEvent();
    assertEquals(testString, read);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) Test(org.junit.Test)

Example 4 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class ReadTest method readThroughSegmentClient.

@Test
public void readThroughSegmentClient() throws SegmentSealedException, EndOfSegmentException, SegmentTruncatedException {
    String endpoint = "localhost";
    String scope = "scope";
    String stream = "stream";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world\n";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
    server.startListening();
    ConnectionFactory clientCF = new ConnectionFactoryImpl(ClientConfig.builder().build());
    Controller controller = new MockController(endpoint, port, clientCF);
    controller.createScope(scope);
    controller.createStream(StreamConfiguration.builder().scope(scope).streamName(stream).build());
    SegmentOutputStreamFactoryImpl segmentproducerClient = new SegmentOutputStreamFactoryImpl(controller, clientCF);
    SegmentInputStreamFactoryImpl segmentConsumerClient = new SegmentInputStreamFactoryImpl(controller, clientCF);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup("close") SegmentOutputStream out = segmentproducerClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), "");
    out.write(new PendingEvent(null, ByteBuffer.wrap(testString.getBytes()), new CompletableFuture<>()));
    out.flush();
    @Cleanup("close") SegmentInputStream in = segmentConsumerClient.createInputStreamForSegment(segment);
    ByteBuffer result = in.read();
    assertEquals(ByteBuffer.wrap(testString.getBytes()), result);
    // Test large write followed by read
    out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
    out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
    out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[150000]), new CompletableFuture<>()));
    assertEquals(in.read().capacity(), 15);
    assertEquals(in.read().capacity(), 15);
    assertEquals(in.read().capacity(), 150000);
}
Also used : MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.stream.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) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PendingEvent(io.pravega.client.stream.impl.PendingEvent) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockController(io.pravega.client.stream.mock.MockController) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Example 5 with PravegaConnectionListener

use of io.pravega.segmentstore.server.host.handler.PravegaConnectionListener in project pravega by pravega.

the class ReaderGroupTest method testEventHandoff.

@Test(timeout = 20000)
public void testEventHandoff() throws Exception {
    String endpoint = "localhost";
    int servicePort = TestUtils.getAvailableListenPort();
    @Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, servicePort, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager(SCOPE, endpoint, servicePort);
    streamManager.createScope(SCOPE);
    streamManager.createStream(SCOPE, STREAM_NAME, StreamConfiguration.builder().scope(SCOPE).streamName(STREAM_NAME).scalingPolicy(ScalingPolicy.fixed(2)).build());
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(-1).stream(Stream.of(SCOPE, STREAM_NAME)).build();
    streamManager.createReaderGroup(READER_GROUP, groupConfig);
    writeEvents(100, clientFactory);
    ReaderThread r1 = new ReaderThread(20, "Reader1", clientFactory);
    ReaderThread r2 = new ReaderThread(80, "Reader2", clientFactory);
    Thread reader1Thread = new Thread(r1);
    Thread reader2Thread = new Thread(r2);
    reader1Thread.start();
    reader2Thread.start();
    reader1Thread.join();
    reader2Thread.join();
    if (r1.exception.get() != null) {
        throw r1.exception.get();
    }
    if (r2.exception.get() != null) {
        throw r2.exception.get();
    }
    streamManager.deleteReaderGroup(READER_GROUP);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Aggregations

PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)46 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)45 Cleanup (lombok.Cleanup)28 Test (org.junit.Test)23 TestingServerStarter (io.pravega.test.common.TestingServerStarter)22 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)20 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)19 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)18 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)16 Before (org.junit.Before)14 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Controller (io.pravega.client.stream.impl.Controller)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)10 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)7 TestingServer (org.apache.curator.test.TestingServer)7 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 StreamImpl (io.pravega.client.stream.impl.StreamImpl)5 ClientFactory (io.pravega.client.ClientFactory)4 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)4