Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSockets Next: always use the managed Vertx instance in tests #40696

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public ArcContainer initContainer(ShutdownContext shutdown, RuntimeValue<Current
@Override
public void run() {
Arc.shutdown();
syntheticBeanProviders = null;
}
});
return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -21,6 +23,9 @@

public class EchoWebSocketTest {

@Inject
Vertx vertx;

@TestHTTPResource("echo")
URI echoUri;

Expand Down Expand Up @@ -127,7 +132,6 @@ public void assertEcho(URI testUri, String payload) throws Exception {
}

public void assertEcho(URI testUri, String payload, BiConsumer<WebSocket, Queue<String>> action) throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -20,21 +22,23 @@

public class BroadcastConnectionTest {

@TestHTTPResource("lo-connection")
URI loConnectionUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(LoConnection.class);
});

@TestHTTPResource("lo-connection")
URI loConnectionUri;

@Inject
Vertx vertx;

@Test
public void testBroadcast() throws Exception {
WebSocketClient client1 = null, client2 = null, client3 = null;
try {
List<String> messages = new CopyOnWriteArrayList<>();
Vertx vertx = Vertx.vertx();
client1 = connect(vertx, "C1", messages);
client2 = connect(vertx, "C2", messages);
client3 = connect(vertx, "C3", messages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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;

Expand All @@ -21,6 +23,12 @@

public class BroadcastOnMessageTest {

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Up.class, UpBlocking.class, UpMultiBidi.class);
});

@TestHTTPResource("up")
URI upUri;

Expand All @@ -30,11 +38,8 @@ public class BroadcastOnMessageTest {
@TestHTTPResource("up-multi-bidi")
URI upMultiBidiUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Up.class, UpBlocking.class, UpMultiBidi.class);
});
@Inject
Vertx vertx;

@Test
public void testUp() throws Exception {
Expand All @@ -52,7 +57,6 @@ public void testUpMultiBidi() throws Exception {
}

public void assertBroadcast(URI testUri) throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client1 = vertx.createWebSocketClient();
WebSocketClient client2 = vertx.createWebSocketClient();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -20,6 +22,12 @@

public class BroadcastOnOpenTest {

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Lo.class, LoBlocking.class, LoMultiProduce.class);
});

@TestHTTPResource("lo")
URI loUri;

Expand All @@ -29,11 +37,8 @@ public class BroadcastOnOpenTest {
@TestHTTPResource("lo-multi-produce")
URI loMultiProduceUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Lo.class, LoBlocking.class, LoMultiProduce.class);
});
@Inject
Vertx vertx;

@Test
public void testLo() throws Exception {
Expand All @@ -51,7 +56,6 @@ public void testLoMultiBidi() throws Exception {
}

public void assertBroadcast(URI testUri) throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client1 = vertx.createWebSocketClient();
WebSocketClient client2 = vertx.createWebSocketClient();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -20,16 +22,19 @@

public class BinaryCodecTest {

@TestHTTPResource("find-binary")
URI findBinaryUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(FindBinary.class, AbstractFind.class, Item.class, FindBinary.ItemBinaryMessageCodec.class,
FindBinary.ListItemBinaryMessageCodec.class);
});

@TestHTTPResource("find-binary")
URI findBinaryUri;

@Inject
Vertx vertx;

@Test
public void testCodec() throws Exception {
JsonArray items = new JsonArray();
Expand All @@ -41,7 +46,6 @@ public void testCodec() throws Exception {

public void assertCodec(URI testUri, Buffer payload, Buffer expected)
throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<Buffer> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,15 +21,18 @@

public class CustomCodecTest {

@TestHTTPResource("find")
URI findUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Find.class, Item.class, AbstractFind.class, MyItemCodec.class);
});

@TestHTTPResource("find")
URI findUri;

@Inject
Vertx vertx;

@Test
public void testCodec() throws Exception {
JsonArray items = new JsonArray();
Expand All @@ -39,7 +44,6 @@ public void testCodec() throws Exception {

public void assertCodec(URI testUri, String payload, String expected)
throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,15 +21,18 @@

public class DefaultTextCodecTest {

@TestHTTPResource("find")
URI findUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(Find.class, AbstractFind.class, Item.class);
});

@TestHTTPResource("find")
URI findUri;

@Inject
Vertx vertx;

@Test
public void testCodec() throws Exception {
JsonArray items = new JsonArray();
Expand All @@ -39,7 +44,6 @@ public void testCodec() throws Exception {

public void assertCodec(URI testUri, String payload, String expected)
throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,15 +21,18 @@

public class TextInputCodecTest {

@TestHTTPResource("find-input-codec")
URI itemCodecUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(FindInputCodec.class, FindInputCodec.MyInputCodec.class, AbstractFind.class, Item.class);
});

@TestHTTPResource("find-input-codec")
URI itemCodecUri;

@Inject
Vertx vertx;

@Test
public void testCodec() throws Exception {
JsonArray items = new JsonArray();
Expand All @@ -39,7 +44,6 @@ public void testCodec() throws Exception {

public void assertCodec(URI testUri, String payload, String expected)
throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,15 +21,18 @@

public class TextOutputCodecTest {

@TestHTTPResource("find-output-codec")
URI itemCodecUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(root -> {
root.addClasses(FindOutputCodec.class, FindOutputCodec.MyOutputCodec.class, AbstractFind.class, Item.class);
});

@Inject
Vertx vertx;

@TestHTTPResource("find-output-codec")
URI itemCodecUri;

@Test
public void testCodec() throws Exception {
JsonArray items = new JsonArray();
Expand All @@ -39,7 +44,6 @@ public void testCodec() throws Exception {

public void assertCodec(URI testUri, String payload, String expected)
throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,6 +21,9 @@

public class SubWebSocketTest {

@Inject
Vertx vertx;

@TestHTTPResource("sub")
URI echoUri;

Expand All @@ -44,7 +49,6 @@ public void testSubSubSub() throws Exception {
}

public void assertEcho(URI testUri, String path, String payload, String expected) throws Exception {
Vertx vertx = Vertx.vertx();
WebSocketClient client = vertx.createWebSocketClient();
try {
LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Expand Down
Loading