forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConsumeEvent - defer request context destruction for async return types
- resolves quarkusio#14595
- Loading branch information
Showing
4 changed files
with
259 additions
and
86 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
104 changes: 104 additions & 0 deletions
104
...x/deployment/src/test/java/io/quarkus/vertx/deployment/RequestContextTerminationTest.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,104 @@ | ||
package io.quarkus.vertx.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.ConsumeEvent; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.eventbus.EventBus; | ||
|
||
public class RequestContextTerminationTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(SimpleBean.class)); | ||
|
||
@Inject | ||
EventBus eventBus; | ||
|
||
@Test | ||
public void testTermination() throws InterruptedException { | ||
assertTerminated("foo"); | ||
assertTerminated("foo-cs"); | ||
assertTerminated("foo-uni"); | ||
} | ||
|
||
void assertTerminated(String address) throws InterruptedException { | ||
BlockingQueue<Object> synchronizer = new LinkedBlockingQueue<>(); | ||
Converter.DESTROYED.set(false); | ||
eventBus.request(address, "bongo", ar -> { | ||
if (ar.succeeded()) { | ||
try { | ||
synchronizer.put(ar.result().body()); | ||
} catch (InterruptedException e) { | ||
fail(e); | ||
} | ||
} else { | ||
fail(ar.cause()); | ||
} | ||
}); | ||
assertEquals("BONGO", synchronizer.poll(2, TimeUnit.SECONDS)); | ||
assertTrue(Converter.DESTROYED.get()); | ||
} | ||
|
||
@Test | ||
public void testFailureNoReplyHandler() throws InterruptedException { | ||
} | ||
|
||
static class SimpleBean { | ||
|
||
@Inject | ||
Converter converter; | ||
|
||
@ConsumeEvent("foo") | ||
String foo(String message) { | ||
return converter.convert(message); | ||
} | ||
|
||
@ConsumeEvent("foo-cs") | ||
CompletionStage<String> asyncFoo(String message) { | ||
return CompletableFuture.completedFuture(converter.convert(message)); | ||
} | ||
|
||
@ConsumeEvent("foo-uni") | ||
Uni<String> asyncFooUni(String message) { | ||
return Uni.createFrom().item(converter.convert(message)); | ||
} | ||
|
||
} | ||
|
||
@RequestScoped | ||
static class Converter { | ||
|
||
static final AtomicBoolean DESTROYED = new AtomicBoolean(); | ||
|
||
String convert(String val) { | ||
return val.toUpperCase(); | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
DESTROYED.set(true); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.