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);
}
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));
}
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());
}
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);
}
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()));
}
Aggregations