Search in sources :

Example 26 with SocketConnectionFactoryImpl

use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.

the class EventProcessorTest method testEventProcessor.

@Test(timeout = 60000)
public void testEventProcessor() throws Exception {
    final String scope = "controllerScope";
    final String streamName = "stream1";
    final String readerGroup = "readerGroup";
    controller.createScope(scope).join();
    final StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    controller.createStream(scope, streamName, config).join();
    eventSerializer = new EventSerializer<>(new TestSerializer());
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
    @Cleanup EventStreamWriter<TestEvent> producer = clientFactory.createEventWriter(streamName, eventSerializer, EventWriterConfig.builder().build());
    int[] input = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    int expectedSum = input.length * (input.length + 1) / 2;
    for (int i = 0; i < input.length; i++) {
        producer.writeEvent("key", new TestEvent(input[i]));
    }
    producer.writeEvent("key", new TestEvent(-1));
    producer.flush();
    EventProcessorSystem system = new EventProcessorSystemImpl("Controller", host, scope, clientFactory, new ReaderGroupManagerImpl(scope, controller, clientFactory));
    CheckpointConfig.CheckpointPeriod period = CheckpointConfig.CheckpointPeriod.builder().numEvents(1).numSeconds(1).build();
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.Periodic).checkpointPeriod(period).build();
    EventProcessorGroupConfig eventProcessorGroupConfig = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(readerGroup).streamName(streamName).checkpointConfig(checkpointConfig).build();
    CompletableFuture<Long> result = new CompletableFuture<>();
    // Test case 1. Actor does not throw any exception during normal operation.
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new TestEventProcessor(false, result)).serializer(eventSerializer).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(eventProcessorGroupConfig).build();
    @Cleanup EventProcessorGroup<TestEvent> eventProcessorGroup = system.createEventProcessorGroup(eventProcessorConfig, CheckpointStoreFactory.createInMemoryStore(), executorService());
    Long value = result.join();
    Assert.assertEquals(expectedSum, value.longValue());
    log.info("SUCCESS: received expected sum = " + expectedSum);
}
Also used : EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) Test(org.junit.Test)

Example 27 with SocketConnectionFactoryImpl

use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.

the class EventProcessorTest method testEventProcessorFailover.

@Test(timeout = 60000)
public void testEventProcessorFailover() throws Exception {
    final String scope = "controllerScope2";
    final String streamName = "stream2";
    final String readerGroup = "readerGroup2";
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    controller.createScope(scope).join();
    final StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    controller.createStream(scope, streamName, config).join();
    eventSerializer = new EventSerializer<>(new TestSerializer());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
    @Cleanup EventStreamWriter<TestEvent> producer = clientFactory.createEventWriter(streamName, eventSerializer, EventWriterConfig.builder().build());
    TestEvent event1 = new TestEvent(0);
    producer.writeEvent("key", event1).join();
    TestEvent event2 = new TestEvent(1);
    producer.writeEvent("key", event2).join();
    producer.flush();
    EventProcessorSystem system = new EventProcessorSystemImpl("Controller", host, scope, clientFactory, new ReaderGroupManagerImpl(scope, controller, clientFactory));
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.None).build();
    EventProcessorGroupConfig eventProcessorGroupConfig = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(readerGroup).streamName(streamName).checkpointConfig(checkpointConfig).build();
    LinkedBlockingQueue<TestEvent> eventsProcessed = new LinkedBlockingQueue<>();
    EventProcessorConfig<TestEvent> eventProcessorConfig = EventProcessorConfig.<TestEvent>builder().supplier(() -> new EventProcessor<TestEvent>() {

        @Override
        protected void process(TestEvent event, Position position) {
            try {
                eventsProcessed.offer(event);
                // keep sending null position
                getCheckpointer().store(null);
            } catch (CheckpointStoreException e) {
                e.printStackTrace();
            }
        }
    }).serializer(eventSerializer).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(eventProcessorGroupConfig).build();
    @Cleanup EventProcessorGroup<TestEvent> eventProcessorGroup = system.createEventProcessorGroup(eventProcessorConfig, CheckpointStoreFactory.createInMemoryStore(), executorService());
    eventProcessorGroup.awaitRunning();
    // wait until both events are read
    assertEquals(event1, eventsProcessed.take());
    assertEquals(event2, eventsProcessed.take());
    assertTrue(eventsProcessed.isEmpty());
    // shutdown event processor
    // upon shutdown readerGroup.offline and reader.close should have been called.
    eventProcessorGroup.stopAsync();
    eventProcessorGroup.awaitTerminated();
    @Cleanup ConnectionFactory connectionFactory2 = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ClientFactoryImpl clientFactory2 = new ClientFactoryImpl(scope, controller, connectionFactory2);
    system = new EventProcessorSystemImpl("Controller2", host, scope, clientFactory2, new ReaderGroupManagerImpl(scope, controller, clientFactory2));
    EventProcessorConfig<TestEvent> eventProcessorConfig2 = EventProcessorConfig.<TestEvent>builder().supplier(() -> new EventProcessor<TestEvent>() {

        @Override
        protected void process(TestEvent event, Position position) {
            try {
                eventsProcessed.offer(event);
                getCheckpointer().store(null);
            } catch (CheckpointStoreException e) {
                e.printStackTrace();
            }
        }
    }).serializer(eventSerializer).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(eventProcessorGroupConfig).build();
    @Cleanup EventProcessorGroup<TestEvent> eventProcessorGroup2 = system.createEventProcessorGroup(eventProcessorConfig2, CheckpointStoreFactory.createInMemoryStore(), executorService());
    eventProcessorGroup2.awaitRunning();
    // verify that both events are read again
    assertEquals(event1, eventsProcessed.take());
    assertEquals(event2, eventsProcessed.take());
    assertTrue(eventsProcessed.isEmpty());
    eventProcessorGroup2.stopAsync();
    eventProcessorGroup2.awaitTerminated();
}
Also used : EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) Position(io.pravega.client.stream.Position) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Cleanup(lombok.Cleanup) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Example 28 with SocketConnectionFactoryImpl

