use of io.pravega.client.segment.impl.Segment 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, "");
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, "");
long length = metadataClient.getSegmentInfo().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.segment.impl.Segment 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, "");
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, "");
long length = metadataClient.getSegmentInfo().getWriteOffset();
@Cleanup SegmentIteratorImpl<String> iter = new SegmentIteratorImpl<>(factory, segment, stringSerializer, 0, length);
assertEquals("1", iter.next());
long segmentLength = metadataClient.fetchCurrentSegmentLength();
assertEquals(0, segmentLength % 3);
metadataClient.truncateSegment(segment, segmentLength * 2 / 3);
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.segment.impl.Segment 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, "");
sendData("1", outputStream);
sendData("2", outputStream);
sendData("3", outputStream);
SegmentMetadataClient metadataClient = factory.createSegmentMetadataClient(segment, "");
long length = metadataClient.getSegmentInfo().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.segment.impl.Segment in project pravega by pravega.
the class RawClientTest method testHello.
@Test
public void testHello() throws ConnectionFailedException {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
Mockito.verify(connection).send(new WireCommands.Hello(0, 0));
rawClient.close();
Mockito.verify(connection).close();
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsAtTime.
@Test
public void testGetSegmentsAtTime() throws Exception {
CompletableFuture<Map<Segment, Long>> positions;
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream1"), 0);
assertEquals(2, positions.get().size());
assertEquals(10, positions.get().get(new Segment("scope1", "stream1", 0)).longValue());
assertEquals(20, positions.get().get(new Segment("scope1", "stream1", 1)).longValue());
positions = controllerClient.getSegmentsAtTime(new StreamImpl("scope1", "stream2"), 0);
AssertExtensions.assertThrows("Should throw Exception", positions, throwable -> true);
}
Aggregations