use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class EndToEndTransactionTest method main.
@Test
public static void main(String[] args) throws Exception {
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
int port = Config.SERVICE_PORT;
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, serviceBuilder.createTableStoreService(), serviceBuilder.getLowPriorityExecutor(), Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()]));
server.startListening();
Thread.sleep(1000);
@Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port);
Controller controller = controllerWrapper.getController();
controllerWrapper.awaitRunning();
final String testScope = "testScope";
final String testStream = "testStream";
if (!controller.createScope(testScope).get()) {
log.error("FAILURE: Error creating test scope");
return;
}
ScalingPolicy policy = ScalingPolicy.fixed(5);
StreamConfiguration streamConfig = StreamConfiguration.builder().scalingPolicy(policy).build();
if (!controller.createStream(testScope, testStream, streamConfig).get()) {
log.error("FAILURE: Error creating test stream");
return;
}
final long txnTimeout = 4000;
ClientConfig config = ClientConfig.builder().build();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
@Cleanup MockClientFactory clientFactory = new MockClientFactory(testScope, controller, new ConnectionPoolImpl(config, connectionFactory));
@Cleanup TransactionalEventStreamWriter<String> producer = clientFactory.createTransactionalEventWriter("writer", testStream, new UTF8StringSerializer(), EventWriterConfig.builder().transactionTimeoutTime(txnTimeout).build());
// region Successful commit tests
Transaction<String> transaction = producer.beginTxn();
for (int i = 0; i < 1; i++) {
String event = "\n Transactional Publish \n";
log.info("Producing event: " + event);
transaction.writeEvent("", event);
transaction.flush();
Thread.sleep(500);
}
CompletableFuture<Object> commit = CompletableFuture.supplyAsync(() -> {
try {
transaction.commit();
} catch (Exception e) {
log.warn("Error committing transaction", e);
}
return null;
});
commit.join();
Transaction.Status txnStatus = transaction.checkStatus();
assertTrue(txnStatus == Transaction.Status.COMMITTING || txnStatus == Transaction.Status.COMMITTED);
log.info("SUCCESS: successful in committing transaction. Transaction status=" + txnStatus);
Thread.sleep(2000);
txnStatus = transaction.checkStatus();
assertTrue(txnStatus == Transaction.Status.COMMITTED);
log.info("SUCCESS: successfully committed transaction. Transaction status=" + txnStatus);
// endregion
// region Successful abort tests
Transaction<String> transaction2 = producer.beginTxn();
for (int i = 0; i < 1; i++) {
String event = "\n Transactional Publish \n";
log.info("Producing event: " + event);
transaction2.writeEvent("", event);
transaction2.flush();
Thread.sleep(500);
}
CompletableFuture<Object> drop = CompletableFuture.supplyAsync(() -> {
try {
transaction2.abort();
} catch (Exception e) {
log.warn("Error aborting transaction", e);
}
return null;
});
drop.join();
Transaction.Status txn2Status = transaction2.checkStatus();
assertTrue(txn2Status == Transaction.Status.ABORTING || txn2Status == Transaction.Status.ABORTED);
log.info("SUCCESS: successful in dropping transaction. Transaction status=" + txn2Status);
Thread.sleep(2000);
txn2Status = transaction2.checkStatus();
assertTrue(txn2Status == Transaction.Status.ABORTED);
log.info("SUCCESS: successfully aborted transaction. Transaction status=" + txn2Status);
// endregion
// region Successful timeout tests
Transaction<String> tx1 = producer.beginTxn();
Thread.sleep((long) (1.3 * txnTimeout));
Transaction.Status txStatus = tx1.checkStatus();
Assert.assertTrue(Transaction.Status.ABORTING == txStatus || Transaction.Status.ABORTED == txStatus);
log.info("SUCCESS: successfully aborted transaction after timeout. Transaction status=" + txStatus);
// endregion
// region Ping failure due to controller going into disconnection state
// Fill in these tests once we have controller.stop() implemented.
System.exit(0);
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class EndToEndAutoScaleDownTest method main.
public static void main(String[] args) throws Exception {
try {
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
int port = Config.SERVICE_PORT;
@Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port, false);
Controller controller = controllerWrapper.getController();
controllerWrapper.getControllerService().createScope(NameUtils.INTERNAL_SCOPE_NAME, 0L).get();
ClientFactoryImpl internalCF = new ClientFactoryImpl(NameUtils.INTERNAL_SCOPE_NAME, controller, new SocketConnectionFactoryImpl(ClientConfig.builder().build()));
ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
TableStore tableStore = serviceBuilder.createTableStoreService();
@Cleanup AutoScaleMonitor autoScaleMonitor = new AutoScaleMonitor(store, internalCF, AutoScalerConfig.builder().with(AutoScalerConfig.MUTE_IN_SECONDS, 0).with(AutoScalerConfig.COOLDOWN_IN_SECONDS, 0).with(AutoScalerConfig.CACHE_CLEANUP_IN_SECONDS, 5).with(AutoScalerConfig.CACHE_EXPIRY_IN_SECONDS, 30).build());
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, false, "localhost", 12345, store, tableStore, autoScaleMonitor.getStatsRecorder(), autoScaleMonitor.getTableSegmentStatsRecorder(), null, null, null, true, serviceBuilder.getLowPriorityExecutor(), Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()]));
server.startListening();
controllerWrapper.awaitRunning();
controllerWrapper.getControllerService().createScope("test", 0L).get();
controller.createStream("test", "test", CONFIG).get();
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);
@Cleanup("shutdownNow") ScheduledExecutorService executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
controller.scaleStream(stream, Collections.singletonList(0L), map, executor).getFuture().get();
Retry.withExpBackoff(10, 10, 100, 10000).retryingOn(NotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments("test", "test").thenAccept(streamSegments -> {
if (streamSegments.getSegments().size() < 3) {
System.err.println("Success");
log.info("Success");
System.exit(0);
} else {
throw new NotDoneException();
}
}), executor).exceptionally(e -> {
System.err.println("Failure");
log.error("Failure");
System.exit(1);
return null;
}).get();
} catch (Throwable e) {
System.err.print("Test failed with exception: " + e.getMessage());
System.exit(-1);
}
System.exit(0);
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class BucketServiceTest method setup.
@Before
public void setup() throws Exception {
executor = ExecutorServiceHelpers.newScheduledThreadPool(10, "test");
hostId = UUID.randomUUID().toString();
streamMetadataStore = createStreamStore(executor);
bucketStore = createBucketStore(3);
TaskMetadataStore taskMetadataStore = TaskStoreFactory.createInMemoryStore(executor);
connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMock();
streamMetadataTasks = new StreamMetadataTasks(streamMetadataStore, bucketStore, taskMetadataStore, segmentHelper, executor, hostId, GrpcAuthHelper.getDisabledAuthHelper());
BucketServiceFactory bucketStoreFactory = new BucketServiceFactory(hostId, bucketStore, 2);
PeriodicRetention periodicRetention = new PeriodicRetention(streamMetadataStore, streamMetadataTasks, executor, requestTracker);
retentionService = bucketStoreFactory.createRetentionService(Duration.ofMillis(5), periodicRetention::retention, executor);
retentionService.startAsync();
retentionService.awaitRunning();
ClientConfig clientConfig = ClientConfig.builder().build();
periodicWatermarking = new PeriodicWatermarking(streamMetadataStore, bucketStore, clientConfig, executor, requestTracker);
watermarkingService = bucketStoreFactory.createWatermarkingService(Duration.ofMillis(5), periodicWatermarking::watermark, executor);
watermarkingService.startAsync();
watermarkingService.awaitRunning();
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class ControllerServiceTest method setup.
@Before
public void setup() throws Exception {
final TaskMetadataStore taskMetadataStore = TaskStoreFactory.createZKStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor);
final HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
BucketStore bucketStore = StreamStoreFactory.createInMemoryBucketStore();
connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), new SocketConnectionFactoryImpl(ClientConfig.builder().build()));
SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMock();
streamMetadataTasks = new StreamMetadataTasks(streamStore, bucketStore, taskMetadataStore, segmentHelper, executor, "host", GrpcAuthHelper.getDisabledAuthHelper());
streamTransactionMetadataTasks = new StreamTransactionMetadataTasks(streamStore, segmentHelper, executor, "host", GrpcAuthHelper.getDisabledAuthHelper());
kvtMetadataTasks = new TableMetadataTasks(kvtStore, segmentHelper, executor, executor, "host", GrpcAuthHelper.getDisabledAuthHelper());
consumer = new ControllerService(kvtStore, kvtMetadataTasks, streamStore, bucketStore, streamMetadataTasks, streamTransactionMetadataTasks, new SegmentHelper(connectionPool, hostStore, executor), executor, null, requestTracker);
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final ScalingPolicy policy2 = ScalingPolicy.fixed(3);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
final StreamConfiguration configuration2 = StreamConfiguration.builder().scalingPolicy(policy2).build();
// createScope
streamStore.createScope(SCOPE, null, executor).get();
// region createStream
startTs = System.currentTimeMillis();
OperationContext context = streamStore.createStreamContext(SCOPE, stream1, 0L);
streamStore.createStream(SCOPE, stream1, configuration1, startTs, context, executor).get();
streamStore.setState(SCOPE, stream1, State.ACTIVE, context, executor).get();
OperationContext context2 = streamStore.createStreamContext(SCOPE, stream2, 0L);
streamStore.createStream(SCOPE, stream2, configuration2, startTs, context2, executor).get();
streamStore.setState(SCOPE, stream2, State.ACTIVE, context2, executor).get();
// endregion
// region scaleSegments
SimpleEntry<Double, Double> segment1 = new SimpleEntry<>(0.5, 0.75);
SimpleEntry<Double, Double> segment2 = new SimpleEntry<>(0.75, 1.0);
List<Long> sealedSegments = Collections.singletonList(1L);
scaleTs = System.currentTimeMillis();
VersionedMetadata<EpochTransitionRecord> record = streamStore.submitScale(SCOPE, stream1, sealedSegments, Arrays.asList(segment1, segment2), startTs, null, null, executor).get();
VersionedMetadata<State> state = streamStore.getVersionedState(SCOPE, stream1, null, executor).get();
state = streamStore.updateVersionedState(SCOPE, stream1, State.SCALING, state, null, executor).get();
record = streamStore.startScale(SCOPE, stream1, false, record, state, null, executor).get();
streamStore.scaleCreateNewEpochs(SCOPE, stream1, record, null, executor).get();
streamStore.scaleSegmentsSealed(SCOPE, stream1, sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), record, null, executor).get();
streamStore.completeScale(SCOPE, stream1, record, null, executor).get();
streamStore.setState(SCOPE, stream1, State.ACTIVE, null, executor).get();
SimpleEntry<Double, Double> segment3 = new SimpleEntry<>(0.0, 0.5);
SimpleEntry<Double, Double> segment4 = new SimpleEntry<>(0.5, 0.75);
SimpleEntry<Double, Double> segment5 = new SimpleEntry<>(0.75, 1.0);
sealedSegments = Arrays.asList(0L, 1L, 2L);
record = streamStore.submitScale(SCOPE, stream2, sealedSegments, Arrays.asList(segment3, segment4, segment5), scaleTs, null, null, executor).get();
state = streamStore.getVersionedState(SCOPE, stream2, null, executor).get();
state = streamStore.updateVersionedState(SCOPE, stream2, State.SCALING, state, null, executor).get();
record = streamStore.startScale(SCOPE, stream2, false, record, state, null, executor).get();
streamStore.scaleCreateNewEpochs(SCOPE, stream2, record, null, executor).get();
streamStore.scaleSegmentsSealed(SCOPE, stream2, sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), record, null, executor).get();
streamStore.completeScale(SCOPE, stream2, record, null, executor).get();
streamStore.setState(SCOPE, stream2, State.ACTIVE, null, executor).get();
// endregion
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class KeyValueTableTest method setup.
@Override
@Before
public void setup() throws Exception {
super.setup();
// 1. Start ZK
this.zkTestServer = new TestingServerStarter().start();
// 2. Start Pravega SegmentStore service.
this.serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
this.tableStore = serviceBuilder.createTableStoreService();
this.serverListener = new PravegaConnectionListener(false, servicePort, serviceBuilder.createStreamSegmentService(), this.tableStore, executorService());
this.serverListener.startListening();
// 3. Start Pravega Controller service
this.controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
this.controllerWrapper.awaitRunning();
this.controller = controllerWrapper.getController();
// 4. Create Scope
this.controller.createScope(SCOPE).get();
ClientConfig clientConfig = ClientConfig.builder().build();
SocketConnectionFactoryImpl connectionFactory = new SocketConnectionFactoryImpl(clientConfig);
this.connectionPool = new ConnectionPoolImpl(clientConfig, connectionFactory);
this.keyValueTableFactory = new KeyValueTableFactoryImpl(SCOPE, this.controller, this.connectionPool);
}
Aggregations