Search in sources :

Example 1 with StreamProcessorControl

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);
}
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 StreamProcessorControl

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);
}
Also used : LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) TopicEvent(io.zeebe.broker.system.log.TopicEvent) ActorSchedulerRule(io.zeebe.util.sched.testing.ActorSchedulerRule) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerOutput(io.zeebe.transport.ServerOutput) Test(org.junit.Test) LogStream(io.zeebe.logstreams.log.LogStream) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) TestStreams(io.zeebe.broker.util.TestStreams) RuleChain(org.junit.rules.RuleChain) TopicState(io.zeebe.broker.system.log.TopicState) MockitoAnnotations(org.mockito.MockitoAnnotations) Rule(org.junit.Rule) BufferUtil(io.zeebe.util.buffer.BufferUtil) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) EventType(io.zeebe.protocol.clientapi.EventType) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Events(io.zeebe.broker.topic.Events) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 3 with StreamProcessorControl

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);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 4 with StreamProcessorControl

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);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 5 with StreamProcessorControl

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;
}
Also used : StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl)

Aggregations

StreamProcessorControl (io.zeebe.broker.topic.StreamProcessorControl)8 Test (org.junit.Test)7 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)5 IncidentEvent (io.zeebe.broker.incident.data.IncidentEvent)1 TopicEvent (io.zeebe.broker.system.log.TopicEvent)1 TopicState (io.zeebe.broker.system.log.TopicState)1 Events (io.zeebe.broker.topic.Events)1 TestStreams (io.zeebe.broker.util.TestStreams)1 WorkflowInstanceEvent (io.zeebe.broker.workflow.data.WorkflowInstanceEvent)1 LogStream (io.zeebe.logstreams.log.LogStream)1 LoggedEvent (io.zeebe.logstreams.log.LoggedEvent)1 EventType (io.zeebe.protocol.clientapi.EventType)1 AutoCloseableRule (io.zeebe.test.util.AutoCloseableRule)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 ServerOutput (io.zeebe.transport.ServerOutput)1 BufferUtil (io.zeebe.util.buffer.BufferUtil)1 ActorSchedulerRule (io.zeebe.util.sched.testing.ActorSchedulerRule)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1