use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class EndToEndTxnWithScaleTest method testTxnWithScale.
@Test(timeout = 10000)
public void testTxnWithScale() throws Exception {
StreamConfiguration config = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
Controller controller = controllerWrapper.getController();
controllerWrapper.getControllerService().createScope("test").get();
controller.createStream(config).get();
@Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ClientFactory clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().transactionTimeoutScaleGracePeriod(10000).transactionTimeoutTime(10000).build());
Transaction<String> transaction = test.beginTxn();
transaction.writeEvent("0", "txntest1");
transaction.commit();
// scale
Stream stream = new StreamImpl("test", "test");
Map<Double, Double> map = new HashMap<>();
map.put(0.0, 0.33);
map.put(0.33, 0.66);
map.put(0.66, 1.0);
Boolean result = controller.scaleStream(stream, Collections.singletonList(0), map, executorService).getFuture().get();
assertTrue(result);
transaction = test.beginTxn();
transaction.writeEvent("0", "txntest2");
transaction.commit();
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory, connectionFactory);
groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/test").build());
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().build());
EventRead<String> event = reader.readNextEvent(10000);
assertNotNull(event);
assertEquals("txntest1", event.getEvent());
event = reader.readNextEvent(10000);
assertNotNull(event);
assertEquals("txntest2", event.getEvent());
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class ReaderGroupManagerImplTest method testCreateReaderGroupManager.
@Test
public void testCreateReaderGroupManager() {
ClientConfig config = ClientConfig.builder().controllerURI(URI.create("tls://localhost:9090")).build();
@Cleanup ReaderGroupManagerImpl readerGroupMgr = (ReaderGroupManagerImpl) ReaderGroupManager.withScope(SCOPE, config);
ClientFactoryImpl factory = (ClientFactoryImpl) readerGroupMgr.getClientFactory();
ConnectionPoolImpl cp = (ConnectionPoolImpl) factory.getConnectionPool();
assertEquals(1, cp.getClientConfig().getMaxConnectionsPerSegmentStore());
assertEquals(config.isEnableTls(), cp.getClientConfig().isEnableTls());
}
use of io.pravega.client.stream.impl.ClientFactoryImpl 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.ClientFactoryImpl in project pravega by pravega.
the class RevisionedStreamClientTest method testMark.
@Test
public void testMark() {
String scope = "scope";
String stream = "stream";
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
createScopeAndStream(scope, stream, controller);
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
@Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
SynchronizerConfig config = SynchronizerConfig.builder().build();
@Cleanup RevisionedStreamClient<String> client = clientFactory.createRevisionedStreamClient(stream, new JavaSerializer<>(), config);
client.writeUnconditionally("a");
Revision ra = client.fetchLatestRevision();
client.writeUnconditionally("b");
Revision rb = client.fetchLatestRevision();
client.writeUnconditionally("c");
Revision rc = client.fetchLatestRevision();
assertTrue(client.compareAndSetMark(null, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, rb));
assertEquals(rb, client.getMark());
assertFalse(client.compareAndSetMark(ra, rc));
assertEquals(rb, client.getMark());
assertTrue(client.compareAndSetMark(rb, rc));
assertEquals(rc, client.getMark());
assertTrue(client.compareAndSetMark(rc, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, null));
assertEquals(null, client.getMark());
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class RevisionedStreamClientTest method testWriteWhileReading.
@Test
public void testWriteWhileReading() {
String scope = "scope";
String stream = "stream";
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
createScopeAndStream(scope, stream, controller);
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
@Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
SynchronizerConfig config = SynchronizerConfig.builder().build();
@Cleanup RevisionedStreamClient<String> client = clientFactory.createRevisionedStreamClient(stream, new JavaSerializer<>(), config);
Revision initialRevision = client.fetchLatestRevision();
client.writeUnconditionally("a");
client.writeUnconditionally("b");
client.writeUnconditionally("c");
Iterator<Entry<Revision, String>> iter = client.readFrom(initialRevision);
assertTrue(iter.hasNext());
assertEquals("a", iter.next().getValue());
client.writeUnconditionally("d");
assertTrue(iter.hasNext());
assertEquals("b", iter.next().getValue());
assertTrue(iter.hasNext());
Entry<Revision, String> entry = iter.next();
assertEquals("c", entry.getValue());
assertFalse(iter.hasNext());
iter = client.readFrom(entry.getKey());
assertTrue(iter.hasNext());
assertEquals("d", iter.next().getValue());
assertFalse(iter.hasNext());
}
Aggregations