Search in sources :

Example 11 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.

the class CheckpointTest method testCheckpointAndRestore.

@Test(timeout = 20000)
public void testCheckpointAndRestore() throws ReinitializationRequiredException, InterruptedException, ExecutionException, TimeoutException {
    String endpoint = "localhost";
    String streamName = "abc";
    String readerName = "reader";
    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().disableAutomaticCheckpoints().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> reader = clientFactory.createReader(readerName, readerGroupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    EventRead<String> read = reader.readNextEvent(60000);
    assertEquals(testString, read.getEvent());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    read = reader.readNextEvent(60000);
    assertEquals(testString, read.getEvent());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    @Cleanup("shutdown") final InlineExecutor backgroundExecutor = new InlineExecutor();
    CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("Checkpoint", backgroundExecutor);
    assertFalse(checkpoint.isDone());
    read = reader.readNextEvent(60000);
    assertTrue(read.isCheckpoint());
    assertEquals("Checkpoint", read.getCheckpointName());
    assertNull(read.getEvent());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    read = reader.readNextEvent(60000);
    assertEquals(testString, read.getEvent());
    Checkpoint cpResult = checkpoint.get(5, TimeUnit.SECONDS);
    assertTrue(checkpoint.isDone());
    assertEquals("Checkpoint", cpResult.getName());
    read = reader.readNextEvent(100);
    assertNull(read.getEvent());
    assertFalse(read.isCheckpoint());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(cpResult).build());
    try {
        reader.readNextEvent(60000);
        fail();
    } catch (ReinitializationRequiredException e) {
    // Expected
    }
    reader.close();
    reader = clientFactory.createReader(readerName, readerGroupName, serializer, ReaderConfig.builder().build());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    read = reader.readNextEvent(60000);
    assertEquals(testString, read.getEvent());
    clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
    read = reader.readNextEvent(100);
    assertNull(read.getEvent());
    assertFalse(read.isCheckpoint());
}
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) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 12 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.

the class StartReader method main.

public static void main(String[] args) throws Exception {
    @Cleanup MockStreamManager streamManager = new MockStreamManager(StartLocalService.SCOPE, InetAddress.getLocalHost().getHostAddress(), StartLocalService.SERVICE_PORT);
    streamManager.createScope(StartLocalService.SCOPE);
    streamManager.createStream(StartLocalService.SCOPE, StartLocalService.STREAM_NAME, null);
    streamManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(StartLocalService.SCOPE, StartLocalService.STREAM_NAME)).build());
    EventStreamReader<String> reader = streamManager.getClientFactory().createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
    for (int i = 0; i < 20; i++) {
        String event = reader.readNextEvent(60000).getEvent();
        System.err.println("Read event: " + event);
    }
    reader.close();
    System.exit(0);
}
Also used : MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup)

Example 13 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.

the class StartWriter method main.

public static void main(String[] args) throws Exception {
    @Cleanup MockStreamManager streamManager = new MockStreamManager(StartLocalService.SCOPE, InetAddress.getLocalHost().getHostAddress(), StartLocalService.SERVICE_PORT);
    streamManager.createScope(StartLocalService.SCOPE);
    streamManager.createStream(StartLocalService.SCOPE, StartLocalService.STREAM_NAME, null);
    MockClientFactory clientFactory = streamManager.getClientFactory();
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(StartLocalService.STREAM_NAME, new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutTime(60000).transactionTimeoutScaleGracePeriod(60000).build());
    Transaction<String> transaction = writer.beginTxn();
    for (int i = 0; i < 10; i++) {
        String event = "\n Transactional write \n";
        System.err.println("Writing event: " + event);
        transaction.writeEvent(event);
        transaction.flush();
        Thread.sleep(500);
    }
    for (int i = 0; i < 10; i++) {
        String event = "\n Non-transactional Publish \n";
        System.err.println("Writing event: " + event);
        writer.writeEvent(event);
        writer.flush();
        Thread.sleep(500);
    }
    transaction.commit();
    System.exit(0);
}
Also used : MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory)

Example 14 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager in project pravega by pravega.

the class AppendTest method miniBenchmark.

@Test(timeout = 40000)
public void miniBenchmark() 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());
    long blockingTime = timeWrites(testString, 200, producer, true);
    long nonBlockingTime = timeWrites(testString, 1000, producer, false);
    System.out.println("Blocking took: " + blockingTime + "ms.");
    System.out.println("Non blocking took: " + nonBlockingTime + "ms.");
    assertTrue(blockingTime < 15000);
    assertTrue(nonBlockingTime < 15000);
}
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 15 with MockStreamManager

use of io.pravega.client.stream.mock.MockStreamManager 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)

Aggregations

MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)22 Cleanup (lombok.Cleanup)21 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)20 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)19 Test (org.junit.Test)17 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)16 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)9 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)7 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Checkpoint (io.pravega.client.stream.Checkpoint)2 ReaderGroup (io.pravega.client.stream.ReaderGroup)2 InlineExecutor (io.pravega.test.common.InlineExecutor)2 Serializable (java.io.Serializable)2 NoSuchEventException (io.pravega.client.segment.impl.NoSuchEventException)1 EventPointer (io.pravega.client.stream.EventPointer)1 ReinitializationRequiredException (io.pravega.client.stream.ReinitializationRequiredException)1 IntegerSerializer (io.pravega.test.integration.utils.IntegerSerializer)1 TreeSet (java.util.TreeSet)1 lombok.val (lombok.val)1