Search in sources :

Example 21 with Segment

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());
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) Test(org.junit.Test)

Example 22 with Segment

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());
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) Test(org.junit.Test)

Example 23 with Segment

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());
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) Test(org.junit.Test)

Example 24 with Segment

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();
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 25 with Segment

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);
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

Segment (io.pravega.client.segment.impl.Segment)97 Test (org.junit.Test)63 Cleanup (lombok.Cleanup)35 HashMap (java.util.HashMap)27 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)22 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)19 AtomicLong (java.util.concurrent.atomic.AtomicLong)19 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)17 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)16 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)16 MockController (io.pravega.client.stream.mock.MockController)15 ClientFactory (io.pravega.client.ClientFactory)13 Stream (io.pravega.client.stream.Stream)13 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)13 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)12 InlineExecutor (io.pravega.test.common.InlineExecutor)12 TreeMap (java.util.TreeMap)10 lombok.val (lombok.val)10 StreamCut (io.pravega.client.stream.StreamCut)8 ByteBuffer (java.nio.ByteBuffer)8