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
- Loading branch information
Showing
14 changed files
with
306 additions
and
13 deletions.
There are no files selected for viewing
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_CALLED = new CountDownLatch(1); | ||
|
||
@OnTextMessage | ||
String echo(String message) { | ||
if ("foo".equals(message)) { | ||
MESSAGE_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; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...va/io/quarkus/websockets/next/test/errors/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,46 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.awaitility.Awaitility; | ||
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.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class UnhandledMessageFailureDefaultStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(EchoMessageError.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(testUri)) { | ||
client.sendAndAwait("foo"); | ||
assertTrue(EchoMessageError.MESSAGE_CALLED.await(5, TimeUnit.SECONDS)); | ||
Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> client.isClosed()); | ||
assertEquals(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code(), client.closeStatusCode()); | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...t/java/io/quarkus/websockets/next/test/errors/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,44 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
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.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class UnhandledMessageFailureLogStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(EchoMessageError.class, WSClient.class); | ||
}).overrideConfigKey("quarkus.websockets-next.server.unhandled-failure-strategy", "log"); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo") | ||
URI testUri; | ||
|
||
@Test | ||
void testErrorDoesNotCloseConnection() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(testUri)) { | ||
client.sendAndAwait("foo"); | ||
assertTrue(EchoMessageError.MESSAGE_CALLED.await(5, TimeUnit.SECONDS)); | ||
client.sendAndAwait("bar"); | ||
client.waitForMessages(1); | ||
assertEquals("bar", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
.../java/io/quarkus/websockets/next/test/errors/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,45 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.awaitility.Awaitility; | ||
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.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class UnhandledOpenFailureDefaultStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(EchoOpenError.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo") | ||
URI testUri; | ||
|
||
@Test | ||
void testError() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(testUri)) { | ||
assertTrue(EchoOpenError.OPEN_CALLED.await(5, TimeUnit.SECONDS)); | ||
Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> client.isClosed()); | ||
assertEquals(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code(), client.closeStatusCode()); | ||
} | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...test/java/io/quarkus/websockets/next/test/errors/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,43 @@ | ||
package io.quarkus.websockets.next.test.errors; | ||
|
||
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.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class UnhandledOpenFailureLogStrategyTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(EchoOpenError.class, WSClient.class); | ||
}).overrideConfigKey("quarkus.websockets-next.server.unhandled-failure-strategy", "log"); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("echo") | ||
URI testUri; | ||
|
||
@Test | ||
void testErrorDoesNotCloseConnection() throws InterruptedException { | ||
try (WSClient client = WSClient.create(vertx).connect(testUri)) { | ||
assertTrue(EchoOpenError.OPEN_CALLED.await(5, TimeUnit.SECONDS)); | ||
client.sendAndAwait("foo"); | ||
client.waitForMessages(1); | ||
assertEquals("foo", client.getLastMessage().toString()); | ||
} | ||
} | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
...ckets-next/runtime/src/main/java/io/quarkus/websockets/next/UnhandledFailureStrategy.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,20 @@ | ||
package io.quarkus.websockets.next; | ||
|
||
/** | ||
* The strategy used when an error occurs but no error handler can handle the failure. | ||
*/ | ||
public enum UnhandledFailureStrategy { | ||
/** | ||
* Close the connection. | ||
*/ | ||
CLOSE, | ||
/** | ||
* Log an error message. | ||
*/ | ||
LOG, | ||
/** | ||
* No operation. | ||
*/ | ||
NOOP; | ||
|
||
} |
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
Oops, something went wrong.