-
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.
Merge pull request #43915 from mkouba/ws-next-request-context-optimiz…
…ation WebSockets Next: activate CDI request context only if needed
- Loading branch information
Showing
16 changed files
with
416 additions
and
23 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
54 changes: 54 additions & 0 deletions
54
.../test/java/io/quarkus/websockets/next/test/requestcontext/ActivateRequestContextTest.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,54 @@ | ||
package io.quarkus.websockets.next.test.requestcontext; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.enterprise.context.control.ActivateRequestContext; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class ActivateRequestContextTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
void testRequestContext() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(endUri)) { | ||
client.sendAndAwait("ping"); | ||
client.waitForMessages(1); | ||
assertEquals("pong:true", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
@ActivateRequestContext // the request context should not be activated by WS next | ||
@OnTextMessage | ||
String process(String message) { | ||
return "pong:" + Arc.container().requestContext().isActive(); | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...io/quarkus/websockets/next/test/requestcontext/RequestContextActivatedByInstanceTest.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,56 @@ | ||
package io.quarkus.websockets.next.test.requestcontext; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class RequestContextActivatedByInstanceTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class, RequestScopedBean.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
void testRequestContext() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(endUri)) { | ||
client.sendAndAwait("ping"); | ||
client.waitForMessages(1); | ||
assertEquals("pong:true", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
@Inject | ||
Instance<RequestScopedBean> instance; | ||
|
||
@OnTextMessage | ||
String process(String message) { | ||
return "pong:" + Arc.container().requestContext().isActive(); | ||
} | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...ava/io/quarkus/websockets/next/test/requestcontext/RequestContextActivatedByListTest.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,57 @@ | ||
package io.quarkus.websockets.next.test.requestcontext; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.All; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class RequestContextActivatedByListTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class, RequestScopedBean.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
void testRequestContext() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(endUri)) { | ||
client.sendAndAwait("ping"); | ||
client.waitForMessages(1); | ||
assertEquals("pong:true", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
@All | ||
List<RequestScopedBean> list; | ||
|
||
@OnTextMessage | ||
String process(String message) { | ||
return "pong:" + Arc.container().requestContext().isActive(); | ||
} | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...t/java/io/quarkus/websockets/next/test/requestcontext/RequestContextAlwaysActiveTest.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,53 @@ | ||
package io.quarkus.websockets.next.test.requestcontext; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class RequestContextAlwaysActiveTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class); | ||
}) | ||
.overrideConfigKey("quarkus.websockets-next.server.activate-request-context", "always"); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
void testRequestContext() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(endUri)) { | ||
client.sendAndAwait("ping"); | ||
client.waitForMessages(1); | ||
assertEquals("pong:true", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
@OnTextMessage | ||
String process(String message) { | ||
return "pong:" + Arc.container().requestContext().isActive(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.