Search in sources :

Example 1 with PartitionRequest

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);
}
Also used : PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) Test(org.junit.Test)

Example 2 with PartitionRequest

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);
}
Also used : PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) Test(org.junit.Test)

Example 3 with PartitionRequest

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

Example 4 with PartitionRequest

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);
}
Also used : Member(io.zeebe.broker.clustering.member.Member) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) IntIterator(io.zeebe.util.collection.IntIterator) SocketAddress(io.zeebe.transport.SocketAddress) Duration(java.time.Duration) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) Before(org.junit.Before) TopicEvent(io.zeebe.broker.system.log.TopicEvent) TransportHeaderDescriptor(io.zeebe.transport.impl.TransportHeaderDescriptor) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) ResolvePendingPartitionsCommand(io.zeebe.broker.system.log.ResolvePendingPartitionsCommand) TopicsIndex(io.zeebe.broker.system.log.TopicsIndex) PendingPartitionsIndex(io.zeebe.broker.system.log.PendingPartitionsIndex) Test(org.junit.Test) SystemPartitionManager(io.zeebe.broker.system.log.SystemPartitionManager) Instant(java.time.Instant) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) Collectors(java.util.stream.Collectors) TopicState(io.zeebe.broker.system.log.TopicState) PartitionState(io.zeebe.broker.system.log.PartitionState) List(java.util.List) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Ignore(org.junit.Ignore) StreamProcessorRule(io.zeebe.broker.util.StreamProcessorRule) BufferUtil(io.zeebe.util.buffer.BufferUtil) Optional(java.util.Optional) TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) RequestResponseHeaderDescriptor(io.zeebe.transport.impl.RequestResponseHeaderDescriptor) IntIterator(io.zeebe.util.collection.IntIterator) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) SocketAddress(io.zeebe.transport.SocketAddress) Member(io.zeebe.broker.clustering.member.Member) Test(org.junit.Test)

Aggregations

PartitionRequest (io.zeebe.broker.topic.TestPartitionManager.PartitionRequest)4 Test (org.junit.Test)4 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)2 PartitionEvent (io.zeebe.broker.system.log.PartitionEvent)2 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)1 Member (io.zeebe.broker.clustering.member.Member)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1 TypedStreamProcessor (io.zeebe.broker.logstreams.processor.TypedStreamProcessor)1 PartitionState (io.zeebe.broker.system.log.PartitionState)1 PendingPartitionsIndex (io.zeebe.broker.system.log.PendingPartitionsIndex)1 ResolvePendingPartitionsCommand (io.zeebe.broker.system.log.ResolvePendingPartitionsCommand)1 SystemPartitionManager (io.zeebe.broker.system.log.SystemPartitionManager)1 TopicEvent (io.zeebe.broker.system.log.TopicEvent)1 TopicState (io.zeebe.broker.system.log.TopicState)1 TopicsIndex (io.zeebe.broker.system.log.TopicsIndex)1 StreamProcessorRule (io.zeebe.broker.util.StreamProcessorRule)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 SocketAddress (io.zeebe.transport.SocketAddress)1 RequestResponseHeaderDescriptor (io.zeebe.transport.impl.RequestResponseHeaderDescriptor)1