Search in sources :

Example 6 with TypedEvent

use of io.zeebe.broker.logstreams.processor.TypedEvent 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)

Example 7 with TypedEvent

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

the class CreateTopicStreamProcessorTest method shouldRejectSecondPartitionCompleteCommand.

/**
 * Tests the case where the stream processor is slower than the interval in which
 * we check the gossip state for the leader of any pending partitions.
 */
@Test
public void shouldRejectSecondPartitionCompleteCommand() {
    // given
    // stream processor is registered and active; configured to block on first partition creating event
    partitionManager.addMember(SOCKET_ADDRESS1);
    final StreamProcessorControl processorControl = rule.runStreamProcessor(this::buildStreamProcessor);
    processorControl.blockAfterEvent(e -> Events.isPartitionEvent(e) && Events.asPartitionEvent(e).getState() == PartitionState.CREATING);
    rule.writeEvent(createTopic("foo", 1));
    // waiting for partition creating event => the stream processor is now suspended
    waitUntil(() -> rule.events().onlyPartitionEvents().inState(PartitionState.CREATING).findFirst().isPresent());
    final PartitionRequest request = partitionManager.getPartitionRequests().get(0);
    partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, request.getPartitionId());
    // calling check pending partition once
    streamProcessor.runAsync(checkPartitionsCmd);
    // waiting for partition creation complete command
    waitUntil(() -> rule.events().onlyPartitionEvents().inState(PartitionState.CREATE_COMPLETE).findFirst().isPresent());
    // when
    // calling check pending partition again
    streamProcessor.runAsync(checkPartitionsCmd);
    // waiting for partition creation complete command
    waitUntil(() -> rule.events().onlyPartitionEvents().inState(PartitionState.CREATE_COMPLETE).count() == 2);
    // and resuming stream processing
    processorControl.unblock();
    // then
    waitUntil(() -> partitionEventsInState(PartitionState.CREATE_COMPLETE_REJECTED).findFirst().isPresent());
    final List<TypedEvent<PartitionEvent>> partitionEvents = rule.events().onlyPartitionEvents().collect(Collectors.toList());
    assertThat(partitionEvents).extracting("value.state").containsExactly(PartitionState.CREATE, PartitionState.CREATING, PartitionState.CREATE_COMPLETE, PartitionState.CREATE_COMPLETE, PartitionState.CREATED, PartitionState.CREATE_COMPLETE_REJECTED);
}
Also used : TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) 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