-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Messaging extensions default execution mode to worker thread for the …
…signatures considered blocking
- Loading branch information
1 parent
a634bc4
commit 01b2ff4
Showing
5 changed files
with
264 additions
and
8 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
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
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
177 changes: 177 additions & 0 deletions
177
.../io/quarkus/smallrye/reactivemessaging/signatures/BlockingSignatureExecutionModeTest.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,177 @@ | ||
package io.quarkus.smallrye.reactivemessaging.signatures; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.Flow; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.smallrye.reactivemessaging.config.DumbConnector; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.common.annotation.NonBlocking; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class BlockingSignatureExecutionModeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(DumbConnector.class, | ||
ProducerOnC.class, | ||
BlockingConsumerFromConnector.class, | ||
ConsumerFromConnector.class, | ||
ConsumerFromInnerChannel.class)) | ||
.overrideConfigKey("mp.messaging.incoming.a.connector", "dummy") | ||
.overrideConfigKey("mp.messaging.incoming.a.values", "bonjour") | ||
.overrideConfigKey("mp.messaging.incoming.b.connector", "dummy") | ||
.overrideConfigKey("mp.messaging.incoming.b.values", "bonjour") | ||
.overrideConfigKey("mp.messaging.incoming.c.connector", "dummy") | ||
.overrideConfigKey("mp.messaging.incoming.c.values", "bonjour"); | ||
|
||
@Inject | ||
BlockingConsumerFromConnector blockingConsumerFromConnector; | ||
|
||
@Test | ||
public void testBlockingSignatureFromConnector() { | ||
await().until(() -> blockingConsumerFromConnector.list().size() == 2); | ||
List<String> threadNames = blockingConsumerFromConnector.threads().stream().distinct().toList(); | ||
assertThat(threadNames.contains(Thread.currentThread().getName())).isFalse(); | ||
for (String name : threadNames) { | ||
assertThat(name.startsWith("executor-thread-")).isTrue(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class BlockingConsumerFromConnector { | ||
private final List<String> list = new CopyOnWriteArrayList<>(); | ||
private final List<String> threads = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("a") | ||
public void produce(String s) { | ||
threads.add(Thread.currentThread().getName()); | ||
list.add(s); | ||
} | ||
|
||
public List<String> threads() { | ||
return threads; | ||
} | ||
|
||
public List<String> list() { | ||
return list; | ||
} | ||
} | ||
|
||
@Inject | ||
ConsumerFromConnector consumerFromConnector; | ||
|
||
@Test | ||
public void testNonBlockingSignatureFromConnector() { | ||
await().until(() -> consumerFromConnector.list().size() == 2); | ||
List<String> threadNames = consumerFromConnector.threads().stream().distinct().toList(); | ||
assertThat(threadNames).containsOnly(Thread.currentThread().getName()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class ConsumerFromConnector { | ||
private final List<String> list = new CopyOnWriteArrayList<>(); | ||
private final List<String> threads = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("b") | ||
public Uni<Void> produce(String s) { | ||
threads.add(Thread.currentThread().getName()); | ||
list.add(s); | ||
return Uni.createFrom().voidItem(); | ||
} | ||
|
||
public List<String> threads() { | ||
return threads; | ||
} | ||
|
||
public List<String> list() { | ||
return list; | ||
} | ||
} | ||
|
||
@Inject | ||
NonBlockingConsumerFromConnector nonBlockingConsumerFromConnector; | ||
|
||
@Test | ||
public void testNonBlockingAnnotationFromConnector() { | ||
await().until(() -> nonBlockingConsumerFromConnector.list().size() == 2); | ||
List<String> threadNames = nonBlockingConsumerFromConnector.threads().stream().distinct().toList(); | ||
assertThat(threadNames).containsOnly(Thread.currentThread().getName()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class NonBlockingConsumerFromConnector { | ||
private final List<String> list = new CopyOnWriteArrayList<>(); | ||
private final List<String> threads = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("c") | ||
@NonBlocking | ||
public void produce(String s) { | ||
threads.add(Thread.currentThread().getName()); | ||
list.add(s); | ||
} | ||
|
||
public List<String> threads() { | ||
return threads; | ||
} | ||
|
||
public List<String> list() { | ||
return list; | ||
} | ||
} | ||
|
||
@Inject | ||
ConsumerFromInnerChannel consumerFromInnerChannel; | ||
|
||
@Test | ||
public void testBlockingSignatureFromInnerChannel() { | ||
await().until(() -> consumerFromInnerChannel.list().size() == 3); | ||
assertThat(consumerFromInnerChannel.list()).containsExactly("d", "e", "f"); | ||
List<String> threadNames = consumerFromInnerChannel.threads().stream().distinct().toList(); | ||
assertThat(threadNames).containsOnly(Thread.currentThread().getName()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class ConsumerFromInnerChannel { | ||
|
||
private final List<String> list = new CopyOnWriteArrayList<>(); | ||
private final List<String> threads = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("d") | ||
public void produce(String s) { | ||
threads.add(Thread.currentThread().getName()); | ||
list.add(s); | ||
} | ||
|
||
public List<String> threads() { | ||
return threads; | ||
} | ||
|
||
public List<String> list() { | ||
return list; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
private static class ProducerOnC { | ||
|
||
@Outgoing("d") | ||
public Flow.Publisher<String> produce() { | ||
return Multi.createFrom().items("d", "e", "f"); | ||
} | ||
|
||
} | ||
} |
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