use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.

the class EventProcessorTest method testEventProcessorRebalance.

@Test(timeout = 60000)
public void testEventProcessorRebalance() throws Exception {
    final String scope = "scope";
    final String streamName = "stream";
    final String readerGroupName = "readerGroup";
    controller.createScope(scope).join();
    final StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(4)).build();
    controller.createStream(scope, streamName, config).join();
    eventSerializer = new EventSerializer<>(new TestSerializer());
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
    CheckpointConfig.CheckpointPeriod period = CheckpointConfig.CheckpointPeriod.builder().numEvents(1).numSeconds(1).build();
    CheckpointConfig checkpointConfig = CheckpointConfig.builder().type(CheckpointConfig.Type.Periodic).checkpointPeriod(period).build();
    EventProcessorGroupConfig eventProcessorGroupConfig = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(readerGroupName).streamName(streamName).checkpointConfig(checkpointConfig).build();
    LinkedBlockingQueue<Integer> queue1 = new LinkedBlockingQueue<>();
    EventProcessorConfig<TestEvent> eventProcessorConfig1 = EventProcessorConfig.<TestEvent>builder().supplier(() -> new TestEventProcessor2(queue1)).serializer(eventSerializer).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(eventProcessorGroupConfig).minRebalanceIntervalMillis(Duration.ofMillis(100).toMillis()).build();
    // create a group and verify that all events can be written and read by readers in this group.
    EventProcessorSystem system1 = new EventProcessorSystemImpl("Controller", "process1", scope, clientFactory, new ReaderGroupManagerImpl(scope, controller, clientFactory));
    @Cleanup EventProcessorGroup<TestEvent> eventProcessorGroup1 = system1.createEventProcessorGroup(eventProcessorConfig1, CheckpointStoreFactory.createInMemoryStore(), executorService());
    eventProcessorGroup1.awaitRunning();
    log.info("first event processor started");
    @Cleanup EventStreamWriter<TestEvent> writer = clientFactory.createEventWriter(streamName, eventSerializer, EventWriterConfig.builder().build());
    // write 10 events and read them back from the queue passed to first event processor's
    List<Integer> input = IntStream.range(0, 10).boxed().collect(Collectors.toList());
    ConcurrentSkipListSet<Integer> output = new ConcurrentSkipListSet<>();
    for (int val : input) {
        writer.writeEvent(new TestEvent(val));
    }
    writer.flush();
    // now wait until all the entries are read back.
    for (int i = 0; i < 10; i++) {
        // read 10 events back
        Integer entry = queue1.take();
        output.add(entry);
    }
    assertEquals(10, output.size());
    log.info("first event processor read all the messages");
    LinkedBlockingQueue<Integer> queue2 = new LinkedBlockingQueue<>();
    EventProcessorConfig<TestEvent> eventProcessorConfig2 = EventProcessorConfig.<TestEvent>builder().supplier(() -> new TestEventProcessor2(queue2)).serializer(eventSerializer).decider((Throwable e) -> ExceptionHandler.Directive.Stop).config(eventProcessorGroupConfig).minRebalanceIntervalMillis(Duration.ofMillis(100).toMillis()).build();
    // add another system and event processor group (effectively add a new set of readers to the readergroup)
    EventProcessorSystem system2 = new EventProcessorSystemImpl("Controller", "process2", scope, clientFactory, new ReaderGroupManagerImpl(scope, controller, clientFactory));
    @Cleanup EventProcessorGroup<TestEvent> eventProcessorGroup2 = system2.createEventProcessorGroup(eventProcessorConfig2, CheckpointStoreFactory.createInMemoryStore(), executorService());
    eventProcessorGroup2.awaitRunning();
    log.info("second event processor started");
    AtomicInteger queue1EntriesFound = new AtomicInteger(0);
    AtomicInteger queue2EntriesFound = new AtomicInteger(0);
    ConcurrentSkipListSet<Integer> output2 = new ConcurrentSkipListSet<>();
    // wait until rebalance may have happened.
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(scope, controller, clientFactory);
    ReaderGroup readerGroup = groupManager.getReaderGroup(readerGroupName);
    AtomicBoolean allAssigned = new AtomicBoolean(false);
    Futures.loop(() -> !allAssigned.get(), () -> Futures.delayedFuture(Duration.ofMillis(100), executorService()).thenAccept(v -> {
        ReaderSegmentDistribution distribution = readerGroup.getReaderSegmentDistribution();
        int numberOfReaders = distribution.getReaderSegmentDistribution().size();
        allAssigned.set(numberOfReaders == 2 && distribution.getReaderSegmentDistribution().values().stream().noneMatch(x -> x == 0));
    }), executorService()).join();
    // write 10 new events
    for (int val : input) {
        writer.writeEvent(new TestEvent(val));
    }
    writer.flush();
    // wait until at least one event is read from queue2
    CompletableFuture.allOf(CompletableFuture.runAsync(() -> {
        while (output2.size() < 10) {
            Integer entry = queue1.poll();
            if (entry != null) {
                log.info("entry read from queue 1: {}", entry);
                queue1EntriesFound.incrementAndGet();
                output2.add(entry);
            } else {
                Exceptions.handleInterrupted(() -> Thread.sleep(100));
            }
        }
    }), CompletableFuture.runAsync(() -> {
        while (output2.size() < 10) {
            Integer entry = queue2.poll();
            if (entry != null) {
                log.info("entry read from queue 2: {}", entry);
                queue2EntriesFound.incrementAndGet();
                output2.add(entry);
            } else {
                Exceptions.handleInterrupted(() -> Thread.sleep(100));
            }
        }
    })).join();
    assertTrue(queue1EntriesFound.get() > 0);
    assertTrue(queue2EntriesFound.get() > 0);
    assertEquals(10, output2.size());
}
Also used : EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) ReaderGroup(io.pravega.client.stream.ReaderGroup) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ReaderSegmentDistribution(io.pravega.client.stream.ReaderSegmentDistribution) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 29 with SocketConnectionFactoryImpl

