Skip to content

Commit

Permalink
Improve AllureGrpc for non-blocking (streaming) stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtuchs committed Mar 2, 2024
1 parent e8c7265 commit 55507f9
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 118 deletions.
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

0 comments on commit 55507f9

Please sign in to comment.