Skip to content

Commit

Permalink
Add support for testing with metrics (#327)
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Bair <rbair23@users.noreply.github.com>
  • Loading branch information
rbair23 authored Nov 15, 2024
1 parent d7c41ea commit e6a8c9b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions pbj-core/pbj-grpc-helidon/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pbj-core/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6a8c9b

Please sign in to comment.