-
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: add test for virtual threads
- Loading branch information
Showing
4 changed files
with
118 additions
and
2 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
71 changes: 71 additions & 0 deletions
71
...rc/test/java21/io/quarkus/websockets/next/test/virtualthreads/RunOnVirtualThreadTest.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,71 @@ | ||
package io.quarkus.websockets.next.test.virtualthreads; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
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.test.vertx.VirtualThreadsAssertions; | ||
import io.quarkus.websockets.next.OnError; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.smallrye.common.annotation.RunOnVirtualThread; | ||
import io.vertx.core.Vertx; | ||
import jakarta.inject.Inject; | ||
|
||
public class RunOnVirtualThreadTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.virtual-threads.name-prefix=wsnext-virtual-thread-"), | ||
"application.properties"); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end") | ||
URI endUri; | ||
|
||
@Test | ||
void testVirtualThreads() { | ||
try (WSClient client = new WSClient(vertx).connect(endUri)) { | ||
client.sendAndAwait("foo"); | ||
client.sendAndAwait("bar"); | ||
client.waitForMessages(2); | ||
String message1 = client.getMessages().get(0).toString(); | ||
String message2 = client.getMessages().get(1).toString(); | ||
assertNotEquals(message1, message2); | ||
assertTrue(message1.startsWith("wsnext-virtual-thread-")); | ||
assertTrue(message2.startsWith("wsnext-virtual-thread-")); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class Endpoint { | ||
|
||
@RunOnVirtualThread | ||
@OnTextMessage | ||
String text(String ignored) { | ||
VirtualThreadsAssertions.assertEverything(); | ||
return Thread.currentThread().getName(); | ||
} | ||
|
||
@OnError | ||
String error(Throwable t) { | ||
return t.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