use of io.zeebe.broker.topic.StreamProcessorControl 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);
}
use of io.zeebe.broker.topic.StreamProcessorControl in project zeebe by zeebe-io.
the class TypedStreamProcessorTest method shouldWriteSourceEventAndProducerOnBatch.
@Test
public void shouldWriteSourceEventAndProducerOnBatch() {
// given
final TypedStreamEnvironment env = new TypedStreamEnvironment(streams.getLogStream(STREAM_NAME), output);
final TypedStreamProcessor streamProcessor = env.newStreamProcessor().onEvent(EventType.TOPIC_EVENT, TopicState.CREATE, new BatchProcessor()).build();
final StreamProcessorControl streamProcessorControl = streams.initStreamProcessor(STREAM_NAME, STREAM_PROCESSOR_ID, () -> streamProcessor);
streamProcessorControl.start();
final long firstEventPosition = streams.newEvent(STREAM_NAME).event(createTopic("foo", 1)).write();
// when
streamProcessorControl.unblock();
final LoggedEvent writtenEvent = doRepeatedly(() -> streams.events(STREAM_NAME).filter(Events::isTopicEvent).filter(e -> Events.asTopicEvent(e).getState() == TopicState.CREATE_REJECTED).findFirst()).until(o -> o.isPresent()).get();
// then
assertThat(writtenEvent.getProducerId()).isEqualTo(STREAM_PROCESSOR_ID);
assertThat(writtenEvent.getSourceEventLogStreamPartitionId()).isEqualTo(stream.getPartitionId());
assertThat(writtenEvent.getSourceEventPosition()).isEqualTo(firstEventPosition);
}
use of io.zeebe.broker.topic.StreamProcessorControl 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);
}
use of io.zeebe.broker.topic.StreamProcessorControl 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);
}
use of io.zeebe.broker.topic.StreamProcessorControl in project zeebe by zeebe-io.
the class StreamProcessorRule method runStreamProcessor.
public StreamProcessorControl runStreamProcessor(Function<TypedStreamEnvironment, StreamProcessor> factory) {
final StreamProcessorControl control = initStreamProcessor(factory);
control.start();
return control;
}
Aggregations