use of io.zeebe.broker.topic.TestPartitionManager.PartitionRequest in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldSendResponseAfterTheDefinedNumberOfPartitionsIsCreated.
@Test
public void shouldSendResponseAfterTheDefinedNumberOfPartitionsIsCreated() {
// given
rule.getClock().pinCurrentTime();
partitionManager.addMember(SOCKET_ADDRESS1);
rule.runStreamProcessor(this::buildStreamProcessor);
// request for two partitions
rule.writeEvent(createTopic("foo", 2));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 2);
final PartitionRequest firstRequest = partitionManager.getPartitionRequests().get(0);
partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, firstRequest.getPartitionId());
// a partition with expired creation
rule.getClock().addTime(CREATION_EXPIRATION.plusSeconds(1));
streamProcessor.runAsync(checkPartitionsCmd);
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 3);
final PartitionEvent creatingEvent = partitionEventsInState(PartitionState.CREATING).skip(2).findFirst().get().getValue();
// when
partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, creatingEvent.getId());
streamProcessor.runAsync(checkPartitionsCmd);
waitUntil(() -> topicEventsInState(TopicState.CREATED).findFirst().isPresent());
// then topic is marked created after two out of three partitions have been created
assertThat(topicEventsInState(TopicState.CREATED).count()).isEqualTo(1);
assertThat(rule.getOutput().getSentResponses()).hasSize(1);
}
use of io.zeebe.broker.topic.TestPartitionManager.PartitionRequest in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldRejectExpirationOnIntermittentCompletion.
@Test
public void shouldRejectExpirationOnIntermittentCompletion() {
rule.getClock().pinCurrentTime();
partitionManager.addMember(SOCKET_ADDRESS1);
final StreamProcessorControl processorControl = rule.runStreamProcessor(this::buildStreamProcessor);
processorControl.blockAfterPartitionEvent(e -> e.getValue().getState() == PartitionState.CREATING);
rule.writeEvent(createTopic("foo", 1));
waitUntil(() -> processorControl.isBlocked());
final PartitionRequest request = partitionManager.getPartitionRequests().get(0);
partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, request.getPartitionId());
// when creating a complete and expire command
rule.getClock().addTime(CREATION_EXPIRATION.plusSeconds(1));
streamProcessor.runAsync(checkPartitionsCmd);
// then
processorControl.unblock();
waitUntil(() -> partitionEventsInState(PartitionState.CREATE_EXPIRE_REJECTED).count() == 1);
assertThat(partitionEventsInState(PartitionState.CREATE_EXPIRED).count()).isEqualTo(0);
assertThat(partitionEventsInState(PartitionState.CREATED).count()).isEqualTo(1);
}
use of io.zeebe.broker.topic.TestPartitionManager.PartitionRequest 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);
}
use of io.zeebe.broker.topic.TestPartitionManager.PartitionRequest in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin.
@Test
public void shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin() {
// given
partitionManager.addMember(SOCKET_ADDRESS1);
partitionManager.addMember(SOCKET_ADDRESS2);
// last member has no management endpoint set yet
partitionManager.currentMembers.add(new Member() {
@Override
public SocketAddress getManagementAddress() {
return null;
}
@Override
public IntIterator getLeadingPartitions() {
return null;
}
});
rule.runStreamProcessor(this::buildStreamProcessor);
// when
rule.writeEvent(createTopic("foo", 4));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 4);
// then
final List<PartitionRequest> requests = partitionManager.getPartitionRequests();
assertThat(requests).extracting(r -> r.endpoint).containsOnly(SOCKET_ADDRESS1, SOCKET_ADDRESS2, SOCKET_ADDRESS1, SOCKET_ADDRESS2);
}
Aggregations