Search in sources :

Example 1 with RequestResponseHeaderDescriptor

use of io.zeebe.transport.impl.RequestResponseHeaderDescriptor in project zeebe by zeebe-io.

the class CreateTopicStreamProcessorTest method shouldCreateTopicsWithInterleavingRequests.

@Test
public void shouldCreateTopicsWithInterleavingRequests() {
    // given
    partitionManager.addMember(SOCKET_ADDRESS1);
    final long request1 = 42;
    final long request2 = 52;
    rule.newEvent().event(createTopic("foo", 2)).metadata(m -> m.requestId(request1)).write();
    rule.newEvent().event(createTopic("bar", 2)).metadata(m -> m.requestId(request2)).write();
    rule.runStreamProcessor(this::buildStreamProcessor);
    waitUntil(() -> partitionManager.getPartitionRequests().size() == 4);
    partitionManager.getPartitionRequests().forEach(r -> partitionManager.declarePartitionLeader(SOCKET_ADDRESS1, r.getPartitionId()));
    // when
    streamProcessor.runAsync(checkPartitionsCmd);
    // then
    waitUntil(() -> rule.getOutput().getSentResponses().size() >= 2);
    final RequestResponseHeaderDescriptor responseHeader = new RequestResponseHeaderDescriptor();
    final List<Long> respondedRequests = rule.getOutput().getSentResponses().stream().map(b -> responseHeader.wrap(b, TransportHeaderDescriptor.headerLength()).requestId()).collect(Collectors.toList());
    assertThat(respondedRequests).containsExactlyInAnyOrder(request1, request2);
}
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) RequestResponseHeaderDescriptor(io.zeebe.transport.impl.RequestResponseHeaderDescriptor) Test(org.junit.Test)

Aggregations

TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)1 Member (io.zeebe.broker.clustering.member.Member)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1 TypedStreamProcessor (io.zeebe.broker.logstreams.processor.TypedStreamProcessor)1 PartitionEvent (io.zeebe.broker.system.log.PartitionEvent)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 PartitionRequest (io.zeebe.broker.topic.TestPartitionManager.PartitionRequest)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 TransportHeaderDescriptor (io.zeebe.transport.impl.TransportHeaderDescriptor)1