Search in sources :

Example 1 with PartitionEvent

use of io.zeebe.broker.system.log.PartitionEvent in project zeebe by zeebe-io.

the class CreateDeploymentStreamProcessorTest method partitionCreated.

protected PartitionEvent partitionCreated(String topicName, int partitionId) {
    final PartitionEvent event = new PartitionEvent();
    event.setState(PartitionState.CREATED);
    event.setTopicName(BufferUtil.wrapString(topicName));
    event.setId(partitionId);
    event.setCreator(BufferUtil.wrapString("host"), 1234);
    return event;
}
Also used : PartitionEvent(io.zeebe.broker.system.log.PartitionEvent)

Example 2 with PartitionEvent

use of io.zeebe.broker.system.log.PartitionEvent 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 3 with PartitionEvent

use of io.zeebe.broker.system.log.PartitionEvent in project zeebe by zeebe-io.

the class CreateTopicStreamProcessorTest method shouldNotCreatePartitionsOnRejection.

@Test
public void shouldNotCreatePartitionsOnRejection() {
    // given
    partitionManager.addMember(SOCKET_ADDRESS1);
    rule.runStreamProcessor(this::buildStreamProcessor);
    rule.writeEvent(createTopic("foo", 1));
    final PartitionEvent creatingEvent = doRepeatedly(() -> partitionEventsInState(PartitionState.CREATING).findFirst()).until(Optional::isPresent).get().getValue();
    partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, creatingEvent.getId());
    streamProcessor.runAsync(checkPartitionsCmd);
    waitUntil(() -> topicEventsInState(TopicState.CREATED).findFirst().isPresent());
    // when creating the same topic again
    rule.writeEvent(createTopic("foo", 1));
    // then
    waitUntil(() -> topicEventsInState(TopicState.CREATE_REJECTED).findFirst().isPresent());
    // only the first create topic command resulted in a partition
    assertThat(partitionEventsInState(PartitionState.CREATE).count()).isEqualTo(1);
}
Also used : Optional(java.util.Optional) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) Test(org.junit.Test)

Example 4 with PartitionEvent

use of io.zeebe.broker.system.log.PartitionEvent in project zeebe by zeebe-io.

the class CreateTopicStreamProcessorTest method shouldSetCreationExpirationTimeInEvent.

@Test
public void shouldSetCreationExpirationTimeInEvent() {
    // given
    rule.getClock().pinCurrentTime();
    partitionManager.addMember(SOCKET_ADDRESS1);
    rule.runStreamProcessor(this::buildStreamProcessor);
    // when
    rule.writeEvent(createTopic("foo", 1));
    waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 1);
    // then
    final PartitionEvent creatingEvent = partitionEventsInState(PartitionState.CREATING).findFirst().get().getValue();
    final Instant expectedExpirationTime = rule.getClock().getCurrentTime().plus(CREATION_EXPIRATION);
    assertThat(creatingEvent.getCreationTimeout()).isEqualTo(expectedExpirationTime.toEpochMilli());
}
Also used : Instant(java.time.Instant) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) Test(org.junit.Test)

Example 5 with PartitionEvent

use of io.zeebe.broker.system.log.PartitionEvent in project zeebe by zeebe-io.

the class CreateTopicStreamProcessorTest method shouldPersistCreatingBrokerInPartitionCreateEvent.

@Test
public void shouldPersistCreatingBrokerInPartitionCreateEvent() {
    // given
    partitionManager.addMember(SOCKET_ADDRESS1);
    final StreamProcessorControl processorControl = rule.runStreamProcessor(this::buildStreamProcessor);
    processorControl.blockAfterTopicEvent(e -> e.getValue().getState() == TopicState.CREATE);
    rule.writeEvent(createTopic("foo", 1));
    // when
    waitUntil(() -> partitionEventsInState(PartitionState.CREATE).findFirst().isPresent());
    // then
    final PartitionEvent partitionEvent = partitionEventsInState(PartitionState.CREATE).findFirst().get().getValue();
    final TopologyBroker creator = partitionEvent.getCreator();
    assertThat(creator.getHost()).isEqualTo(SOCKET_ADDRESS1.getHostBuffer());
    assertThat(creator.getPort()).isEqualTo(SOCKET_ADDRESS1.port());
}
Also used : PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) Test(org.junit.Test)

Aggregations

PartitionEvent (io.zeebe.broker.system.log.PartitionEvent)6 Test (org.junit.Test)4 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)1 PartitionRequest (io.zeebe.broker.topic.TestPartitionManager.PartitionRequest)1 Instant (java.time.Instant)1 Optional (java.util.Optional)1