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.
Merge pull request quarkusio#40207 from mkouba/issue-39862
WebSockets Next: send ping message from the server automatically
- Loading branch information
Showing
10 changed files
with
147 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
77 changes: 77 additions & 0 deletions
77
...ployment/src/test/java/io/quarkus/websockets/next/test/pingpong/AutoPingIntervalTest.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,77 @@ | ||
package io.quarkus.websockets.next.test.pingpong; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutionException; | ||
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.OnOpen; | ||
import io.quarkus.websockets.next.OnPongMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.WebSocketClient; | ||
|
||
public class AutoPingIntervalTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class); | ||
}).overrideConfigKey("quarkus.websockets-next.server.auto-ping-interval", "200ms"); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
public void testPingPong() throws InterruptedException, ExecutionException { | ||
WebSocketClient client = vertx.createWebSocketClient(); | ||
try { | ||
CountDownLatch connectedLatch = new CountDownLatch(1); | ||
client | ||
.connect(endUri.getPort(), endUri.getHost(), endUri.getPath()) | ||
.onComplete(r -> { | ||
if (r.succeeded()) { | ||
connectedLatch.countDown(); | ||
} else { | ||
throw new IllegalStateException(r.cause()); | ||
} | ||
}); | ||
assertTrue(connectedLatch.await(5, TimeUnit.SECONDS)); | ||
// The pong message should be sent by the client automatically and should be identical to the ping message | ||
assertTrue(Endpoint.PONG.await(5, TimeUnit.SECONDS)); | ||
} finally { | ||
client.close().toCompletionStage().toCompletableFuture().get(); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
static final CountDownLatch PONG = new CountDownLatch(3); | ||
|
||
@OnOpen | ||
public String open() { | ||
return "ok"; | ||
} | ||
|
||
@OnPongMessage | ||
void pong(Buffer data) { | ||
PONG.countDown(); | ||
} | ||
|
||
} | ||
|
||
} |
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
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
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