Search in sources :

Example 16 with EventWriterConfig

use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.

the class EventStreamWriterTest method testTxn.

@Test
public void testTxn() throws TxnFailedException {
    String scope = "scope";
    String streamName = "stream";
    StreamImpl stream = new StreamImpl(scope, streamName);
    Segment segment = new Segment(scope, streamName, 0);
    UUID txid = UUID.randomUUID();
    EventWriterConfig config = EventWriterConfig.builder().transactionTimeoutTime(0).transactionTimeoutScaleGracePeriod(0).build();
    SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
    Controller controller = Mockito.mock(Controller.class);
    Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment));
    FakeSegmentOutputStream outputStream = new FakeSegmentOutputStream(segment);
    FakeSegmentOutputStream bad = new FakeSegmentOutputStream(segment);
    Mockito.when(controller.createTransaction(stream, 0, 0)).thenReturn(CompletableFuture.completedFuture(new TxnSegments(getSegments(segment), txid)));
    Mockito.when(streamFactory.createOutputStreamForTransaction(eq(segment), eq(txid), any(), any(), any())).thenReturn(outputStream);
    Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(bad);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    @Cleanup EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, serializer, config, new InlineExecutor());
    Transaction<String> txn = writer.beginTxn();
    txn.writeEvent("Foo");
    Mockito.verify(controller).getCurrentSegments(any(), any());
    assertTrue(bad.getUnackedEventsOnSeal().isEmpty());
    assertEquals(1, outputStream.getUnackedEventsOnSeal().size());
    outputStream.getUnackedEventsOnSeal().get(0).getAckFuture().complete(true);
    txn.flush();
    assertTrue(bad.getUnackedEventsOnSeal().isEmpty());
    assertTrue(outputStream.getUnackedEventsOnSeal().isEmpty());
}
Also used : Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) InlineExecutor(io.pravega.test.common.InlineExecutor) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with EventWriterConfig

use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.

the class EventStreamWriterTest method testWrite.

@Test
public void testWrite() {
    String scope = "scope";
    String streamName = "stream";
    StreamImpl stream = new StreamImpl(scope, streamName);
    Segment segment = new Segment(scope, streamName, 0);
    EventWriterConfig config = EventWriterConfig.builder().build();
    SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
    Controller controller = Mockito.mock(Controller.class);
    Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment));
    MockSegmentIoStreams outputStream = new MockSegmentIoStreams(segment);
    Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(outputStream);
    EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, new JavaSerializer<>(), config, new InlineExecutor());
    writer.writeEvent("Foo");
    writer.writeEvent("Bar");
    writer.close();
    try {
        writer.writeEvent("fail");
        fail();
    } catch (IllegalStateException e) {
    // expected.
    }
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) InlineExecutor(io.pravega.test.common.InlineExecutor) MockSegmentIoStreams(io.pravega.client.stream.mock.MockSegmentIoStreams) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

EventWriterConfig (io.pravega.client.stream.EventWriterConfig)17 Test (org.junit.Test)16 Segment (io.pravega.client.segment.impl.Segment)15 Cleanup (lombok.Cleanup)14 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)12 InlineExecutor (io.pravega.test.common.InlineExecutor)12 MockSegmentIoStreams (io.pravega.client.stream.mock.MockSegmentIoStreams)5 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)4 SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)3 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)3 UUID (java.util.UUID)3 ClientConfig (io.pravega.client.ClientConfig)1 ClientFactory (io.pravega.client.ClientFactory)1 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)1 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)1 EventStreamReader (io.pravega.client.stream.EventStreamReader)1 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)1 ReaderConfig (io.pravega.client.stream.ReaderConfig)1