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#29377 from cescoffier/grpc-hibernate-nat…
…ive-tests Implement native test for the gRPC / Hibernate ITs
- Loading branch information
Showing
7 changed files
with
243 additions
and
30 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ation-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingMutinyIT.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 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; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
integration-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/BlockingRawIT.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 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; | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...ts/grpc-hibernate/src/test/java/com/example/grpc/hibernate/GrpcIntegrationTestHelper.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,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> T createClient(int port, Class<T> clazz, Function<GrpcClientChannel, AbstractStub<?>> function) { | ||
try { | ||
GrpcClientChannel channel = new GrpcClientChannel(grpcClient, SocketAddress.inetSocketAddress(port, "localhost")); | ||
var stub = function.apply(channel); | ||
Constructor<T> constructor = clazz.getDeclaredConstructor(stub.getClass()); | ||
constructor.setAccessible(true); | ||
return constructor.newInstance(stub); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingMutinyIT.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,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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ion-tests/grpc-hibernate/src/test/java/com/example/grpc/hibernate/VertxBlockingRawIT.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,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; | ||
} | ||
} |