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

Remove retries from executor metrics test fix; use the pre-existing countdown latch in GreetService instead #5109

Merged
merged 6 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Remove retries from executor metrics test fix; use the pre-existing c…
…ountdown latch in GreetService instead
  • Loading branch information
tjquinno committed Oct 6, 2022
commit 73471bf117ec2e8675508822254cf0a09d8a70bd
5 changes: 0 additions & 5 deletions metrics/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@
<artifactId>helidon-common-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.reactive.fault-tolerance</groupId>
<artifactId>helidon-reactive-fault-tolerance</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
40 changes: 18 additions & 22 deletions metrics/metrics/src/test/java/io/helidon/metrics/TestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import io.helidon.common.http.Http;
import io.helidon.common.media.type.MediaTypes;
import io.helidon.reactive.faulttolerance.Retry;
import io.helidon.reactive.media.jsonp.JsonpSupport;
import io.helidon.reactive.webclient.WebClient;
import io.helidon.reactive.webclient.WebClientRequestBuilder;
Expand Down Expand Up @@ -50,18 +49,14 @@
public class TestServer {

private static final Logger LOGGER = Logger.getLogger(TestServer.class.getName());
private static final int RETRY_COUNT = Integer.getInteger("io.helidon.test.retryCount", 10);
private static final Duration RETRY_DELAY = Duration.ofMillis(Integer.getInteger("io.helidon.test.retryDelayMs", 500));
private static final Duration CLIENT_TIMEOUT = Duration.ofSeconds(Integer.getInteger("io.helidon.test.clientTimeoutSec", 10));
private static final Duration RETRY_TIMEOUT = Duration.ofSeconds(Integer.getInteger("io.helidon.test.retryTimeoutSec", 60));
private static final String[] EXPECTED_NO_CACHE_HEADER_SETTINGS = {"no-cache", "no-store", "must-revalidate", "no-transform"};

private static WebServer webServer;

private static final MetricsSupport.Builder NORMAL_BUILDER = MetricsSupport.builder();

private static MetricsSupport metricsSupport;
private static Retry.Builder retry;
private static WebClient.Builder webClientBuilder;

@BeforeAll
Expand All @@ -71,12 +66,6 @@ public static void startup() {
webClientBuilder = WebClient.builder()
.baseUri("http://localhost:" + webServer.port() + "/")
.addMediaSupport(JsonpSupport.create());
retry = Retry.builder()
.overallTimeout(RETRY_TIMEOUT)
.retryPolicy(Retry.JitterRetryPolicy.builder()
.calls(RETRY_COUNT)
.delay(RETRY_DELAY)
.build());
}

@AfterAll
Expand Down Expand Up @@ -164,7 +153,7 @@ void checkKPIDisabledByDefault() {
}

@Test
void checkMetricsForExecutorService() {
void checkMetricsForExecutorService() throws InterruptedException {

String jsonKeyForCompleteTaskCountInThreadPool =
"executor-service.completed-task-count;poolIndex=0;supplierCategory=my-thread-thread-pool-1;supplierIndex=0";
Expand All @@ -190,6 +179,7 @@ void checkMetricsForExecutorService() {
int completedTaskCount = metrics.getInt(jsonKeyForCompleteTaskCountInThreadPool);
assertThat("Completed task count before accessing slow endpoint", completedTaskCount, is(0));

GreetService.initSlowRequest();
WebClientResponse slowGreetResponse = webClientBuilder
.build()
.get()
Expand All @@ -200,17 +190,23 @@ void checkMetricsForExecutorService() {

assertThat("Slow greet access response status", slowGreetResponse.status().code(), is(200));

retry.build()
.invoke(() -> metricsRequestBuilder
.submit()
.peek(res -> assertThat("Second access to metrics", res.status().code(), is(200)))
.flatMapSingle(res -> res.content().as(JsonObject.class))
.peek(json -> assertThat("JSON metrics results after accessing slow endpoint",
json, hasKey(jsonKeyForCompleteTaskCountInThreadPool)))
.map(json -> json.getInt(jsonKeyForCompleteTaskCountInThreadPool))
.forSingle(secCompletedTaskCnt ->
assertThat("Completed task count after accessing slow endpoint", secCompletedTaskCnt, is(1))))
GreetService.awaitSlowRequestStarted();

WebClientResponse secondMetricsResponse = metricsRequestBuilder
.submit()
.await(CLIENT_TIMEOUT);

assertThat("Second access to metrics", secondMetricsResponse.status().code(), is(200));

JsonObject secondMetrics = secondMetricsResponse.content().as(JsonObject.class).await(CLIENT_TIMEOUT);

assertThat("JSON metrics results after accessing slow endpoint",
secondMetrics,
hasKey(jsonKeyForCompleteTaskCountInThreadPool));

int secondCompletedTaskCount = secondMetrics.getInt(jsonKeyForCompleteTaskCountInThreadPool);

assertThat("Completed task count after accessing slow endpoint", secondCompletedTaskCount, is(1));
}

@ParameterizedTest
Expand Down