use of io.camunda.zeebe.util.sched.ActorScheduler in project zeebe by zeebe-io.
the class TestStreams method buildStreamProcessor.
private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
final var storage = createRuntimeFolder(stream);
final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
final var recoveredLatch = new CountDownLatch(1);
final var recoveredAwaiter = new StreamProcessorLifecycleAware() {
@Override
public void onRecovered(final ReadonlyProcessingContext context) {
recoveredLatch.countDown();
}
};
final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
final ZeebeDb<?> zeebeDb;
if (snapshotWasTaken) {
zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
} else {
zeebeDb = zeebeDbFactory.createDb(storage.toFile());
}
final String logName = stream.getLogName();
final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
final var openFuture = streamProcessor.openAsync(false);
if (awaitOpening) {
// and recovery
try {
recoveredLatch.await(15, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
Thread.interrupted();
}
}
openFuture.join(15, TimeUnit.SECONDS);
final LogContext context = logContextMap.get(logName);
final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
streamContextMap.put(logName, processorContext);
closeables.manage(processorContext);
return streamProcessor;
}
use of io.camunda.zeebe.util.sched.ActorScheduler in project zeebe-process-test by camunda.
the class EngineFactory method create.
public static ZeebeTestEngine create(final int port) {
final int partitionId = 1;
final int partitionCount = 1;
final ControlledActorClock clock = createActorClock();
final ActorScheduler scheduler = createAndStartActorScheduler(clock);
final InMemoryLogStorage logStorage = new InMemoryLogStorage();
final LogStream logStream = createLogStream(logStorage, scheduler, partitionId);
final SubscriptionCommandSenderFactory subscriptionCommandSenderFactory = new SubscriptionCommandSenderFactory(logStream.newLogStreamRecordWriter().join(), partitionId);
final GrpcToLogStreamGateway gateway = new GrpcToLogStreamGateway(logStream.newLogStreamRecordWriter().join(), partitionId, partitionCount, port);
final Server grpcServer = ServerBuilder.forPort(port).addService(gateway).build();
final GrpcResponseWriter grpcResponseWriter = new GrpcResponseWriter(gateway);
final ZeebeDb<ZbColumnFamilies> zeebeDb = createDatabase();
final EngineStateMonitor engineStateMonitor = new EngineStateMonitor(logStorage, logStream.newLogStreamReader().join());
final StreamProcessor streamProcessor = createStreamProcessor(logStream, zeebeDb, scheduler, grpcResponseWriter, engineStateMonitor, partitionCount, subscriptionCommandSenderFactory);
final LogStreamReader reader = logStream.newLogStreamReader().join();
final RecordStreamSourceImpl recordStream = new RecordStreamSourceImpl(reader, partitionId);
return new InMemoryEngine(grpcServer, streamProcessor, gateway, zeebeDb, logStream, scheduler, recordStream, clock, engineStateMonitor);
}
use of io.camunda.zeebe.util.sched.ActorScheduler in project zeebe by camunda.
the class ClusteringRule method createGateway.
private Gateway createGateway() {
final String contactPoint = NetUtil.toSocketAddressString(getBrokerCfg(0).getNetwork().getInternalApi().getAddress());
final GatewayCfg gatewayCfg = new GatewayCfg();
gatewayCfg.getCluster().setContactPoint(contactPoint).setClusterName(clusterName);
gatewayCfg.getNetwork().setPort(SocketUtil.getNextAddress().getPort());
gatewayCfg.getCluster().setPort(SocketUtil.getNextAddress().getPort());
// temporarily increase request time out, but we should make this configurable per test
gatewayCfg.getCluster().setRequestTimeout(Duration.ofSeconds(45));
gatewayCfg.init();
gatewayConfigurator.accept(gatewayCfg);
final ClusterCfg clusterCfg = gatewayCfg.getCluster();
// copied from StandaloneGateway
final AtomixCluster atomixCluster = new AtomixClusterBuilder(new ClusterConfig()).withMemberId(clusterCfg.getMemberId()).withAddress(Address.from(clusterCfg.getHost(), clusterCfg.getPort())).withClusterId(clusterCfg.getClusterName()).withMembershipProvider(BootstrapDiscoveryProvider.builder().withNodes(Address.from(clusterCfg.getContactPoint())).build()).withMembershipProtocol(SwimMembershipProtocol.builder().withSyncInterval(Duration.ofSeconds(1)).build()).withMessageCompression(gatewayCfg.getCluster().getMessageCompression()).build();
atomixCluster.start().join();
final ActorScheduler actorScheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(1).build();
actorScheduler.start();
final Gateway gateway = new Gateway(gatewayCfg, atomixCluster.getMessagingService(), atomixCluster.getMembershipService(), atomixCluster.getEventService(), actorScheduler);
closeables.manage(gateway::stop);
closeables.manage(atomixCluster::stop);
closeables.manage(actorScheduler::stop);
return gateway;
}
use of io.camunda.zeebe.util.sched.ActorScheduler in project zeebe by camunda.
the class TestStreams method buildStreamProcessor.
private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
final var storage = createRuntimeFolder(stream);
final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
final var recoveredLatch = new CountDownLatch(1);
final var recoveredAwaiter = new StreamProcessorLifecycleAware() {
@Override
public void onRecovered(final ReadonlyProcessingContext context) {
recoveredLatch.countDown();
}
};
final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
final ZeebeDb<?> zeebeDb;
if (snapshotWasTaken) {
zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
} else {
zeebeDb = zeebeDbFactory.createDb(storage.toFile());
}
final String logName = stream.getLogName();
final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
final var openFuture = streamProcessor.openAsync(false);
if (awaitOpening) {
// and recovery
try {
recoveredLatch.await(15, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
Thread.interrupted();
}
}
openFuture.join(15, TimeUnit.SECONDS);
final LogContext context = logContextMap.get(logName);
final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
streamContextMap.put(logName, processorContext);
closeables.manage(processorContext);
return streamProcessor;
}
use of io.camunda.zeebe.util.sched.ActorScheduler in project zeebe by camunda-cloud.
the class TestStreams method buildStreamProcessor.
private StreamProcessor buildStreamProcessor(final SynchronousLogStream stream, final ZeebeDbFactory zeebeDbFactory, final TypedRecordProcessorFactory factory, final boolean awaitOpening) {
final var storage = createRuntimeFolder(stream);
final var snapshot = storage.getParent().resolve(SNAPSHOT_FOLDER);
final var recoveredLatch = new CountDownLatch(1);
final var recoveredAwaiter = new StreamProcessorLifecycleAware() {
@Override
public void onRecovered(final ReadonlyProcessingContext context) {
recoveredLatch.countDown();
}
};
final TypedRecordProcessorFactory wrappedFactory = (ctx) -> factory.createProcessors(ctx).withListener(recoveredAwaiter);
final ZeebeDb<?> zeebeDb;
if (snapshotWasTaken) {
zeebeDb = zeebeDbFactory.createDb(snapshot.toFile());
} else {
zeebeDb = zeebeDbFactory.createDb(storage.toFile());
}
final String logName = stream.getLogName();
final StreamProcessor streamProcessor = StreamProcessor.builder().logStream(stream.getAsyncLogStream()).zeebeDb(zeebeDb).actorSchedulingService(actorScheduler).commandResponseWriter(mockCommandResponseWriter).listener(mockStreamProcessorListener).streamProcessorFactory(wrappedFactory).eventApplierFactory(eventApplierFactory).streamProcessorMode(streamProcessorMode).build();
final var openFuture = streamProcessor.openAsync(false);
if (awaitOpening) {
// and recovery
try {
recoveredLatch.await(15, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
Thread.interrupted();
}
}
openFuture.join(15, TimeUnit.SECONDS);
final LogContext context = logContextMap.get(logName);
final ProcessorContext processorContext = ProcessorContext.createStreamContext(context, streamProcessor, zeebeDb, storage, snapshot);
streamContextMap.put(logName, processorContext);
closeables.manage(processorContext);
return streamProcessor;
}
Aggregations