use of io.pravega.client.stream.mock.MockSegmentStreamFactory 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.mock.MockSegmentStreamFactory 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.mock.MockSegmentStreamFactory 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.mock.MockSegmentStreamFactory in project pravega by pravega.
the class RevisionedStreamClientTest method testCreateRevisionedStreamClientError.
@Test
public void testCreateRevisionedStreamClientError() {
String scope = "scope";
String stream = "stream";
JavaSerializer<Serializable> serializer = new JavaSerializer<>();
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
Controller controller = Mockito.mock(Controller.class);
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
@Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
SynchronizerConfig config = SynchronizerConfig.builder().build();
// Simulate sealed stream.
CompletableFuture<StreamSegments> result = new CompletableFuture<>();
result.complete(new StreamSegments(new TreeMap<>()));
when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
// Simulate invalid stream.
result = new CompletableFuture<>();
result.completeExceptionally(new RuntimeException());
when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
// Simulate null result from Controller.
result = new CompletableFuture<>();
result.complete(null);
when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
}
use of io.pravega.client.stream.mock.MockSegmentStreamFactory in project pravega by pravega.
the class RevisionedStreamClientTest method testMark.
@Test
public void testMark() {
String scope = "scope";
String stream = "stream";
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
createScopeAndStream(scope, stream, controller);
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
@Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
SynchronizerConfig config = SynchronizerConfig.builder().build();
@Cleanup RevisionedStreamClient<String> client = clientFactory.createRevisionedStreamClient(stream, new JavaSerializer<>(), config);
client.writeUnconditionally("a");
Revision ra = client.fetchLatestRevision();
client.writeUnconditionally("b");
Revision rb = client.fetchLatestRevision();
client.writeUnconditionally("c");
Revision rc = client.fetchLatestRevision();
assertTrue(client.compareAndSetMark(null, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, rb));
assertEquals(rb, client.getMark());
assertFalse(client.compareAndSetMark(ra, rc));
assertEquals(rb, client.getMark());
assertTrue(client.compareAndSetMark(rb, rc));
assertEquals(rc, client.getMark());
assertTrue(client.compareAndSetMark(rc, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, null));
assertEquals(null, client.getMark());
}
Aggregations