Search in sources :

Example 6 with StreamProcessorControl

use of io.zeebe.broker.topic.StreamProcessorControl in project zeebe by zeebe-io.

the class CreateDeploymentStreamProcessorTest method shouldTimeOutDeploymentAfterStreamProcessorRestart.

@Test
public void shouldTimeOutDeploymentAfterStreamProcessorRestart() {
    // given
    rule.getClock().pinCurrentTime();
    final StreamProcessorControl control = rule.runStreamProcessor(this::buildStreamProcessor);
    control.blockAfterDeploymentEvent(e -> e.getValue().getState() == DeploymentState.VALIDATED);
    rule.writeEvent(partitionCreated(STREAM_NAME, 1));
    rule.writeEvent(topicCreated(STREAM_NAME, 1));
    rule.writeEvent(createDeployment(ONE_TASK_PROCESS));
    waitUntil(() -> control.isBlocked());
    control.restart();
    // when
    rule.getClock().addTime(DEPLOYMENT_TIMEOUT.plus(Duration.ofSeconds(1)));
    // then
    waitUntil(() -> rule.events().onlyDeploymentEvents().inState(DeploymentState.TIMED_OUT).count() > 0);
}
Also used : StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

Example 7 with StreamProcessorControl

use of io.zeebe.broker.topic.StreamProcessorControl 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)

Example 8 with StreamProcessorControl

use of io.zeebe.broker.topic.StreamProcessorControl in project zeebe by zeebe-io.

the class TaskInstanceStreamProcessorTest method shouldExpireLockOnlyOnce.

@Test
public void shouldExpireLockOnlyOnce() {
    // 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, expireLock());
    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.EXPIRE_LOCK, TaskState.EXPIRE_LOCK, TaskState.LOCK_EXPIRED, TaskState.LOCK_EXPIRATION_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) StreamProcessorControl(io.zeebe.broker.topic.StreamProcessorControl) Test(org.junit.Test)

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