Search in sources :

Example 1 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class ClientConfigTest method serializable.

@Test
public void serializable() {
    JavaSerializer<ClientConfig> s = new JavaSerializer<>();
    ClientConfig expected = ClientConfig.builder().credentials(new DefaultCredentials(PASSWORD, USERNAME)).controllerURI(URI.create("tcp://localhost:9090")).trustStore("truststore.jks").validateHostName(false).build();
    ClientConfig actual = s.deserialize(s.serialize(expected));
    assertEquals(expected, actual);
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Test(org.junit.Test)

Example 2 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class RevisionedStreamClientTest method testCreateRevisionedStreamClientError.

@Test
public void testCreateRevisionedStreamClientError() {
    String scope = "scope";
    String stream = "stream";
    JavaSerializer<Serializable> serializer = new JavaSerializer<>();
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    Controller controller = Mockito.mock(Controller.class);
    MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
    @Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
    SynchronizerConfig config = SynchronizerConfig.builder().build();
    // Simulate sealed stream.
    CompletableFuture<StreamSegments> result = new CompletableFuture<>();
    result.complete(new StreamSegments(new TreeMap<>()));
    when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
    assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
    // Simulate invalid stream.
    result = new CompletableFuture<>();
    result.completeExceptionally(new RuntimeException());
    when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
    assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
    // Simulate null result from Controller.
    result = new CompletableFuture<>();
    result.complete(null);
    when(controller.getCurrentSegments(scope, stream)).thenReturn(result);
    assertThrows(InvalidStreamException.class, () -> clientFactory.createRevisionedStreamClient(stream, serializer, config));
}
Also used : Serializable(java.io.Serializable) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) TreeMap(java.util.TreeMap) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Cleanup(lombok.Cleanup) SynchronizerClientFactory(io.pravega.client.SynchronizerClientFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Test(org.junit.Test)

Example 3 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class RevisionedStreamClientTest method testTimeoutWithStreamIterator.

@Test
public void testTimeoutWithStreamIterator() throws Exception {
    String scope = "scope";
    String stream = "stream";
    // Setup Environment
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
    createScopeAndStream(scope, stream, controller);
    MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
    // Setup mock
    SegmentOutputStreamFactory outFactory = mock(SegmentOutputStreamFactory.class);
    SegmentOutputStream out = mock(SegmentOutputStream.class);
    Segment segment = new Segment(scope, stream, 0);
    when(outFactory.createOutputStreamForSegment(eq(segment), any(), any(), any(DelegationTokenProvider.class))).thenReturn(out);
    SegmentInputStreamFactory inFactory = mock(SegmentInputStreamFactory.class);
    EventSegmentReader in = mock(EventSegmentReader.class);
    when(inFactory.createEventReaderForSegment(eq(segment), anyInt())).thenReturn(in);
    when(in.read(anyLong())).thenReturn(null).thenReturn(serializer.serialize("testData"));
    SegmentMetadataClientFactory metaFactory = mock(SegmentMetadataClientFactory.class);
    SegmentMetadataClient metaClient = mock(SegmentMetadataClient.class);
    when(metaFactory.createSegmentMetadataClient(any(Segment.class), any(DelegationTokenProvider.class))).thenReturn(metaClient);
    when(metaClient.getSegmentInfo()).thenReturn(CompletableFuture.completedFuture(new SegmentInfo(segment, 0, 30, false, System.currentTimeMillis())));
    @Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, inFactory, streamFactory, streamFactory, metaFactory);
    @Cleanup RevisionedStreamClient<String> client = clientFactory.createRevisionedStreamClient(stream, serializer, SynchronizerConfig.builder().build());
    Iterator<Entry<Revision, String>> iterator = client.readFrom(new RevisionImpl(segment, 15, 1));
    assertTrue("True is expected since offset is less than end offset", iterator.hasNext());
    assertNotNull("Verify the entry is not null", iterator.next());
    verify(in, times(2)).read(anyLong());
}
Also used : MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) SynchronizerClientFactory(io.pravega.client.SynchronizerClientFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Entry(java.util.Map.Entry) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) EventSegmentReader(io.pravega.client.segment.impl.EventSegmentReader) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) SegmentInfo(io.pravega.client.segment.impl.SegmentInfo) SegmentInputStreamFactory(io.pravega.client.segment.impl.SegmentInputStreamFactory) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) Test(org.junit.Test)

Example 4 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class SynchronizerTest method testReturnValue.

