Skip to content

Commit

Permalink
Merge pull request #30481 from alesj/i30379
Browse files Browse the repository at this point in the history
Test all gRPC combos wrt exception handling, msgs, etc
  • Loading branch information
cescoffier authored Jan 23, 2023
2 parents 1672206 + 22406b9 commit 8226a56
Show file tree
Hide file tree
Showing 40 changed files with 574 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public static Channel createChannel(String name, Set<String> perClientIntercepto
return builder.build();
} else {
HttpClientOptions options = new HttpClientOptions(); // TODO options
options.setHttp2ClearTextUpgrade(false); // this fixes i30379

if (!plainText) {
if (config.ssl.trustStore.isPresent()) {
Expand Down
98 changes: 98 additions & 0 deletions integration-tests/grpc-exceptions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-integration-test-grpc-exceptions</artifactId>
<name>Quarkus - Integration Tests - gRPC - Exceptions</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-grpc</artifactId>
<version>${project.version}</version> <!--kept here to not pollute the BOM-->
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-code</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.grpc.exc;

import io.grpc.Status;
import io.grpc.StatusException;
import io.grpc.stub.StreamObserver;
import io.quarkus.grpc.GrpcService;

@GrpcService
public class LegacyHelloGrpcService extends LegacyHelloGrpcGrpc.LegacyHelloGrpcImplBase {
@Override
public void legacySayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
// it NEEDS to be plain StatusException, and NOT StatusRuntimeException ?!
final StatusException t = new StatusException(Status.INVALID_ARGUMENT);
responseObserver.onError(t);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.grpc.exc;

import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Uni;

@GrpcService
public class SmallryeHelloGrpcService implements HelloGrpc {

@Override
public Uni<HelloReply> sayHello(HelloRequest request) {
throw new IllegalArgumentException("test");
}

}
23 changes: 23 additions & 0 deletions integration-tests/grpc-exceptions/src/main/proto/hello.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.example.grpc.exc";
option java_outer_classname = "HelloGrpcProto";

package hello;

service HelloGrpc {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

service LegacyHelloGrpc {
rpc LegacySayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
string name = 1;
}

message HelloReply {
string message = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## --- servers

%vertx.quarkus.grpc.server.use-separate-server=false
%n2o.quarkus.grpc.server.use-separate-server=true
%o2n.quarkus.grpc.server.use-separate-server=false

## --- clients

quarkus.grpc.clients.hello.host=localhost
quarkus.grpc.clients.hello.port=9001

%vertx.quarkus.grpc.clients.hello.port=8081
%vertx.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true

%n2o.quarkus.grpc.clients.hello.port=9001
%n2o.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true

%o2n.quarkus.grpc.clients.hello.port=8081
%o2n.quarkus.grpc.clients.hello.use-quarkus-grpc-client=false

quarkus.grpc.clients.stub.host=localhost
quarkus.grpc.clients.stub.port=9001

%vertx.quarkus.grpc.clients.stub.port=8081
%vertx.quarkus.grpc.clients.stub.use-quarkus-grpc-client=true

%n2o.quarkus.grpc.clients.stub.port=9001
%n2o.quarkus.grpc.clients.stub.use-quarkus-grpc-client=true

%o2n.quarkus.grpc.clients.stub.port=8081
%o2n.quarkus.grpc.clients.stub.use-quarkus-grpc-client=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.grpc.exc;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class LegacyHelloGrpcServiceTest extends LegacyHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.grpc.exc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.grpc.GrpcClient;

class LegacyHelloGrpcServiceTestBase {
@SuppressWarnings("CdiInjectionPointsInspection")
@GrpcClient
LegacyHelloGrpcGrpc.LegacyHelloGrpcBlockingStub stub;

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void legacySayHello() {
final StatusRuntimeException exception = assertThrows(StatusRuntimeException.class,
() -> stub.legacySayHello(HelloRequest.newBuilder().setName("Neo").build()));
assertEquals(Status.Code.INVALID_ARGUMENT, exception.getStatus().getCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.N2OGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(N2OGRPCTestProfile.class)
class N2OLegacyHelloGrpcServiceTest extends LegacyHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.N2OGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(N2OGRPCTestProfile.class)
public class N2OSmallryeHelloGrpcServiceTest extends SmallryeHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.O2NGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(O2NGRPCTestProfile.class)
class O2NLegacyHelloGrpcServiceTest extends LegacyHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.O2NGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(O2NGRPCTestProfile.class)
public class O2NSmallryeHelloGrpcServiceTest extends SmallryeHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.grpc.exc;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class SmallryeHelloGrpcServiceTest extends SmallryeHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.grpc.exc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.time.Duration;

import org.junit.jupiter.api.Test;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.grpc.GrpcClient;

public class SmallryeHelloGrpcServiceTestBase {

@SuppressWarnings("CdiInjectionPointsInspection")
@GrpcClient
HelloGrpc hello;

@Test
public void testHello() {
final StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> hello
.sayHello(HelloRequest.newBuilder().setName("Neo").build()).await()
.atMost(Duration.ofSeconds(5)));
assertEquals(Status.Code.INVALID_ARGUMENT, exception.getStatus().getCode());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.VertxGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(VertxGRPCTestProfile.class)
class VertxLegacyHelloGrpcServiceTest extends LegacyHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.grpc.exc;

import io.quarkus.grpc.test.utils.VertxGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(VertxGRPCTestProfile.class)
public class VertxSmallryeHelloGrpcServiceTest extends SmallryeHelloGrpcServiceTestBase {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
quarkus.grpc.server.port=9001

%vertx.quarkus.grpc.server.use-separate-server=false
%n2o.quarkus.grpc.server.use-separate-server=true
%o2n.quarkus.grpc.server.use-separate-server=false

quarkus.grpc.clients.hello.host=localhost
quarkus.grpc.clients.hello.port=9001

%vertx.quarkus.grpc.clients.hello.port=8081
%vertx.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true
%vertx.quarkus.grpc.server.use-separate-server=false

%n2o.quarkus.grpc.clients.hello.port=9001
%n2o.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true

%o2n.quarkus.grpc.clients.hello.port=8081
%o2n.quarkus.grpc.clients.hello.use-quarkus-grpc-client=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.grpc.example.interceptors;

import io.quarkus.grpc.test.utils.N2OGRPCTestProfile;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusIntegrationTest
@TestProfile(N2OGRPCTestProfile.class)
class N2OHelloWorldEndpointIT extends HelloWorldEndpointTestBase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.grpc.example.interceptors;

import io.quarkus.grpc.test.utils.N2OGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(N2OGRPCTestProfile.class)
class N2OHelloWorldEndpointTest extends HelloWorldEndpointTestBase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.grpc.example.interceptors;

import io.quarkus.grpc.test.utils.O2NGRPCTestProfile;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusIntegrationTest
@TestProfile(O2NGRPCTestProfile.class)
class O2NHelloWorldEndpointIT extends HelloWorldEndpointTestBase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.grpc.example.interceptors;

import io.quarkus.grpc.test.utils.O2NGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(O2NGRPCTestProfile.class)
class O2NHelloWorldEndpointTest extends HelloWorldEndpointTestBase {

}
Loading

0 comments on commit 8226a56

Please sign in to comment.