use of io.camunda.zeebe.util.sched.clock.ControlledActorClock 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.clock.ControlledActorClock in project zeebe by camunda.
the class ActivateJobsTest method shouldFetchFullJobRecordFromProcess.
@Test
public void shouldFetchFullJobRecordFromProcess() {
// given
final ControlledActorClock clock = ENGINE.getClock();
clock.pinCurrentTime();
final String worker = "testWorker";
final Duration timeout = Duration.ofMinutes(4);
ENGINE.deployment().withXmlResource(PROCESS_ID + ".bpmn", MODEL_SUPPLIER.apply(taskType)).deploy();
createProcessInstances(1, "{'foo':'bar'}");
final Record<JobRecordValue> jobRecord = jobRecords(JobIntent.CREATED).withType(taskType).getFirst();
// when
final Record<JobBatchRecordValue> jobActivatedRecord = ENGINE.jobs().withType(taskType).byWorker(worker).withTimeout(timeout.toMillis()).withMaxJobsToActivate(1).activate();
final JobRecordValue jobActivated = jobActivatedRecord.getValue().getJobs().get(0);
final Record<JobBatchRecordValue> jobActivate = RecordingExporter.jobBatchRecords().withType(taskType).withIntent(JobBatchIntent.ACTIVATE).getFirst();
// then
assertThat(jobActivated).hasType(taskType).hasWorker(worker).hasRetries(3).hasDeadline(jobActivate.getTimestamp() + timeout.toMillis());
assertThat(jobActivated.getVariables()).containsExactly(entry("foo", "bar"));
final JobRecordValue jobRecordValue = jobRecord.getValue();
assertThat(jobActivated.getProcessInstanceKey()).isEqualTo(jobRecordValue.getProcessInstanceKey());
assertThat(jobActivated).hasBpmnProcessId(jobRecordValue.getBpmnProcessId()).hasProcessDefinitionVersion(jobRecordValue.getProcessDefinitionVersion()).hasProcessDefinitionKey(jobRecordValue.getProcessDefinitionKey()).hasElementId(jobRecordValue.getElementId()).hasElementInstanceKey(jobRecordValue.getElementInstanceKey());
assertThat(jobActivated.getCustomHeaders()).isEqualTo(jobRecordValue.getCustomHeaders());
}
use of io.camunda.zeebe.util.sched.clock.ControlledActorClock in project zeebe by camunda.
the class GatewayIntegrationTest method setup.
@Before
public void setup() {
final GatewayCfg configuration = new GatewayCfg();
final var brokerCfg = broker.getBrokerCfg();
final var internalApi = brokerCfg.getNetwork().getInternalApi();
configuration.getCluster().setHost("0.0.0.0").setPort(SocketUtil.getNextAddress().getPort()).setContactPoint(internalApi.toString()).setRequestTimeout(Duration.ofSeconds(10));
configuration.init();
final ControlledActorClock clock = new ControlledActorClock();
final ClusterServices clusterServices = broker.getClusterServices();
client = new BrokerClientImpl(configuration, clusterServices.getMessagingService(), clusterServices.getMembershipService(), clusterServices.getEventService(), clock);
}
use of io.camunda.zeebe.util.sched.clock.ControlledActorClock in project zeebe by zeebe-io.
the class BrokerClientTest method setUp.
@Before
public void setUp() {
final GatewayCfg configuration = new GatewayCfg();
configuration.getCluster().setHost("0.0.0.0").setPort(SocketUtil.getNextAddress().getPort()).setContactPoint(NetUtil.toSocketAddressString(broker.getSocketAddress())).setRequestTimeout(Duration.ofSeconds(3));
configuration.init();
final ControlledActorClock clock = new ControlledActorClock();
final var stubAddress = Address.from(broker.getCurrentStubHost(), broker.getCurrentStubPort());
final var stubNode = Node.builder().withAddress(stubAddress).build();
final var listOfNodes = List.of(stubNode);
atomixCluster = AtomixCluster.builder().withPort(SocketUtil.getNextAddress().getPort()).withMemberId("gateway").withClusterId("cluster").withMembershipProvider(BootstrapDiscoveryProvider.builder().withNodes(listOfNodes).build()).build();
atomixCluster.start().join();
client = new BrokerClientImpl(configuration, atomixCluster.getMessagingService(), atomixCluster.getMembershipService(), atomixCluster.getEventService(), clock);
final BrokerClusterStateImpl topology = new BrokerClusterStateImpl();
topology.addPartitionIfAbsent(START_PARTITION_ID);
topology.setPartitionLeader(START_PARTITION_ID, 0, 1);
topology.addBrokerIfAbsent(0);
topology.setBrokerAddressIfPresent(0, stubAddress.toString());
((BrokerTopologyManagerImpl) client.getTopologyManager()).setTopology(topology);
}
use of io.camunda.zeebe.util.sched.clock.ControlledActorClock in project zeebe by zeebe-io.
the class ActivateJobsTest method shouldFetchFullJobRecordFromProcess.
@Test
public void shouldFetchFullJobRecordFromProcess() {
// given
final ControlledActorClock clock = ENGINE.getClock();
clock.pinCurrentTime();
final String worker = "testWorker";
final Duration timeout = Duration.ofMinutes(4);
ENGINE.deployment().withXmlResource(PROCESS_ID + ".bpmn", MODEL_SUPPLIER.apply(taskType)).deploy();
createProcessInstances(1, "{'foo':'bar'}");
final Record<JobRecordValue> jobRecord = jobRecords(JobIntent.CREATED).withType(taskType).getFirst();
// when
final Record<JobBatchRecordValue> jobActivatedRecord = ENGINE.jobs().withType(taskType).byWorker(worker).withTimeout(timeout.toMillis()).withMaxJobsToActivate(1).activate();
final JobRecordValue jobActivated = jobActivatedRecord.getValue().getJobs().get(0);
final Record<JobBatchRecordValue> jobActivate = RecordingExporter.jobBatchRecords().withType(taskType).withIntent(JobBatchIntent.ACTIVATE).getFirst();
// then
assertThat(jobActivated).hasType(taskType).hasWorker(worker).hasRetries(3).hasDeadline(jobActivate.getTimestamp() + timeout.toMillis());
assertThat(jobActivated.getVariables()).containsExactly(entry("foo", "bar"));
final JobRecordValue jobRecordValue = jobRecord.getValue();
assertThat(jobActivated.getProcessInstanceKey()).isEqualTo(jobRecordValue.getProcessInstanceKey());
assertThat(jobActivated).hasBpmnProcessId(jobRecordValue.getBpmnProcessId()).hasProcessDefinitionVersion(jobRecordValue.getProcessDefinitionVersion()).hasProcessDefinitionKey(jobRecordValue.getProcessDefinitionKey()).hasElementId(jobRecordValue.getElementId()).hasElementInstanceKey(jobRecordValue.getElementInstanceKey());
assertThat(jobActivated.getCustomHeaders()).isEqualTo(jobRecordValue.getCustomHeaders());
}
Aggregations