@Test(timeout = 20000)
public void testReturnValue() {
    String streamName = "streamName";
    String scope = "scope";
    MockSegmentStreamFactory ioFactory = new MockSegmentStreamFactory();
    @Cleanup MockClientFactory clientFactory = new MockClientFactory(scope, ioFactory);
    createScopeAndStream(streamName, scope, clientFactory.getController());
    StateSynchronizer<RevisionedImpl> sync = clientFactory.createStateSynchronizer(streamName, new JavaSerializer<>(), new JavaSerializer<>(), SynchronizerConfig.builder().build());
    StateSynchronizer<RevisionedImpl> syncA = clientFactory.createStateSynchronizer(streamName, new JavaSerializer<>(), new JavaSerializer<>(), SynchronizerConfig.builder().build());
    StateSynchronizer<RevisionedImpl> syncB = clientFactory.createStateSynchronizer(streamName, new JavaSerializer<>(), new JavaSerializer<>(), SynchronizerConfig.builder().build());
    syncA.initialize(new RegularUpdate("Foo"));
    AtomicInteger callCount = new AtomicInteger(0);
    String previous = syncB.updateState((state, updates) -> {
        callCount.incrementAndGet();
        updates.add(new RegularUpdate("Bar"));
        return state.getValue();
    });
    assertEquals(previous, "Foo");
    assertEquals(1, callCount.get());
    assertEquals("Foo", syncA.getState().value);
    previous = syncA.updateState((state, updates) -> {
        callCount.incrementAndGet();
        updates.add(new RegularUpdate("Baz"));
        return state.getValue();
    });
    assertEquals(previous, "Bar");
    assertEquals(3, callCount.get());
    assertEquals("Baz", syncA.getState().value);
    syncB.fetchUpdates();
    assertEquals("Baz", syncA.getState().value);
    previous = syncB.updateState((state, updates) -> {
        callCount.incrementAndGet();
        updates.add(new RegularUpdate("Bat"));
        return state.getValue();
    });
    assertEquals(previous, "Baz");
    assertEquals(4, callCount.get());
    assertEquals("Baz", syncA.getState().value);
    syncA.fetchUpdates();
    assertEquals("Bat", syncA.getState().value);
}
Also used : AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamSegments(io.pravega.client.stream.impl.StreamSegments) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) InitialUpdate(io.pravega.client.state.InitialUpdate) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Serializable(java.io.Serializable) CountDownLatch(java.util.concurrent.CountDownLatch) SetSynchronizer(io.pravega.client.state.examples.SetSynchronizer) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) SegmentAttribute(io.pravega.client.segment.impl.SegmentAttribute) Controller(io.pravega.client.control.impl.Controller) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) Mockito.mock(org.mockito.Mockito.mock) StateSynchronizer(io.pravega.client.state.StateSynchronizer) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Segment(io.pravega.client.segment.impl.Segment) TruncatedDataException(io.pravega.client.stream.TruncatedDataException) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ByteArraySerializer(io.pravega.client.stream.impl.ByteArraySerializer) Update(io.pravega.client.state.Update) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RevisionedStreamClient(io.pravega.client.state.RevisionedStreamClient) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) ReusableLatch(io.pravega.common.util.ReusableLatch) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Revisioned(io.pravega.client.state.Revisioned) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractMap(java.util.AbstractMap) Assert.assertNull(org.junit.Assert.assertNull) TreeMap(java.util.TreeMap) SynchronizerClientFactory(io.pravega.client.SynchronizerClientFactory) Data(lombok.Data) Revision(io.pravega.client.state.Revision) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) Cleanup(lombok.Cleanup) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) Test(org.junit.Test)

Example 5 with JavaSerializer

use of io.pravega.client.stream.impl.JavaSerializer in project pravega by pravega.

the class SynchronizerTest method testCreateStateSynchronizerError.

@Test(timeout = 20000)
public void testCreateStateSynchronizerError() {
    String streamName = "streamName";
    String scope = "scope";
    Controller controller = mock(Controller.class);
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, ClientConfig.builder().build());
    // Simulate a sealed stream.
    CompletableFuture<StreamSegments> result = new CompletableFuture<>();
    result.complete(new StreamSegments(new TreeMap<>()));
    when(controller.getCurrentSegments(scope, streamName)).thenReturn(result);
    AssertExtensions.assertThrows(InvalidStreamException.class, () -> clientFactory.createStateSynchronizer(streamName, new JavaSerializer<>(), new JavaSerializer<>(), SynchronizerConfig.builder().build()));
    result = new CompletableFuture<>();
    result.completeExceptionally(new RuntimeException("Controller exception"));
    when(controller.getCurrentSegments(scope, streamName)).thenReturn(result);
    AssertExtensions.assertThrows(InvalidStreamException.class, () -> clientFactory.createStateSynchronizer(streamName, new JavaSerializer<>(), new JavaSerializer<>(), SynchronizerConfig.builder().build()));
}
Also used : ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Controller(io.pravega.client.control.impl.Controller) TreeMap(java.util.TreeMap) Cleanup(lombok.Cleanup) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Test(org.junit.Test)

Aggregations

JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)37 Cleanup (lombok.Cleanup)34 Test (org.junit.Test)34 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)22 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)21 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)19 ClientConfig (io.pravega.client.ClientConfig)17 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)16 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)16 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)16 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)16 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)15 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)15 CompletableFuture (java.util.concurrent.CompletableFuture)15 Slf4j (lombok.extern.slf4j.Slf4j)15 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)14 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)14 Controller (io.pravega.client.control.impl.Controller)14 Stream (io.pravega.client.stream.Stream)14 Map (java.util.Map)14