- Notifications
You must be signed in to change notification settings - Fork16
Add test for super stream exchange#357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
acogoluegnes wants to merge2 commits intomainChoose a base branch fromsuper-stream-exchange
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions.github/workflows/test-pr.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletionssrc/test/java/com/rabbitmq/stream/impl/SuperStreamExchangeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Copyright (c) 2023 VMware, Inc. or its affiliates. All rights reserved. | ||
| // | ||
| // This software, the RabbitMQ Stream Java client library, is dual-licensed under the | ||
| // Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL"). | ||
| // For the MPL, please see LICENSE-MPL-RabbitMQ. For the ASL, | ||
| // please see LICENSE-APACHE2. | ||
| // | ||
| // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, | ||
| // either express or implied. See the LICENSE file for specific language governing | ||
| // rights and limitations of this software. | ||
| // | ||
| // If you have any questions regarding licensing, please contact us at | ||
| // info@rabbitmq.com. | ||
| package com.rabbitmq.stream.impl; | ||
| import static com.rabbitmq.stream.impl.TestUtils.*; | ||
| import static com.rabbitmq.stream.impl.TestUtils.SuperStreamExchangeType.SUPER; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import com.rabbitmq.client.AMQP; | ||
| import com.rabbitmq.client.Channel; | ||
| import com.rabbitmq.client.Connection; | ||
| import com.rabbitmq.client.ConnectionFactory; | ||
| import com.rabbitmq.stream.*; | ||
| import io.netty.channel.EventLoopGroup; | ||
| import java.util.*; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.function.BiConsumer;import java.util.stream.IntStream; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInfo; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| @ExtendWith(TestUtils.StreamTestInfrastructureExtension.class) | ||
| public class SuperStreamExchangeTest { | ||
| EventLoopGroup eventLoopGroup; | ||
| Environment environment; | ||
| Connection connection; | ||
| int partitions = 3; | ||
| int messageCount = 10_000; | ||
| String superStream; | ||
| @BeforeEach | ||
| void init(TestInfo info) throws Exception { | ||
| EnvironmentBuilder environmentBuilder = | ||
| Environment.builder().netty().eventLoopGroup(eventLoopGroup).environmentBuilder(); | ||
| environmentBuilder.addressResolver(add -> localhost()); | ||
| environment = environmentBuilder.build(); | ||
| connection = new ConnectionFactory().newConnection(); | ||
| superStream = TestUtils.streamName(info); | ||
| } | ||
| @AfterEach | ||
| void tearDown() throws Exception { | ||
| environment.close(); | ||
| deleteSuperStreamTopology(connection, superStream, partitions); | ||
| connection.close(); | ||
| } | ||
| @Test | ||
| void publish() throws Exception { | ||
| declareSuperStreamTopology(connection, superStream, SUPER, partitions); | ||
| List<String> routingKeys = new ArrayList<>(messageCount); | ||
| IntStream.range(0, messageCount) | ||
| .forEach(ignored -> routingKeys.add(UUID.randomUUID().toString())); | ||
| CountDownLatch publishLatch = new CountDownLatch(messageCount); | ||
| try (Producer producer = | ||
| environment | ||
| .producerBuilder() | ||
| .superStream(superStream) | ||
| .routing(msg -> msg.getProperties().getMessageIdAsString()) | ||
| .producerBuilder() | ||
| .build()) { | ||
| ConfirmationHandler confirmationHandler = status -> publishLatch.countDown(); | ||
| routingKeys.forEach( | ||
| rk -> | ||
| producer.send( | ||
| producer.messageBuilder().properties().messageId(rk).messageBuilder().build(), | ||
| confirmationHandler)); | ||
| latchAssert(publishLatch).completes(); | ||
| } | ||
| java.util.function.Consumer<Map<String, Set<String>>> consumeMessages = | ||
| receivedMessages -> { | ||
| CountDownLatch consumeLatch = new CountDownLatch(messageCount); | ||
| try (Consumer ignored = | ||
| environment | ||
| .consumerBuilder() | ||
| .superStream(superStream) | ||
| .offset(OffsetSpecification.first()) | ||
| .messageHandler( | ||
| (ctx, msg) -> { | ||
| receivedMessages | ||
| .computeIfAbsent(ctx.stream(), k -> ConcurrentHashMap.newKeySet()) | ||
| .add(msg.getProperties().getMessageIdAsString()); | ||
| consumeLatch.countDown(); | ||
| }) | ||
| .build()) { | ||
| latchAssert(consumeLatch).completes(); | ||
| assertThat(receivedMessages.values().stream().mapToInt(Set::size).sum()) | ||
| .isEqualTo(messageCount); | ||
| } | ||
| }; | ||
| Map<String, Set<String>> streamProducerMessages = new ConcurrentHashMap<>(partitions); | ||
| consumeMessages.accept(streamProducerMessages); | ||
| deleteSuperStreamTopology(connection, superStream, partitions); | ||
| declareSuperStreamTopology(connection, superStream, SUPER, partitions); | ||
| try (Channel channel = connection.createChannel()) { | ||
| channel.confirmSelect(); | ||
| for (String rk : routingKeys) { | ||
| channel.basicPublish( | ||
| superStream, rk, new AMQP.BasicProperties.Builder().messageId(rk).build(), null); | ||
| } | ||
| channel.waitForConfirmsOrDie(); | ||
| } | ||
| Map<String, Set<String>> amqpProducerMessages = new ConcurrentHashMap<>(partitions); | ||
| consumeMessages.accept(amqpProducerMessages); | ||
| assertThat(amqpProducerMessages).hasSameSizeAs(streamProducerMessages) | ||
| .containsKeys(streamProducerMessages.keySet().toArray(new String[]{})); | ||
| BiConsumer<Set<String>, Set<String>> compareSets = (s1, s2) -> { | ||
| assertThat(s1).hasSameSizeAs(s2); | ||
| s1.forEach(rk -> assertThat(s2).contains(rk)); | ||
| }; | ||
| amqpProducerMessages.forEach( | ||
| (key, value) -> compareSets.accept(value, streamProducerMessages.get(key))); | ||
| } | ||
| } |
34 changes: 32 additions & 2 deletionssrc/test/java/com/rabbitmq/stream/impl/TestUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.