Search in sources :

Example 1 with EventWriterConfig

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());
}
Also used : Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) InlineExecutor(io.pravega.test.common.InlineExecutor) TxnFailedException(io.pravega.client.stream.TxnFailedException) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with EventWriterConfig

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());
}
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 3 with EventWriterConfig

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());
}
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 4 with EventWriterConfig

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());
}
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 5 with EventWriterConfig

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());
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Test(org.junit.Test)

Aggregations

EventWriterConfig (io.pravega.client.stream.EventWriterConfig)58 Test (org.junit.Test)51 Cleanup (lombok.Cleanup)46 Segment (io.pravega.client.segment.impl.Segment)39 Controller (io.pravega.client.control.impl.Controller)33 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)30 UUID (java.util.UUID)14 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)11 FakeSegmentOutputStream (io.pravega.client.stream.impl.EventStreamWriterTest.FakeSegmentOutputStream)7 MockSegmentIoStreams (io.pravega.client.stream.mock.MockSegmentIoStreams)7 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 ClientConnection (io.pravega.client.connection.impl.ClientConnection)5 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)5 MockController (io.pravega.client.stream.mock.MockController)5 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)5 CreateTransientSegment (io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ByteBuf (io.netty.buffer.ByteBuf)4 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)4