public async Task when_message_published_to_kafka_topic_it_should_be_received_by_properly_configured_poezd() { var timeoutOrDoneSource = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)); var doneOrTimeout = timeoutOrDoneSource.Token; var topic = RoutingTests.GetRandomTopic(); await using var kafkaTestContext = _kafkaTestContextFactory.Create <string, string>(doneOrTimeout); await kafkaTestContext.CreateTopics(topic); var enterProperties = new MessageLoggingStep.Properties(); var exitProperties = new MessageCountingStep.Properties(expectedMessageCount: 2, timeoutOrDoneSource); var publishedKey1 = CreateString(length: 10); var publishedPayload1 = CreateString(length: 10); await ProduceMessage( topic, publishedKey1, publishedPayload1, kafkaTestContext); var container = BuildContainerToHandleMessages(enterProperties, exitProperties); container.RegisterSingleton( () => CreateMessageRouterConfigurationToHandleMessages().CreateMessageRouter(new SimpleInjectorAdapter(container))); await container.GetInstance <IMessageRouter>().Start(doneOrTimeout); var publishedKey2 = CreateString(length: 20); var publishedPayload2 = CreateString(length: 20); await ProduceMessage( topic, publishedKey2, publishedPayload2, kafkaTestContext); await doneOrTimeout; enterProperties.Messages.Select(message => (string)message.Key).Should().Equal( new[] { publishedKey1, publishedKey2 }, "these messages were published in this order"); enterProperties.Messages.Select(message => (string)message.Value).Should().Equal( new[] { publishedPayload1, publishedPayload2 }, "these messages were published in this order"); }
public async Task when_message_published_to_kafka_topic_it_should_be_received_from_same_topic() { var topic = RoutingTests.GetRandomTopic(); var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)).Token; await using var kafkaTestContext = _kafkaTestContextFactory.Create <string, string>(timeout); await kafkaTestContext.CreateTopics(topic); var expectedValue = RoutingTests.GetRandomString(); await kafkaTestContext.Produce( topic, string.Empty, expectedValue, new Dictionary <string, byte[]> { { "header1", new byte[0] } }); var consumeResult = kafkaTestContext.Consume(topic); consumeResult.Message.Value.Should().Be(expectedValue, "this thing was sent"); consumeResult.Message.Headers.Count.Should().Be(expected: 1, "one header was set"); }