Skip to content

Commit

Permalink
Verify that HELP lines are not duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Mar 28, 2024
1 parent c1657f2 commit 49a7338
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ public long countMeB() {
return 666666;
}

@Counted(name = "counter.with.desc", tags = {"number=one"}, description = "description")
public void counterWithDesc1() {

}

@Counted(name = "counter.with.desc", tags = {"number=two"}, description = "description")
public void counterWithDesc2() {

}

public void gaugeMe() {

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
Expand Down Expand Up @@ -801,7 +805,43 @@ public void testMultipleTaggedMetricsProm() {
"taggedTimer_seconds_sum{mp_scope=\"application\",number=\"two\",tier=\"integration\"} "))
.body(containsString(
"taggedTimer_seconds_max{mp_scope=\"application\",number=\"two\",tier=\"integration\"} "));
}

@Test
@RunAsClient
public void testApplicationContainsHelpMessageOnce() {
given().header("Accept", TEXT_PLAIN).when().get("/metrics/application")
.then().statusCode(200)
.and()
.body(containsLineOnce(
"HELP application_org_eclipse_microprofile_metrics_test_MetricAppBean_counter_with_desc_total description"));
}

/**
* Checks that given line appears in the body only once.
*
* @param expected
* @return
*/
private Matcher<String> containsLineOnce(String expected) {
return new BaseMatcher<String>() {
@Override
public void describeTo(Description description) {
description.appendText("Body should contain line [" + expected + "] only once.");
}

@Override
public boolean matches(Object o) {
String body = (String) o;
Pattern pattern = Pattern.compile(expected);
java.util.regex.Matcher matcher = pattern.matcher(body);
int count = 0;
while (matcher.find()) {
count++;
}
return count == 1;
}
};
}

}

0 comments on commit 49a7338

Please sign in to comment.