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());
}
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.
}
}
Aggregations