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.
WebSockets Next: provide strategies to process unhandled failures
- resolves quarkusio#40648 - also add WebSocketConnection#closeReason() and WebSocketClientConnection#closeReason()
- Loading branch information
Showing
25 changed files
with
609 additions
and
16 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
35 changes: 35 additions & 0 deletions
35
...ment/src/test/java/io/quarkus/websockets/next/test/client/ClientMessageErrorEndpoint.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,35 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import io.quarkus.websockets.next.OnClose; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocketClient; | ||
|
||
@WebSocketClient(path = "/endpoint") | ||
public class ClientMessageErrorEndpoint { | ||
|
||
static final CountDownLatch MESSAGE_LATCH = new CountDownLatch(1); | ||
|
||
static final List<String> MESSAGES = new CopyOnWriteArrayList<>(); | ||
|
||
static final CountDownLatch CLOSED_LATCH = new CountDownLatch(1); | ||
|
||
@OnTextMessage | ||
void message(String message) { | ||
if ("foo".equals(message)) { | ||
throw new IllegalStateException("I cannot do it!"); | ||
} else { | ||
MESSAGES.add(message); | ||
} | ||
MESSAGE_LATCH.countDown(); | ||
} | ||
|
||
@OnClose | ||
void close() { | ||
CLOSED_LATCH.countDown(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...loyment/src/test/java/io/quarkus/websockets/next/test/client/ClientOpenErrorEndpoint.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,37 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import io.quarkus.websockets.next.OnClose; | ||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocketClient; | ||
|
||
@WebSocketClient(path = "/endpoint") | ||
public class ClientOpenErrorEndpoint { | ||
|
||
static final CountDownLatch MESSAGE_LATCH = new CountDownLatch(1); | ||
|
||
static final List<String> MESSAGES = new CopyOnWriteArrayList<>(); | ||
|
||
static final CountDownLatch CLOSED_LATCH = new CountDownLatch(1); | ||
|
||
@OnOpen | ||
void open() { | ||
throw new IllegalStateException("I cannot do it!"); | ||
} | ||
|
||
@OnTextMessage | ||
void message(String message) { | ||
MESSAGES.add(message); | ||
MESSAGE_LATCH.countDown(); | ||
} | ||
|
||
@OnClose | ||
void close() { | ||
CLOSED_LATCH.countDown(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/ServerEndpoint.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,24 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import io.quarkus.websockets.next.OnClose; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
|
||
@WebSocket(path = "/endpoint") | ||
public class ServerEndpoint { | ||
|
||
static final CountDownLatch CLOSED_LATCH = new CountDownLatch(1); | ||
|
||
@OnTextMessage | ||
String echo(String message) { | ||
return message; | ||
} | ||
|
||
@OnClose | ||
void close() { | ||
CLOSED_LATCH.countDown(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...va/io/quarkus/websockets/next/test/client/UnhandledMessageFailureDefaultStrategyTest.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,47 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.WebSocketClientConnection; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
|
||
public class UnhandledMessageFailureDefaultStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(ServerEndpoint.class, ClientMessageErrorEndpoint.class); | ||
}); | ||
|
||
@Inject | ||
WebSocketConnector<ClientMessageErrorEndpoint> connector; | ||
|
||
@TestHTTPResource("/") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
WebSocketClientConnection connection = connector | ||
.baseUri(testUri) | ||
.connectAndAwait(); | ||
connection.sendTextAndAwait("foo"); | ||
assertTrue(ServerEndpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertTrue(ClientMessageErrorEndpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertTrue(connection.isClosed()); | ||
assertEquals(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code(), connection.closeReason().getCode()); | ||
assertTrue(ClientMessageErrorEndpoint.MESSAGES.isEmpty()); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...t/java/io/quarkus/websockets/next/test/client/UnhandledMessageFailureLogStrategyTest.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,46 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.WebSocketClientConnection; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
|
||
public class UnhandledMessageFailureLogStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(ServerEndpoint.class, ClientMessageErrorEndpoint.class); | ||
}).overrideConfigKey("quarkus.websockets-next.client.unhandled-failure-strategy", "log"); | ||
|
||
@Inject | ||
WebSocketConnector<ClientMessageErrorEndpoint> connector; | ||
|
||
@TestHTTPResource("/") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
WebSocketClientConnection connection = connector | ||
.baseUri(testUri) | ||
.connectAndAwait(); | ||
connection.sendTextAndAwait("foo"); | ||
assertFalse(connection.isClosed()); | ||
connection.sendText("bar"); | ||
assertTrue(ClientMessageErrorEndpoint.MESSAGE_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertEquals("bar", ClientMessageErrorEndpoint.MESSAGES.get(0)); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
.../java/io/quarkus/websockets/next/test/client/UnhandledOpenFailureDefaultStrategyTest.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,46 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.WebSocketClientConnection; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
|
||
public class UnhandledOpenFailureDefaultStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(ServerEndpoint.class, ClientOpenErrorEndpoint.class); | ||
}); | ||
|
||
@Inject | ||
WebSocketConnector<ClientOpenErrorEndpoint> connector; | ||
|
||
@TestHTTPResource("/") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
WebSocketClientConnection connection = connector | ||
.baseUri(testUri) | ||
.connectAndAwait(); | ||
assertTrue(ServerEndpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertTrue(ClientOpenErrorEndpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertTrue(connection.isClosed()); | ||
assertEquals(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code(), connection.closeReason().getCode()); | ||
assertTrue(ClientOpenErrorEndpoint.MESSAGES.isEmpty()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...test/java/io/quarkus/websockets/next/test/client/UnhandledOpenFailureLogStrategyTest.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,47 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.WebSocketClientConnection; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
|
||
public class UnhandledOpenFailureLogStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(ServerEndpoint.class, ClientOpenErrorEndpoint.class); | ||
}).overrideConfigKey("quarkus.websockets-next.client.unhandled-failure-strategy", "log"); | ||
|
||
@Inject | ||
WebSocketConnector<ClientOpenErrorEndpoint> connector; | ||
|
||
@TestHTTPResource("/") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
WebSocketClientConnection connection = connector | ||
.baseUri(testUri) | ||
.connectAndAwait(); | ||
connection.sendTextAndAwait("foo"); | ||
assertFalse(connection.isClosed()); | ||
assertNull(connection.closeReason()); | ||
assertTrue(ClientOpenErrorEndpoint.MESSAGE_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertEquals("foo", ClientOpenErrorEndpoint.MESSAGES.get(0)); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ext/deployment/src/test/java/io/quarkus/websockets/next/test/errors/EchoMessageError.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,23 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
|
||
@WebSocket(path = "/echo") | ||
public class EchoMessageError { | ||
|
||
static final CountDownLatch MESSAGE_FAILURE_CALLED = new CountDownLatch(1); | ||
|
||
@OnTextMessage | ||
String echo(String message) { | ||
if ("foo".equals(message)) { | ||
MESSAGE_FAILURE_CALLED.countDown(); | ||
throw new IllegalStateException("I cannot do it!"); | ||
} else { | ||
return message; | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...s-next/deployment/src/test/java/io/quarkus/websockets/next/test/errors/EchoOpenError.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,25 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
|
||
@WebSocket(path = "/echo") | ||
public class EchoOpenError { | ||
|
||
static final CountDownLatch OPEN_CALLED = new CountDownLatch(1); | ||
|
||
@OnOpen | ||
void open() { | ||
OPEN_CALLED.countDown(); | ||
throw new IllegalStateException("I cannot do it!"); | ||
} | ||
|
||
@OnTextMessage | ||
String echo(String message) { | ||
return message; | ||
} | ||
|
||
} |
Oops, something went wrong.