diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyIT.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyIT.java new file mode 100644 index 0000000000000..ffc64e0de5efb --- /dev/null +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyIT.java @@ -0,0 +1,45 @@ +package com.example.grpc.hibernate; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; + +import com.example.test.MutinyTestGrpc; +import com.example.test.Test; +import com.example.test.TestClient; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class BlockingMutinyIT extends BlockingMutinyTestBase { + + @BeforeAll + static void init() { + GrpcIntegrationTestHelper.init(); + } + + @AfterAll + static void cleanup() { + GrpcIntegrationTestHelper.cleanup(); + } + + @AfterEach + void close() { + if (client != null) { + client = null; + } + } + + /** + * Native tests cannot get the injected client, thus we build the client directly. + * + * @return the test client + */ + @Override + Test getClient() { + if (client == null) { + client = GrpcIntegrationTestHelper.createClient(9000, TestClient.class, MutinyTestGrpc::newMutinyStub); + } + return client; + } +} diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyTestBase.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyTestBase.java index 87dc1ba433368..df61ec7293692 100644 --- a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyTestBase.java +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyTestBase.java @@ -24,9 +24,13 @@ public class BlockingMutinyTestBase { @GrpcClient Test client; + Test getClient() { + return client; + } + @BeforeEach void clear() { - client.clear(EMPTY).onFailure().invoke(e -> { + getClient().clear(EMPTY).onFailure().invoke(e -> { throw new RuntimeException("Failed to clear items", e); }).await().atMost(Duration.ofSeconds(20)); } @@ -39,7 +43,7 @@ void shouldAddItems() { String text = "text " + i; expected.add(text); final int attempt = i; - client.add(TestOuterClass.Item.newBuilder().setText(text).build()) + getClient().add(TestOuterClass.Item.newBuilder().setText(text).build()) .onFailure().invoke(e -> { throw new RuntimeException("Failed to add on attempt " + attempt, e); }) @@ -47,11 +51,7 @@ void shouldAddItems() { } List actual = new ArrayList<>(); - Multi all = client.getAll(EMPTY) - .onFailure().invoke(th -> { - System.out.println("Failed to read"); - th.printStackTrace(); - }); + Multi all = getClient().getAll(EMPTY); all.subscribe().with(item -> actual.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) .until(() -> actual.size() == NO_OF_ELTS); @@ -74,17 +74,13 @@ void shouldAddViaBidi() { } m.complete(); }); - client.bidi(request).subscribe().with(item -> echoed.add(item.getText())); + getClient().bidi(request).subscribe().with(item -> echoed.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) .until(() -> echoed.size() == NO_OF_ELTS); assertThat(echoed).containsExactlyInAnyOrderElementsOf(expected); - Multi all = client.getAll(EMPTY) - .onFailure().invoke(th -> { - System.out.println("Failed to read"); - th.printStackTrace(); - }); + Multi all = getClient().getAll(EMPTY); all.subscribe().with(item -> actual.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) .until(() -> actual.size() == NO_OF_ELTS); diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawIT.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawIT.java new file mode 100644 index 0000000000000..5b2b79447042c --- /dev/null +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawIT.java @@ -0,0 +1,45 @@ +package com.example.grpc.hibernate; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; + +import com.example.test.MutinyTestRawGrpc; +import com.example.test.TestRaw; +import com.example.test.TestRawClient; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class BlockingRawIT extends BlockingRawTestBase { + + @BeforeAll + static void init() { + GrpcIntegrationTestHelper.init(); + } + + @AfterAll + static void cleanup() { + GrpcIntegrationTestHelper.cleanup(); + } + + @AfterEach + void close() { + if (client != null) { + client = null; + } + } + + /** + * Native tests cannot get the injected client, thus we build the client directly. + * + * @return the test client + */ + @Override + TestRaw getClient() { + if (client == null) { + client = GrpcIntegrationTestHelper.createClient(9000, TestRawClient.class, MutinyTestRawGrpc::newMutinyStub); + } + return client; + } +} diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawTestBase.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawTestBase.java index b5b75ce49f2db..d68498e3ad4ee 100644 --- a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawTestBase.java +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawTestBase.java @@ -27,9 +27,13 @@ public class BlockingRawTestBase { @GrpcClient TestRaw client; + TestRaw getClient() { + return client; + } + @BeforeEach void clear() { - client.clear(EMPTY).onFailure().invoke(e -> { + getClient().clear(EMPTY).onFailure().invoke(e -> { throw new RuntimeException("Failed to clear items", e); }).await().atMost(Duration.ofSeconds(20)); } @@ -43,7 +47,7 @@ void shouldAdd() { String text = "text " + i; expected.add(text); final int attempt = i; - client.add(TestOuterClass.Item.newBuilder().setText(text).build()) + getClient().add(TestOuterClass.Item.newBuilder().setText(text).build()) .onFailure().invoke(e -> { throw new RuntimeException("Failed to add on attempt " + attempt, e); }) @@ -51,11 +55,7 @@ void shouldAdd() { } List actual = new CopyOnWriteArrayList<>(); - Multi all = client.getAll(EMPTY) - .onFailure().invoke(th -> { - System.out.println("Failed to read"); - th.printStackTrace(); - }); + Multi all = getClient().getAll(EMPTY); all.subscribe().with(item -> actual.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) .until(() -> actual.size() == NO_OF_ELTS); @@ -78,23 +78,16 @@ void shouldAddViaBidi() { } m.complete(); }); - client.bidi(request).subscribe().with(item -> echoed.add(item.getText())); + getClient().bidi(request).subscribe().with(item -> echoed.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) .until(() -> echoed.size() == NO_OF_ELTS); assertThat(echoed).containsExactlyInAnyOrderElementsOf(expected); - Multi all = client.getAll(EMPTY) - .onFailure().invoke(th -> { - System.out.println("Failed to read"); - th.printStackTrace(); - }); + Multi all = getClient().getAll(EMPTY); all.subscribe().with(item -> actual.add(item.getText())); await().atMost(Duration.ofSeconds(TIMEOUT / 2)) - .until(() -> { - System.out.println("no of elements: " + actual.size()); - return actual.size() == NO_OF_ELTS; - }); + .until(() -> actual.size() == NO_OF_ELTS); assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); } } diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/GrpcIntegrationTestHelper.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/GrpcIntegrationTestHelper.java new file mode 100644 index 0000000000000..51b5d4b57471b --- /dev/null +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/GrpcIntegrationTestHelper.java @@ -0,0 +1,39 @@ +package com.example.grpc.hibernate; + +import java.lang.reflect.Constructor; +import java.util.function.Function; + +import io.grpc.stub.AbstractStub; +import io.vertx.core.Vertx; +import io.vertx.core.net.SocketAddress; +import io.vertx.grpc.client.GrpcClient; +import io.vertx.grpc.client.GrpcClientChannel; + +public class GrpcIntegrationTestHelper { + + private static Vertx vertx; + private static GrpcClient grpcClient; + + static void init() { + vertx = Vertx.vertx(); + grpcClient = GrpcClient.client(vertx); + } + + static void cleanup() { + grpcClient.close().toCompletionStage().toCompletableFuture().join(); + vertx.close().toCompletionStage().toCompletableFuture().join(); + } + + static T createClient(int port, Class clazz, Function> function) { + try { + GrpcClientChannel channel = new GrpcClientChannel(grpcClient, SocketAddress.inetSocketAddress(port, "localhost")); + var stub = function.apply(channel); + Constructor constructor = clazz.getDeclaredConstructor(stub.getClass()); + constructor.setAccessible(true); + return constructor.newInstance(stub); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingMutinyIT.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingMutinyIT.java new file mode 100644 index 0000000000000..9a3c521a09c5c --- /dev/null +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingMutinyIT.java @@ -0,0 +1,48 @@ +package com.example.grpc.hibernate; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; + +import com.example.test.MutinyTestGrpc; +import com.example.test.Test; +import com.example.test.TestClient; + +import io.quarkus.grpc.test.utils.VertxGRPCTestProfile; +import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusIntegrationTest +@TestProfile(VertxGRPCTestProfile.class) +public class VertxBlockingMutinyIT extends BlockingMutinyTestBase { + + @BeforeAll + static void init() { + GrpcIntegrationTestHelper.init(); + } + + @AfterAll + static void cleanup() { + GrpcIntegrationTestHelper.cleanup(); + } + + @AfterEach + void close() { + if (client != null) { + client = null; + } + } + + /** + * Native tests cannot get the injected client, thus we build the client directly. + * + * @return the test client + */ + @Override + Test getClient() { + if (client == null) { + client = GrpcIntegrationTestHelper.createClient(8081, TestClient.class, MutinyTestGrpc::newMutinyStub); + } + return client; + } +} diff --git a/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingRawIT.java b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingRawIT.java new file mode 100644 index 0000000000000..f0ee8728aa361 --- /dev/null +++ b/integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingRawIT.java @@ -0,0 +1,47 @@ +package com.example.grpc.hibernate; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; + +import com.example.test.MutinyTestRawGrpc; +import com.example.test.TestRaw; +import com.example.test.TestRawClient; + +import io.quarkus.grpc.test.utils.VertxGRPCTestProfile; +import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusIntegrationTest +@TestProfile(VertxGRPCTestProfile.class) +public class VertxBlockingRawIT extends BlockingRawTestBase { + @BeforeAll + static void init() { + GrpcIntegrationTestHelper.init(); + } + + @AfterAll + static void cleanup() { + GrpcIntegrationTestHelper.cleanup(); + } + + @AfterEach + void close() { + if (client != null) { + client = null; + } + } + + /** + * Native tests cannot get the injected client, thus we build the client directly. + * + * @return the test client + */ + @Override + TestRaw getClient() { + if (client == null) { + client = GrpcIntegrationTestHelper.createClient(8081, TestRawClient.class, MutinyTestRawGrpc::newMutinyStub); + } + return client; + } +}