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));
}
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));
}
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)));
}
Aggregations