Search in sources :

Example 51 with EventWriterConfig

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

Example 52 with EventWriterConfig

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());
}
Also used : EventWriterConfig(io.pravega.client.stream.EventWriterConfig) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NameUtils.isTransactionSegment(io.pravega.shared.NameUtils.isTransactionSegment) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Controller(io.pravega.client.control.impl.Controller) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Test(org.junit.Test)

Example 53 with EventWriterConfig

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());
}
Also used : ByteArraySegment(io.pravega.common.util.ByteArraySegment) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteBuffer(java.nio.ByteBuffer) Cleanup(lombok.Cleanup) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 54 with EventWriterConfig

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;
    });
}
Also used : Segment(io.pravega.client.segment.impl.Segment) TokenExpiredException(io.pravega.auth.TokenExpiredException) Retry(io.pravega.common.util.Retry) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) ConditionalCheckFailed(io.pravega.shared.protocol.netty.WireCommands.ConditionalCheckFailed) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentSealedException(io.pravega.client.segment.impl.SegmentSealedException) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) ArrayList(java.util.ArrayList) RawClient(io.pravega.client.connection.impl.RawClient) ConditionalBlockEnd(io.pravega.shared.protocol.netty.WireCommands.ConditionalBlockEnd) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) ByteBuf(io.netty.buffer.ByteBuf) AuthTokenCheckFailed(io.pravega.shared.protocol.netty.WireCommands.AuthTokenCheckFailed) MergeSegments(io.pravega.shared.protocol.netty.WireCommands.MergeSegments) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) Futures.getThrowingException(io.pravega.common.concurrent.Futures.getThrowingException) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Nonnull(javax.annotation.Nonnull) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Serializer(io.pravega.client.stream.Serializer) SegmentsMerged(io.pravega.shared.protocol.netty.WireCommands.SegmentsMerged) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) NoSuchSegmentException(io.pravega.client.segment.impl.NoSuchSegmentException) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) lombok.val(lombok.val) AuthenticationException(io.pravega.auth.AuthenticationException) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) InvalidEventNumber(io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) Controller(io.pravega.client.control.impl.Controller) TokenExpiredException(io.pravega.auth.TokenExpiredException) RawClient(io.pravega.client.connection.impl.RawClient) ByteBuf(io.netty.buffer.ByteBuf) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Cleanup(lombok.Cleanup)

Example 55 with EventWriterConfig

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);
}
Also used : EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) 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