Search in sources :

Example 1 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent in project zeebe by zeebe-io.

the class IncidentStreamProcessorTest method shouldNotResolveIncidentIfActivityTerminated.

@Test
public void shouldNotResolveIncidentIfActivityTerminated() {
    // given
    final long workflowInstanceKey = 1L;
    final long activityInstanceKey = 2L;
    final StreamProcessorControl control = rule.runStreamProcessor(this::buildStreamProcessor);
    control.blockAfterIncidentEvent(e -> e.getValue().getState() == IncidentState.CREATED);
    final WorkflowInstanceEvent activityInstance = new WorkflowInstanceEvent();
    activityInstance.setState(WorkflowInstanceState.ACTIVITY_READY);
    activityInstance.setWorkflowInstanceKey(workflowInstanceKey);
    final long position = rule.writeEvent(activityInstanceKey, activityInstance);
    final IncidentEvent incident = new IncidentEvent();
    incident.setState(IncidentState.CREATE);
    incident.setWorkflowInstanceKey(workflowInstanceKey);
    incident.setActivityInstanceKey(activityInstanceKey);
    incident.setFailureEventPosition(position);
    rule.writeEvent(incident);
    // stream processor is now blocked
    waitForEventInState(IncidentState.CREATED);
    activityInstance.setState(WorkflowInstanceState.PAYLOAD_UPDATED);
    rule.writeEvent(activityInstanceKey, activityInstance);
    activityInstance.setState(WorkflowInstanceState.ACTIVITY_TERMINATED);
    rule.writeEvent(activityInstanceKey, activityInstance);
    // when
    control.unblock();
    // then
    waitForEventInState(IncidentState.DELETED);
    final List<TypedEvent<IncidentEvent>> incidentEvents = rule.events().onlyIncidentEvents().collect(Collectors.toList());
    assertThat(incidentEvents).extracting("value.state").containsExactly(IncidentState.CREATE, IncidentState.CREATED, IncidentState.RESOLVE, IncidentState.DELETE, IncidentState.RESOLVE_REJECTED, IncidentState.DELETED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) WorkflowInstanceEvent(io.zeebe.broker.workflow.data.WorkflowInstanceEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) IncidentEvent(io.zeebe.broker.incident.data.IncidentEvent) Test(org.junit.Test)

Example 2 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent in project zeebe by zeebe-io.

the class TaskInstanceStreamProcessorTest method shouldRejectExpireCommandIfTaskFailed.

@Test
public void shouldRejectExpireCommandIfTaskFailed() {
    // given
    final long key = 1;
    final StreamProcessorControl control = rule.runStreamProcessor(this::buildStreamProcessor);
    rule.writeEvent(key, create());
    waitForEventInState(TaskState.CREATED);
    control.blockAfterTaskEvent(e -> e.getValue().getState() == TaskState.LOCKED);
    rule.writeEvent(key, lock(nowPlus(Duration.ofSeconds(30))));
    waitForEventInState(TaskState.LOCKED);
    // when
    rule.writeEvent(key, failure());
    rule.writeEvent(key, expireLock());
    control.unblock();
    // then
    waitForEventInState(TaskState.LOCK_EXPIRATION_REJECTED);
    final List<TypedEvent<TaskEvent>> taskEvents = rule.events().onlyTaskEvents().collect(Collectors.toList());
    assertThat(taskEvents).extracting("value.state").containsExactly(TaskState.CREATE, TaskState.CREATED, TaskState.LOCK, TaskState.LOCKED, TaskState.FAIL, TaskState.EXPIRE_LOCK, TaskState.FAILED, TaskState.LOCK_EXPIRATION_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 3 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent in project zeebe by zeebe-io.

the class TaskInstanceStreamProcessorTest method shouldRejectExpireCommandIfTaskCompleted.

@Test
public void shouldRejectExpireCommandIfTaskCompleted() {
    // given
    final long key = 1;
    final StreamProcessorControl control = rule.runStreamProcessor(this::buildStreamProcessor);
    rule.writeEvent(key, create());
    waitForEventInState(TaskState.CREATED);
    control.blockAfterTaskEvent(e -> e.getValue().getState() == TaskState.LOCKED);
    rule.writeEvent(key, lock(nowPlus(Duration.ofSeconds(30))));
    waitForEventInState(TaskState.LOCKED);
    // when
    rule.writeEvent(key, complete());
    rule.writeEvent(key, expireLock());
    control.unblock();
    // then
    waitForEventInState(TaskState.LOCK_EXPIRATION_REJECTED);
    final List<TypedEvent<TaskEvent>> taskEvents = rule.events().onlyTaskEvents().collect(Collectors.toList());
    assertThat(taskEvents).extracting("value.state").containsExactly(TaskState.CREATE, TaskState.CREATED, TaskState.LOCK, TaskState.LOCKED, TaskState.COMPLETE, TaskState.EXPIRE_LOCK, TaskState.COMPLETED, TaskState.LOCK_EXPIRATION_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 4 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent in project zeebe by zeebe-io.

the class IncidentStreamProcessorTest method shouldNotCreateIncidentIfRetriesAreUpdatedIntermittently.

/**
 * Event order:
 *
 * Task FAILED -> UPDATE_RETRIES -> RETRIES UPDATED -> Incident CREATE -> Incident CREATE_REJECTED
 */
@Test
public void shouldNotCreateIncidentIfRetriesAreUpdatedIntermittently() {
    // given
    final TaskEvent task = taskFailed(0);
    // trigger incident creation
    final long key = rule.writeEvent(task);
    task.setState(TaskState.RETRIES_UPDATED);
    task.setRetries(1);
    // triggering incident removal
    rule.writeEvent(key, task);
    // when
    rule.runStreamProcessor(this::buildStreamProcessor);
    // then
    waitForEventInState(IncidentState.CREATE_REJECTED);
    final List<TypedEvent<IncidentEvent>> incidentEvents = rule.events().onlyIncidentEvents().collect(Collectors.toList());
    assertThat(incidentEvents).extracting("value.state").containsExactly(IncidentState.CREATE, IncidentState.CREATE_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) TaskEvent(io.zeebe.broker.task.data.TaskEvent) Test(org.junit.Test)

Example 5 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent in project zeebe by zeebe-io.

the class TaskInstanceStreamProcessorTest method shouldLockOnlyOnce.

@Test
public void shouldLockOnlyOnce() {
    // given
    rule.getClock().pinCurrentTime();
    final long key = 1;
    final StreamProcessorControl control = rule.runStreamProcessor(this::buildStreamProcessor);
    control.blockAfterTaskEvent(e -> e.getValue().getState() == TaskState.CREATED);
    rule.writeEvent(key, create());
    waitForEventInState(TaskState.CREATED);
    // when
    rule.writeEvent(key, lock(nowPlus(Duration.ofSeconds(30))));
    rule.writeEvent(key, lock(nowPlus(Duration.ofSeconds(30))));
    control.unblock();
    // then
    waitForEventInState(TaskState.LOCK_REJECTED);
    final List<TypedEvent<TaskEvent>> taskEvents = rule.events().onlyTaskEvents().collect(Collectors.toList());
    assertThat(taskEvents).extracting("value.state").containsExactly(TaskState.CREATE, TaskState.CREATED, TaskState.LOCK, TaskState.LOCK, TaskState.LOCKED, TaskState.LOCK_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Aggregations

TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)7 Test (org.junit.Test)7 StreamProcessorControl (io.zeebe.broker.topic.StreamProcessorControl)5 IncidentEvent (io.zeebe.broker.incident.data.IncidentEvent)1 TaskEvent (io.zeebe.broker.task.data.TaskEvent)1 PartitionRequest (io.zeebe.broker.topic.TestPartitionManager.PartitionRequest)1 WorkflowInstanceEvent (io.zeebe.broker.workflow.data.WorkflowInstanceEvent)1