Search in sources :

Example 36 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 37 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 38 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 39 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 40 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