use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.

the class EndToEndChannelLeakTest method testDetectChannelLeakSegmentSealedPooled.

@Test(timeout = 30000)
public void testDetectChannelLeakSegmentSealedPooled() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope(SCOPE, 0L).get();
    controller.createStream(SCOPE, STREAM_NAME, config).get();
    // Set the max number connections to verify channel creation behaviour
    final ClientConfig clientConfig = ClientConfig.builder().maxConnectionsPerSegmentStore(5).build();
    @Cleanup SocketConnectionFactoryImpl connectionFactory = new SocketConnectionFactoryImpl(clientConfig, new InlineExecutor());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(clientConfig, connectionFactory);
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionPool);
    // Create a writer.
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(SCOPE, serializer, writerConfig);
    // Write an event.
    writer.writeEvent("0", "zero").get();
    assertChannelCount(1, connectionPool, connectionFactory);
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(SCOPE, controller, clientFactory);
    groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(0).stream(Stream.of(SCOPE, STREAM_NAME)).build());
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId1", READER_GROUP, serializer, ReaderConfig.builder().disableTimeWindows(true).build());
    // Read an event.
    EventRead<String> event = reader1.readNextEvent(10000);
    assertEquals("zero", event.getEvent());
    // scale
    Stream stream = new StreamImpl(SCOPE, SCOPE);
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.33);
    map.put(0.33, 0.66);
    map.put(0.66, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0L), map, executor).getFuture().get();
    assertTrue(result);
    event = reader1.readNextEvent(0);
    assertNull(event.getEvent());
    @Cleanup ReaderGroup readerGroup = groupManager.getReaderGroup(READER_GROUP);
    readerGroup.initiateCheckpoint("cp", executor);
    event = reader1.readNextEvent(5000);
    assertEquals("cp", event.getCheckpointName());
    // Write more events.
    writer.writeEvent("0", "one").get();
    writer.writeEvent("0", "two").get();
    writer.writeEvent("1", "three").get();
    event = reader1.readNextEvent(10000);
    assertNotNull(event.getEvent());
    assertChannelCount(5, connectionPool, connectionFactory);
    event = reader1.readNextEvent(10000);
    assertNotNull(event.getEvent());
    assertChannelCount(5, connectionPool, connectionFactory);
    event = reader1.readNextEvent(10000);
    assertNotNull(event.getEvent());
    assertChannelCount(5, connectionPool, connectionFactory);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ReaderGroup(io.pravega.client.stream.ReaderGroup) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) InlineExecutor(io.pravega.test.common.InlineExecutor) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Example 30 with SocketConnectionFactoryImpl

