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 May 14, 2021
1 parent bb4671d commit dc202cb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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 @@ -47,6 +47,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.inject.Inject;
Expand All @@ -55,7 +56,9 @@
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.microprofile.metrics.MetricRegistry;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.BaseMatcher;
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 @@ -1274,7 +1277,42 @@ public void testApplicationSimpleTimerUnitOpenMetrics() {
;
}


@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;
}
};
}

/**
* Checks that the value is within tolerance of the expected value
*
Expand Down

0 comments on commit dc202cb

Please sign in to comment.