Search in sources :

Example 31 with PravegaConnectionListener

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

the class AppendTest method appendThroughStreamingClient.

@Test
public void appendThroughStreamingClient() throws InterruptedException, ExecutionException, TimeoutException {
    String endpoint = "localhost";
    String streamName = "abc";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world\n";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
    server.startListening();
    @Cleanup MockStreamManager streamManager = new MockStreamManager("Scope", endpoint, port);
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    streamManager.createScope("Scope");
    streamManager.createStream("Scope", streamName, null);
    @Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
    Future<Void> ack = producer.writeEvent(testString);
    ack.get(5, TimeUnit.SECONDS);
}
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) Test(org.junit.Test)

Example 32 with PravegaConnectionListener

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

the class AutoCheckpointTest method testCheckpointsOccur.

@Test(timeout = 30000)
public void testCheckpointsOccur() throws ReinitializationRequiredException, DurableDataLogException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerName = "reader";
    String readerGroup = "group";
    int port = TestUtils.getAvailableListenPort();
    String testString = "Hello world: ";
    String scope = "Scope1";
    @Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = 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().automaticCheckpointIntervalMillis(10000).stream(Stream.of(scope, streamName)).build();
    streamManager.createScope(scope);
    streamManager.createStream(scope, streamName, null);
    streamManager.createReaderGroup(readerGroup, groupConfig);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    populateEvents(streamName, testString, clientFactory, serializer);
    AtomicLong fakeClock = new AtomicLong(0);
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build(), () -> fakeClock.get(), () -> fakeClock.get() / NANOS_PER_SECOND);
    int numRead = 0;
    int checkpointCount = 0;
    while (numRead < 100) {
        fakeClock.addAndGet(NANOS_PER_SECOND);
        EventRead<String> event = reader.readNextEvent(1000);
        if (event.isCheckpoint()) {
            checkpointCount++;
        } else {
            String message = event.getEvent();
            assertEquals(testString + numRead, message);
            numRead++;
        }
    }
    assertTrue("Count was " + checkpointCount, checkpointCount > 5);
    assertTrue("Count was " + checkpointCount, checkpointCount < 20);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) 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) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 33 with PravegaConnectionListener

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

the class CheckpointTest method testMoreReadersThanSegments.

@Test(timeout = 20000)
public void testMoreReadersThanSegments() throws ReinitializationRequiredException, InterruptedException, ExecutionException, TimeoutException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerGroupName = "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, StreamConfiguration.builder().scope(scope).streamName(streamName).scalingPolicy(ScalingPolicy.fixed(1)).build());
    ReaderGroup readerGroup = streamManager.createReaderGroup(readerGroupName, groupConfig);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
    producer.writeEvent(testString);
    producer.writeEvent(testString);
    producer.writeEvent(testString);
    producer.flush();
    AtomicLong clock = new AtomicLong();
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("reader1", readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
    @Cleanup EventStreamReader<String> reader2 = clientFactory.createReader("reader2", readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    @Cleanup("shutdown") final InlineExecutor backgroundExecutor = new InlineExecutor();
    CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("Checkpoint", backgroundExecutor);
    assertFalse(checkpoint.isDone());
    EventRead<String> read = reader1.readNextEvent(60000);
    assertTrue(read.isCheckpoint());
    assertEquals("Checkpoint", read.getCheckpointName());
    assertNull(read.getEvent());
    read = reader2.readNextEvent(60000);
    assertTrue(read.isCheckpoint());
    assertEquals("Checkpoint", read.getCheckpointName());
    assertNull(read.getEvent());
    Checkpoint cpResult = checkpoint.get(5, TimeUnit.SECONDS);
    assertTrue(checkpoint.isDone());
    assertEquals("Checkpoint", cpResult.getName());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ReaderGroup(io.pravega.client.stream.ReaderGroup) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Checkpoint(io.pravega.client.stream.Checkpoint) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) Checkpoint(io.pravega.client.stream.Checkpoint) InlineExecutor(io.pravega.test.common.InlineExecutor) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 34 with PravegaConnectionListener

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

the class ControllerBootstrapTest method bootstrapTest.

@Test(timeout = 20000)
public void bootstrapTest() throws Exception {
    Controller controller = controllerWrapper.getController();
    // 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().scope(SCOPE).streamName(STREAM).scalingPolicy(ScalingPolicy.fixed(1)).build();
    CompletableFuture<Boolean> streamStatus = controller.createStream(streamConfiguration);
    Assert.assertTrue(!streamStatus.isDone());
    // Create transaction should fail.
    CompletableFuture<TxnSegments> txIdFuture = controller.createTransaction(new StreamImpl(SCOPE, STREAM), 10000, 30000);
    try {
        txIdFuture.join();
        Assert.fail();
    } catch (CompletionException ce) {
        Assert.assertEquals(IllegalStateException.class, ce.getCause().getClass());
        Assert.assertTrue("Expected failure", true);
    }
    // Now start Pravega service.
    ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    server = new PravegaConnectionListener(false, servicePort, store);
    server.startListening();
    // Ensure that create stream succeeds.
    try {
        Boolean status = streamStatus.join();
        Assert.assertEquals(true, status);
    } catch (CompletionException ce) {
        Assert.fail();
    }
    // Sleep for a while for initialize to complete
    boolean initialized = controllerWrapper.awaitTasksModuleInitialization(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(initialized);
    // Now create transaction should succeed.
    txIdFuture = controller.createTransaction(new StreamImpl(SCOPE, STREAM), 10000, 30000);
    try {
        TxnSegments id = txIdFuture.join();
        Assert.assertNotNull(id);
    } catch (CompletionException ce) {
        Assert.fail();
    }
    controllerWrapper.awaitRunning();
}
Also used : TxnSegments(io.pravega.client.stream.impl.TxnSegments) Controller(io.pravega.client.stream.impl.Controller) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) StreamImpl(io.pravega.client.stream.impl.StreamImpl) CompletionException(java.util.concurrent.CompletionException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 35 with PravegaConnectionListener

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

the class ControllerFailoverTest method setup.

@Before
public void setup() throws Exception {
    // 1. Start ZK
    zkTestServer = new TestingServerStarter().start();
    // 2. Start Pravega SSS
    ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    server = new PravegaConnectionListener(false, servicePort, store);
    server.startListening();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Before(org.junit.Before)

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