-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test verifying back pressure for RabbitMQ consumption
- Loading branch information
1 parent
a303391
commit 4891f83
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
88 changes: 88 additions & 0 deletions
88
...-rabbitmq/src/test/java/io/smallrye/reactive/messaging/rabbitmq/ConsumerBackPressure.java
This file contains 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,88 @@ | ||
package io.smallrye.reactive.messaging.rabbitmq; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.helpers.test.AssertSubscriber; | ||
import io.smallrye.reactive.messaging.MutinyEmitter; | ||
import io.smallrye.reactive.messaging.providers.extension.HealthCenter; | ||
import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import org.eclipse.microprofile.reactive.messaging.Channel; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
public class ConsumerBackPressure extends WeldTestBase { | ||
|
||
private MapBasedConfig getBaseConfig() { | ||
return new MapBasedConfig() | ||
.with("mp.messaging.outgoing.to-rabbitmq.connector", RabbitMQConnector.CONNECTOR_NAME) | ||
.with("mp.messaging.outgoing.to-rabbitmq.exchange.name", exchange) | ||
|
||
.with("mp.messaging.incoming.from-rabbitmq.connector", RabbitMQConnector.CONNECTOR_NAME) | ||
.with("mp.messaging.incoming.from-rabbitmq.queue.name", queue) | ||
.with("mp.messaging.incoming.from-rabbitmq.queue.durable", true) | ||
|
||
.with("mp.messaging.incoming.from-rabbitmq.exchange.name", exchange); | ||
} | ||
|
||
@Test | ||
void testConsumerBackpressure() { | ||
addBeans(Publisher.class, Subscriber.class); | ||
runApplication(getBaseConfig()); | ||
|
||
Subscriber subscriber = container.getBeanManager().createInstance().select(Subscriber.class).get(); | ||
Publisher publisher = container.getBeanManager().createInstance().select(Publisher.class).get(); | ||
|
||
AssertSubscriber<Object> consumer = AssertSubscriber.create(0); | ||
subscriber.getMulti().subscribe().withSubscriber(consumer); | ||
|
||
HealthCenter health = container.getBeanManager().createInstance().select(HealthCenter.class).get(); | ||
assertThat(health.getLiveness().isOk()).isTrue(); | ||
|
||
publisher.generate(); | ||
|
||
AtomicInteger i = new AtomicInteger(1); | ||
while(consumer.getItems().size() < 10000) { | ||
consumer.request(100); | ||
await().until(() -> consumer.getItems().size() == 100 * i.get()); | ||
i.getAndIncrement(); | ||
} | ||
await().until(() -> consumer.getItems().size() == 10000); | ||
|
||
} | ||
|
||
|
||
@ApplicationScoped | ||
public static class Publisher { | ||
|
||
@Inject @Channel("to-rabbitmq") | ||
MutinyEmitter<String> emitter; | ||
|
||
public void generate() { | ||
for (int i = 0; i < 10000; i++) { | ||
emitter.sendAndAwait(Integer.toString(i)); | ||
} | ||
} | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class Subscriber { | ||
|
||
@Inject @Channel("from-rabbitmq") Multi<String> multi; | ||
|
||
public Multi<String> getMulti() { | ||
return multi; | ||
} | ||
} | ||
|
||
} |