-
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.
WebSockets Next: error handlers part 4
- use error handlers to process Mutiny Multi failures - update docs
- Loading branch information
Showing
14 changed files
with
683 additions
and
48 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
68 changes: 68 additions & 0 deletions
68
...est/java/io/quarkus/websockets/next/test/args/OnClosePathParamConnectionArgumentTest.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,68 @@ | ||
package io.quarkus.websockets.next.test.args; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnClose; | ||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.PathParam; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.WebSocketConnection; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.WebSocketConnectOptions; | ||
|
||
public class OnClosePathParamConnectionArgumentTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(MontyEcho.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo/monty/and/foo") | ||
URI testUri; | ||
|
||
@Test | ||
void testArguments() throws InterruptedException { | ||
String header = "fool"; | ||
WSClient client = WSClient.create(vertx).connect(new WebSocketConnectOptions().addHeader("X-Test", header), testUri); | ||
client.disconnect(); | ||
assertTrue(MontyEcho.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertEquals("foo:monty:fool", MontyEcho.CLOSED_MESSAGE.get()); | ||
} | ||
|
||
@WebSocket(path = "/echo/{grail}/and/{life}") | ||
public static class MontyEcho { | ||
|
||
static final CountDownLatch CLOSED_LATCH = new CountDownLatch(1); | ||
static final AtomicReference<String> CLOSED_MESSAGE = new AtomicReference<>(); | ||
|
||
@OnOpen | ||
void open() { | ||
} | ||
|
||
@OnClose | ||
void close(@PathParam String life, @PathParam String grail, WebSocketConnection connection) { | ||
CLOSED_MESSAGE.set(life + ":" + grail + ":" + connection.handshakeRequest().header("X-Test")); | ||
CLOSED_LATCH.countDown(); | ||
} | ||
|
||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...test/java/io/quarkus/websockets/next/test/args/OnOpenPathParamConnectionArgumentTest.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.args; | ||
|
||
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.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.PathParam; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.WebSocketConnection; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.WebSocketConnectOptions; | ||
|
||
public class OnOpenPathParamConnectionArgumentTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(MontyEcho.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo/monty/and/foo") | ||
URI testUri; | ||
|
||
@Test | ||
void testArguments() { | ||
String header = "fool"; | ||
WSClient client = WSClient.create(vertx).connect(new WebSocketConnectOptions().addHeader("X-Test", header), testUri); | ||
client.waitForMessages(1); | ||
assertEquals("foo:monty:fool", client.getMessages().get(0).toString()); | ||
} | ||
|
||
@WebSocket(path = "/echo/{grail}/and/{life}") | ||
public static class MontyEcho { | ||
|
||
@OnOpen | ||
String process(@PathParam String life, @PathParam String grail, WebSocketConnection connection) { | ||
return life + ":" + grail + ":" + connection.handshakeRequest().header("X-Test"); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.