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 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 LargeEventWriter method writeLargeEvent.
/**
* Write the provided list of events (atomically) to the provided segment.
*
* @param segment The segment to write to
* @param events The events to append
* @param tokenProvider A token provider
* @param config Used for retry configuration parameters
* @throws NoSuchSegmentException If the provided segment does not exit.
* @throws SegmentSealedException If the segment is sealed.
* @throws AuthenticationException If the token can't be used for this segment.
* @throws UnsupportedOperationException If the server does not support large events.
*/
public void writeLargeEvent(Segment segment, List<ByteBuffer> events, DelegationTokenProvider tokenProvider, EventWriterConfig config) throws NoSuchSegmentException, AuthenticationException, SegmentSealedException {
List<ByteBuf> payloads = createBufs(events);
int attempts = 1 + Math.max(0, config.getRetryAttempts());
Retry.withExpBackoff(config.getInitialBackoffMillis(), config.getBackoffMultiple(), attempts, config.getMaxBackoffMillis()).retryWhen(t -> {
Throwable ex = Exceptions.unwrap(t);
if (ex instanceof ConnectionFailedException) {
log.info("Connection failure while sending large event: {}. Retrying", ex.getMessage());
return true;
} else if (ex instanceof TokenExpiredException) {
tokenProvider.signalTokenExpired();
log.info("Authentication token expired while writing large event to segment {}. Retrying", segment);
return true;
} else {
return false;
}
}).run(() -> {
@Cleanup RawClient client = new RawClient(controller, connectionPool, segment);
write(segment, payloads, client, tokenProvider);
return null;
});
}
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