Search in sources :

Example 1 with ControlledActorClock

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);
}
Also used : StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) Server(io.grpc.Server) LogStream(io.camunda.zeebe.logstreams.log.LogStream) ZbColumnFamilies(io.camunda.zeebe.engine.state.ZbColumnFamilies) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader)

Example 2 with ControlledActorClock

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());
}
Also used : ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Duration(java.time.Duration) RandomString(org.assertj.core.internal.bytebuddy.utility.RandomString) Test(org.junit.Test)

Example 3 with ControlledActorClock

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);
}
Also used : ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) ClusterServices(io.camunda.zeebe.broker.clustering.ClusterServices) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) BrokerClientImpl(io.camunda.zeebe.gateway.impl.broker.BrokerClientImpl) Before(org.junit.Before)

Example 4 with ControlledActorClock

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);
}
Also used : BrokerTopologyManagerImpl(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManagerImpl) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) BrokerClientImpl(io.camunda.zeebe.gateway.impl.broker.BrokerClientImpl) BrokerClusterStateImpl(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterStateImpl) Before(org.junit.Before)

Example 5 with ControlledActorClock

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());
}
Also used : ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) JobBatchRecordValue(io.camunda.zeebe.protocol.record.value.JobBatchRecordValue) Duration(java.time.Duration) Test(org.junit.Test)

Aggregations

ControlledActorClock (io.camunda.zeebe.util.sched.clock.ControlledActorClock)14 BrokerClientImpl (io.camunda.zeebe.gateway.impl.broker.BrokerClientImpl)6 GatewayCfg (io.camunda.zeebe.gateway.impl.configuration.GatewayCfg)6 Duration (java.time.Duration)6 Before (org.junit.Before)6 Test (org.junit.Test)6 EmbeddedBrokerRule (io.camunda.zeebe.broker.test.EmbeddedBrokerRule)3 ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)3 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)3 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)3 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)3 JobTimeoutTrigger (io.camunda.zeebe.engine.processing.job.JobTimeoutTrigger)3 GrpcClientRule (io.camunda.zeebe.it.util.GrpcClientRule)3 ZeebeAssertHelper (io.camunda.zeebe.it.util.ZeebeAssertHelper)3 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3 Record (io.camunda.zeebe.protocol.record.Record)3 ValueType (io.camunda.zeebe.protocol.record.ValueType)3 IncidentIntent (io.camunda.zeebe.protocol.record.intent.IncidentIntent)3 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)3