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 SynchronizerConfigTest method testValidValues.
@Test
public void testValidValues() throws IOException, ClassNotFoundException {
EventWriterConfig eventConfig = EventWriterConfig.builder().automaticallyNoteTime(true).backoffMultiple(2).enableConnectionPooling(false).initialBackoffMillis(100).maxBackoffMillis(1000).retryAttempts(3).transactionTimeoutTime(100000).build();
SynchronizerConfig synchConfig = SynchronizerConfig.builder().readBufferSize(1024).eventWriterConfig(eventConfig).build();
SynchronizerConfig.SynchronizerConfigSerializer serializer = new SynchronizerConfig.SynchronizerConfigSerializer();
ByteArraySegment buff = serializer.serialize(synchConfig);
SynchronizerConfig result1 = serializer.deserialize(buff);
ByteBuffer buffer = synchConfig.toBytes();
SynchronizerConfig result2 = SynchronizerConfig.fromBytes(buffer);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
@Cleanup ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(synchConfig);
byte[] byteArray = bout.toByteArray();
ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(byteArray));
Object revision = oin.readObject();
assertEquals(synchConfig, revision);
assertEquals(true, result1.getEventWriterConfig().isAutomaticallyNoteTime());
assertEquals(2, result1.getEventWriterConfig().getBackoffMultiple());
assertEquals(false, result1.getEventWriterConfig().isEnableConnectionPooling());
assertEquals(100, result1.getEventWriterConfig().getInitialBackoffMillis());
assertEquals(1000, result1.getEventWriterConfig().getMaxBackoffMillis());
assertEquals(3, result1.getEventWriterConfig().getRetryAttempts());
assertEquals(100000, result1.getEventWriterConfig().getTransactionTimeoutTime());
assertEquals(1024, result1.getReadBufferSize());
assertEquals(true, result2.getEventWriterConfig().isAutomaticallyNoteTime());
assertEquals(2, result2.getEventWriterConfig().getBackoffMultiple());
assertEquals(false, result2.getEventWriterConfig().isEnableConnectionPooling());
assertEquals(100, result2.getEventWriterConfig().getInitialBackoffMillis());
assertEquals(1000, result2.getEventWriterConfig().getMaxBackoffMillis());
assertEquals(3, result2.getEventWriterConfig().getRetryAttempts());
assertEquals(100000, result2.getEventWriterConfig().getTransactionTimeoutTime());
assertEquals(1024, result2.getReadBufferSize());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentOutputStreamFactoryTest method createOutputStreamForSegment.
@Test
public void createOutputStreamForSegment() {
EventWriterConfig writerConfig = EventWriterConfig.builder().enableConnectionPooling(false).build();
SegmentOutputStreamImpl segWriter = (SegmentOutputStreamImpl) factory.createOutputStreamForSegment(segment, writerConfig, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals(segment.getScopedName(), segWriter.getSegmentName());
assertEquals(writerConfig.isEnableConnectionPooling(), segWriter.isUseConnectionPooling());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class SegmentOutputStreamFactoryTest method createOutputStreamForSegmentAndconnect.
@Test
public void createOutputStreamForSegmentAndconnect() {
EventWriterConfig writerConfig = EventWriterConfig.builder().enableConnectionPooling(false).build();
SegmentOutputStreamImpl segWriter = (SegmentOutputStreamImpl) factory.createOutputStreamForSegment(segment, s -> {
}, writerConfig, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals(segment.getScopedName(), segWriter.getSegmentName());
assertEquals(writerConfig.isEnableConnectionPooling(), segWriter.isUseConnectionPooling());
}
use of io.pravega.client.stream.EventWriterConfig in project pravega by pravega.
the class EndToEndStatsTest method testStatsCount.
@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testStatsCount() throws Exception {
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
Controller controller = controllerWrapper.getController();
controllerWrapper.getControllerService().createScope("test", 0L).get();
controller.createStream("test", "test", config).get();
@Cleanup EventStreamClientFactory clientFactory = new ClientFactoryImpl("test", controller, ClientConfig.builder().build());
EventWriterConfig writerConfig = EventWriterConfig.builder().transactionTimeoutTime(10000).build();
@Cleanup EventStreamWriter<String> eventWriter = clientFactory.createEventWriter("test", new JavaSerializer<>(), writerConfig);
@Cleanup TransactionalEventStreamWriter<String> txnWriter = clientFactory.createTransactionalEventWriter("test", new JavaSerializer<>(), writerConfig);
String[] tags = segmentTags(NameUtils.getQualifiedStreamSegmentName("test", "test", 0L));
for (int i = 0; i < 10; i++) {
eventWriter.writeEvent("test").get();
}
assertEventuallyEquals(10, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_EVENTS, tags).count()), 2000);
assertEventuallyEquals(190, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_BYTES, tags).count()), 100);
Transaction<String> transaction = txnWriter.beginTxn();
for (int i = 0; i < 10; i++) {
transaction.writeEvent("0", "txntest1");
}
assertEventuallyEquals(10, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_EVENTS, tags).count()), 2000);
assertEventuallyEquals(190, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_BYTES, tags).count()), 100);
transaction.commit();
assertEventuallyEquals(20, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_EVENTS, tags).count()), 10000);
assertEventuallyEquals(420, () -> (int) (statsRecorder.getRegistry().counter(SEGMENT_WRITE_BYTES, tags).count()), 100);
}
Aggregations