From e6a8c9bf9985b5c52d04bbbd575c0ad699622fca Mon Sep 17 00:00:00 2001 From: Richard Bair Date: Fri, 15 Nov 2024 15:07:21 -0800 Subject: [PATCH] Add support for testing with metrics (#327) Signed-off-by: Richard Bair --- pbj-core/pbj-grpc-helidon/build.gradle.kts | 1 + .../grpc/helidon/PbjProtocolHandlerTest.java | 18 +++++++++--------- .../com/hedera/pbj/grpc/helidon/PbjTest.java | 1 - pbj-core/settings.gradle.kts | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pbj-core/pbj-grpc-helidon/build.gradle.kts b/pbj-core/pbj-grpc-helidon/build.gradle.kts index c736f90c..596bc589 100644 --- a/pbj-core/pbj-grpc-helidon/build.gradle.kts +++ b/pbj-core/pbj-grpc-helidon/build.gradle.kts @@ -33,6 +33,7 @@ testModuleInfo { requires("io.helidon.webclient") requires("io.helidon.webserver") requires("io.helidon.webserver.http2") + requires("io.helidon.webserver.observe.metrics") requires("io.helidon.webclient.http2") requires("com.google.protobuf.util") requires("io.grpc.protobuf") diff --git a/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjProtocolHandlerTest.java b/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjProtocolHandlerTest.java index 77fa8b69..f5c812fb 100644 --- a/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjProtocolHandlerTest.java +++ b/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjProtocolHandlerTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.assertj.core.api.Assumptions.assumeThat; import com.hedera.pbj.grpc.helidon.config.PbjConfig; import com.hedera.pbj.runtime.grpc.GrpcStatus; @@ -69,11 +70,10 @@ void setUp() { route = new PbjMethodRoute(new GreeterServiceImpl(), GreeterService.GreeterMethod.sayHello); deadlineDetector = new DeadlineDetectorStub(); - // FUTURE: We need an easy way to test counters. When we have them, we can test this. -// assumeThat(route.requestCounter().count()).isEqualTo(0); -// assumeThat(route.failedGrpcRequestCounter().count()).isEqualTo(0); -// assumeThat(route.failedHttpRequestCounter().count()).isEqualTo(0); -// assumeThat(route.failedUnknownRequestCounter().count()).isEqualTo(0); + assumeThat(route.requestCounter().count()).isEqualTo(0); + assumeThat(route.failedGrpcRequestCounter().count()).isEqualTo(0); + assumeThat(route.failedHttpRequestCounter().count()).isEqualTo(0); + assumeThat(route.failedUnknownRequestCounter().count()).isEqualTo(0); } /** @@ -90,11 +90,11 @@ void unsupportedContentType(String contentType) { final var handler = new PbjProtocolHandler(headers, streamWriter, streamId, flowControl, currentStreamState, config, route, deadlineDetector); handler.init(); // Even though the request failed, it was made, and should be counted -// assertThat(route.requestCounter().count()).isEqualTo(1); + assertThat(route.requestCounter().count()).isEqualTo(1); // And since it failed the failed counter should be incremented -// assertThat(route.failedGrpcRequestCounter().count()).isEqualTo(0); -// assertThat(route.failedHttpRequestCounter().count()).isEqualTo(1); -// assertThat(route.failedUnknownRequestCounter().count()).isEqualTo(0); + assertThat(route.failedGrpcRequestCounter().count()).isEqualTo(0); + assertThat(route.failedHttpRequestCounter().count()).isEqualTo(1); + assertThat(route.failedUnknownRequestCounter().count()).isEqualTo(0); // Check the HTTP2 response header frame was error 415 assertThat(streamWriter.writtenHeaders).hasSize(1); diff --git a/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjTest.java b/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjTest.java index 0403f311..0979694e 100644 --- a/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjTest.java +++ b/pbj-core/pbj-grpc-helidon/src/test/java/com/hedera/pbj/grpc/helidon/PbjTest.java @@ -57,7 +57,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Flow; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/pbj-core/settings.gradle.kts b/pbj-core/settings.gradle.kts index 157b4854..5a27c4b0 100644 --- a/pbj-core/settings.gradle.kts +++ b/pbj-core/settings.gradle.kts @@ -49,6 +49,7 @@ dependencyResolutionManagement { // which will have the set of these dependencies that are required. version("io.helidon.webserver", helidonVersion) version("io.helidon.webserver.http2", helidonVersion) + version("io.helidon.webserver.observe.metrics", helidonVersion) version("io.helidon.metrics.api", helidonVersion) version("io.helidon.common.features.api", helidonVersion) version("io.helidon.common.features.processor", helidonVersion) // annotation processing