use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.

the class EndToEndChannelLeakTest method testDetectChannelLeakSegmentSealed.

@Test(timeout = 30000)
public void testDetectChannelLeakSegmentSealed() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope(SCOPE, 0L).get();
    controller.createStream(SCOPE, STREAM_NAME, config).get();
    // Set the max number connections to verify channel creation behaviour
    final ClientConfig clientConfig = ClientConfig.builder().maxConnectionsPerSegmentStore(500).build();
    @Cleanup SocketConnectionFactoryImpl connectionFactory = new SocketConnectionFactoryImpl(clientConfig, executor);
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(clientConfig, connectionFactory);
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionPool);
    int channelCount = 0;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(SCOPE, controller, clientFactory);
    groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(0).stream(Stream.of(SCOPE, STREAM_NAME)).build());
    // Should not add any connections
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    // Create a writer.
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(SCOPE, serializer, writerConfig);
    // Write an event.
    writer.writeEvent("0", "zero").get();
    channelCount += 1;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId1", READER_GROUP, serializer, ReaderConfig.builder().disableTimeWindows(true).build());
    // One for segment 3 for state synchronizer
    channelCount += 4;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    // Read an event.
    EventRead<String> event = reader1.readNextEvent(10000);
    assertEquals("zero", event.getEvent());
    channelCount += 1;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    // scale
    Stream stream = new StreamImpl(SCOPE, SCOPE);
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.33);
    map.put(0.33, 0.66);
    map.put(0.66, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0L), map, executor).getFuture().get();
    assertTrue(result);
    event = reader1.readNextEvent(0);
    assertNull(event.getEvent());
    // Reader should see EOS
    channelCount -= 1;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    // should detect end of segment
    writer.writeEvent("1", "one").get();
    // Close one segment open 3.
    channelCount += 2;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    ReaderGroup readerGroup = groupManager.getReaderGroup(READER_GROUP);
    readerGroup.getMetrics().unreadBytes();
    CompletableFuture<Checkpoint> future = readerGroup.initiateCheckpoint("cp1", executor);
    // 3 more from the state synchronizer
    channelCount += 4;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    event = reader1.readNextEvent(5000);
    assertEquals("cp1", event.getCheckpointName());
    event = reader1.readNextEvent(10000);
    assertEquals("one", event.getEvent());
    // From new segments on reader
    channelCount += 3;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    future.join();
    // Checkpoint should close connections back down
    readerGroup.close();
    channelCount -= 4;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    // Write more events.
    writer.writeEvent("2", "two").get();
    writer.writeEvent("3", "three").get();
    writer.writeEvent("4", "four").get();
    // no changes to socket count.
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    event = reader1.readNextEvent(10000);
    assertNotNull(event.getEvent());
    // no changes to socket count.
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    reader1.close();
    // 3 from segments 4 from group state.
    channelCount -= 7;
    assertChannelCount(channelCount, connectionPool, connectionFactory);
    groupManager.close();
    writer.close();
    assertChannelCount(0, connectionPool, connectionFactory);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ReaderGroup(io.pravega.client.stream.ReaderGroup) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) Checkpoint(io.pravega.client.stream.Checkpoint) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Checkpoint(io.pravega.client.stream.Checkpoint) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Test(org.junit.Test)

Aggregations

SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)90 Cleanup (lombok.Cleanup)63 Test (org.junit.Test)60 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)54 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)51 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)49 ClientConfig (io.pravega.client.ClientConfig)48 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)43 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)38 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)34 Controller (io.pravega.client.control.impl.Controller)31 Stream (io.pravega.client.stream.Stream)27 HashMap (java.util.HashMap)23 Before (org.junit.Before)23 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)21 StreamImpl (io.pravega.client.stream.impl.StreamImpl)21 LocalController (io.pravega.controller.server.eventProcessor.LocalController)20 StreamManager (io.pravega.client.admin.StreamManager)19 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)19 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)19