use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class EventStreamWriterTest method testTxnFailed.
@Test
public void testTxnFailed() {
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();
outputStream.invokeSealedCallBack();
try {
txn.writeEvent("Foo");
} catch (TxnFailedException e) {
// Expected
}
Mockito.verify(controller).getCurrentSegments(any(), any());
assertTrue(bad.getUnackedEventsOnSeal().isEmpty());
assertEquals(1, outputStream.getUnackedEventsOnSeal().size());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentIteratorTest method testTruncate.
@Test(timeout = 5000)
public void testTruncate() {
MockSegmentStreamFactory factory = new MockSegmentStreamFactory();
Segment segment = new Segment("Scope", "Stream", 1);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStream outputStream = factory.createOutputStreamForSegment(segment, c -> {
}, config, DelegationTokenProviderFactory.createWithEmptyToken());
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
@Cleanup SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
long length = metadataClient.getSegmentInfo().join().getWriteOffset();
@Cleanup SegmentIteratorImpl<String> iter = new SegmentIteratorImpl<>(factory, segment, stringSerializer, 0, length);
assertEquals("1", iter.next());
long segmentLength = metadataClient.fetchCurrentSegmentLength().join();
assertEquals(0, segmentLength % 3);
metadataClient.truncateSegment(segmentLength * 2 / 3).join();
AssertExtensions.assertThrows(TruncatedDataException.class, () -> iter.next());
@Cleanup SegmentIteratorImpl<String> iter2 = new SegmentIteratorImpl<>(factory, segment, stringSerializer, segmentLength * 2 / 3, length);
assertTrue(iter2.hasNext());
assertEquals("3", iter2.next());
assertFalse(iter.hasNext());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentIteratorTest method testOffset.
@Test(timeout = 5000)
public void testOffset() {
MockSegmentStreamFactory factory = new MockSegmentStreamFactory();
Segment segment = new Segment("Scope", "Stream", 1);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStream outputStream = factory.createOutputStreamForSegment(segment, c -> {
}, config, DelegationTokenProviderFactory.createWithEmptyToken());
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
@Cleanup SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
long length = metadataClient.getSegmentInfo().join().getWriteOffset();
@Cleanup SegmentIteratorImpl<String> iter = new SegmentIteratorImpl<>(factory, segment, stringSerializer, 0, length);
assertEquals(0, iter.getOffset());
assertEquals("1", iter.next());
assertEquals(length / 3, iter.getOffset());
assertEquals("2", iter.next());
assertEquals(length / 3 * 2, iter.getOffset());
assertTrue(iter.hasNext());
assertEquals(length / 3 * 2, iter.getOffset());
assertEquals("3", iter.next());
assertEquals(length, iter.getOffset());
assertThrows(NoSuchElementException.class, () -> iter.next());
assertFalse(iter.hasNext());
assertEquals(length, iter.getOffset());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentIteratorTest method testHasNext.
@Test(timeout = 5000)
public void testHasNext() {
MockSegmentStreamFactory factory = new MockSegmentStreamFactory();
Segment segment = new Segment("Scope", "Stream", 1);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStream outputStream = factory.createOutputStreamForSegment(segment, c -> {
}, config, DelegationTokenProviderFactory.createWithEmptyToken());
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
@Cleanup SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
long length = metadataClient.getSegmentInfo().join().getWriteOffset();
@Cleanup SegmentIteratorImpl<String> iter = new SegmentIteratorImpl<>(factory, segment, stringSerializer, 0, length);
assertTrue(iter.hasNext());
assertTrue(iter.hasNext());
assertEquals("1", iter.next());
assertEquals("2", iter.next());
assertTrue(iter.hasNext());
assertEquals("3", iter.next());
assertFalse(iter.hasNext());
assertThrows(NoSuchElementException.class, () -> iter.next());
assertFalse(iter.hasNext());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentOutputStreamFactoryTest method createOutputStreamForTransaction.
@Test
public void createOutputStreamForTransaction() {
EventWriterConfig writerConfig = EventWriterConfig.builder().build();
SegmentOutputStreamImpl segWriter = (SegmentOutputStreamImpl) factory.createOutputStreamForTransaction(segment, txId, writerConfig, DelegationTokenProviderFactory.createWithEmptyToken());
assertTrue(isTransactionSegment(segWriter.getSegmentName()));
assertEquals(writerConfig.isEnableConnectionPooling(), segWriter.isUseConnectionPooling());
}
Aggregations