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

Improve AllureGrpc integartion for support non-blocking (streaming) stubs #1015

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ You can specify custom templates, which should be placed in src/main/resources/t

## gRPC

Interceptor for gRPC stubs, that generates attachment for allure.
Interceptor for gRPC stubs (blocking and non-blocking), that generates attachment for allure.

```xml
<dependency>
Expand All @@ -136,20 +136,51 @@ Interceptor for gRPC stubs, that generates attachment for allure.
</dependency>
```

Usage example:
Usage example with blocking stub:
```
ServiceGrpc.newBlockingStub(channel)
.withInterceptors(new AllureGrpc());

@Test
void test() {
blockingStub.unaryCall(...);
}
```
.newBlockingStub(channel).withInterceptors(new AllureGrpc());
Similarly with non-blocking stub:
```
ServiceGrpc.newStub(channel)
.withInterceptors(new AllureGrpc());

@Test
void test() {
stub.streamingCall(...);
}

@AfterEach
void awaitAllureForNonBlockingCalls() {
AllureGrpc.await();
}
```
With non-blocking Stubs you have to use after-each hook for tests because non-blocking stubs
are async, and allure-report might not be created after non-blocking Stubs call.
You can use `@AfterEach` annotation for JUnit 5, `@AfterTest` for TestNG and `@After` for JUnit 4.
Of course, you can implement Extension or Rule to achieve that.

Also, you can register interceptor for `Channel` and use it for all kinds of gRPC stubs,
but you still need to use `AllureGrpc.await()` after non-blocking Stubs calls.
```
final Channel channel = ManagedChannelBuilder.forAddress("localhost", 8092)
.intercept(new AllureGrpc())
.build();
```
You can enable interception of response metadata (disabled by default)
```
.withInterceptors(new AllureGrpc()
.interceptResponseMetadata(true))
.withInterceptors(new AllureGrpc().interceptResponseMetadata(true))
```
By default, a step will be marked as failed in case that response contains any statuses except 0(OK).
You can change this behavior, for example, for negative scenarios
```
.withInterceptors(new AllureGrpc()
.markStepFailedOnNonZeroCode(false))
.withInterceptors(new AllureGrpc().markStepFailedOnNonZeroCode(false))
```
You can specify custom templates, which should be placed in src/main/resources/tpl folder:
```
Expand Down
5 changes: 3 additions & 2 deletions allure-grpc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ description = "Allure gRPC Integration"

val agent: Configuration by configurations.creating

val grpcVersion = "1.57.2"
val protobufVersion = "3.22.4"
val grpcVersion = "1.62.2"
val protobufVersion = "3.25.3"

dependencies {
agent("org.aspectj:aspectjweaver")
api(project(":allure-attachments"))
implementation("io.grpc:grpc-core:$grpcVersion")
implementation("com.google.protobuf:protobuf-java-util:$protobufVersion")
internal("com.fasterxml.jackson.core:jackson-databind")

testImplementation("io.grpc:grpc-stub:$grpcVersion")
testImplementation("io.grpc:grpc-protobuf:$grpcVersion")
Expand Down
348 changes: 267 additions & 81 deletions allure-grpc/src/main/java/io/qameta/allure/grpc/AllureGrpc.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import java.util.Objects;

/**
* @author dtuchs (Dmitrii Tuchs).
*/
public class GrpcRequestAttachment implements AttachmentData {

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.util.Map;
import java.util.Objects;

/**
* @author dtuchs (Dmitrii Tuchs).
*/
public class GrpcResponseAttachment implements AttachmentData {

private final String name;
Expand Down
Loading
Loading