Search in sources :

Example 56 with EventWriterConfig

use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.

the class EndToEndTruncationTest method testWriteOnSealedStream.

@Test(timeout = 50000)
public void testWriteOnSealedStream() throws Exception {
    JavaSerializer<String> serializer = new JavaSerializer<>();
    EventWriterConfig writerConfig = EventWriterConfig.builder().build();
    String scope = "testSeal";
    String streamName = "testWriteOnSealedStream";
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 2)).build();
    LocalController controller = (LocalController) PRAVEGA.getLocalController();
    controller.createScope(scope).get();
    controller.createStream(scope, streamName, config).get();
    config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
    controller.updateStream(scope, streamName, config).get();
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, writerConfig);
    // write an event.
    writer.writeEvent("0", "data").get();
    // Seal Stream.
    assertTrue(controller.sealStream(scope, streamName).get());
    // Write by an existing writer to a sealed stream should complete exceptionally.
    assertFutureThrows("Should throw IllegalStateException", writer.writeEvent("2", "Write to sealed stream"), e -> IllegalStateException.class.isAssignableFrom(e.getClass()));
    // Subsequent writes will throw an exception.
    assertThrows(IllegalStateException.class, () -> writer.writeEvent("testEvent"));
    // Creating a writer against a sealed stream throws an exception.
    assertThrows(IllegalStateException.class, () -> clientFactory.createEventWriter(streamName, serializer, writerConfig));
}
Also used : ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) LocalController(io.pravega.controller.server.eventProcessor.LocalController) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 57 with EventWriterConfig

use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.

the class ByteStreanWriterImplTest method setup.

@Before
public void setup() {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    connectionFactory = new MockConnectionFactoryImpl();
    ClientConnection connection = mock(ClientConnection.class);
    connectionFactory.provideConnection(endpoint, connection);
    controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
    controller.createScope(SCOPE);
    controller.createStream(SCOPE, STREAM, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
    MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
    StreamSegments segments = Futures.getThrowingException(controller.getCurrentSegments(SCOPE, STREAM));
    Preconditions.checkState(segments.getNumberOfSegments() > 0, "Stream is sealed");
    Preconditions.checkState(segments.getNumberOfSegments() == 1, "Stream is configured with more than one segment");
    Segment segment = segments.getSegments().iterator().next();
    EventWriterConfig config = EventWriterConfig.builder().retryAttempts(Integer.MAX_VALUE).build();
    DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controller, segment, AccessOperation.WRITE);
    mockWriter = new ByteStreamWriterImpl(streamFactory.createOutputStreamForSegment(segment, config, tokenProvider), streamFactory.createSegmentMetadataClient(segment, tokenProvider));
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Segment(io.pravega.client.segment.impl.Segment) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) Before(org.junit.Before)

Example 58 with EventWriterConfig

use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.

the class ByteStreamClientImpl method createByteStreamWriter.

@Override
public ByteStreamWriter createByteStreamWriter(String streamName) {
    StreamSegments segments = Futures.getThrowingException(controller.getCurrentSegments(scope, streamName));
    Preconditions.checkState(segments.getNumberOfSegments() > 0, "Stream is sealed");
    Preconditions.checkState(segments.getNumberOfSegments() == 1, "Stream is configured with more than one segment");
    Segment segment = segments.getSegments().iterator().next();
    // The writer should not give up connecting to SegmentStore in the background until the ByteStreamWriter is closed.
    EventWriterConfig config = EventWriterConfig.builder().retryAttempts(Integer.MAX_VALUE).build();
    DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controller, segment, AccessOperation.WRITE);
    return new BufferedByteStreamWriterImpl(new ByteStreamWriterImpl(outputStreamFactory.createOutputStreamForSegment(segment, config, tokenProvider), metaStreamFactory.createSegmentMetadataClient(segment, tokenProvider)));
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Segment(io.pravega.client.segment.impl.Segment) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider)

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