Skip to content

Commit

Permalink
Merge pull request #722 from jgallimore/tck-test-fix
Browse files Browse the repository at this point in the history
Make testGcCountMetrics and testGcTimeMetrics more robust
  • Loading branch information
donbourne committed Aug 18, 2022
2 parents c8c76f6 + 3e27464 commit 58a1e93
Showing 1 changed file with 25 additions and 21 deletions.
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -359,7 +360,7 @@ public void testApplicationMetricsPrometheus() {

/*
* HISTOGRAMS
*
*
* CANNOT GURANTEE ACCURACY OF QUANTILES - WILL OMIT BETTER TESTING FOR "VALUES" WILL BE DONE IN API TCK
*/
.body(containsString("# HELP metricTest_test1_histogram_bytes"))
Expand Down Expand Up @@ -387,7 +388,7 @@ public void testApplicationMetricsPrometheus() {

/*
* TIMERS
*
*
* ONLY INTERESTED IN THE COUNT. NOT INTERESTED IN ANY OTHER VALUES. TIMES RECORDED COULD VARY. BETTER
* TESTING FOR "VALUES" WILL BE DONE IN API TCKS
*/
Expand Down Expand Up @@ -778,18 +779,20 @@ public void testGcCountMetrics() {
for (String line : lines) {
// explicitly check for the metric line wth value (i.e. the use of `{`)
if (line.contains("gc_total{")) {
final Pattern gcTotalPattern = Pattern.compile("(gc_total\\{.*?\\}) (\\d+\\.\\d+)");
assertThat("Line format should be gc_total\\{.*?\\} \\d+\\.\\d+",
gcTotalPattern.matcher(line).matches());

final String metricID = gcTotalPattern.matcher(line).replaceAll("$1");
final String tags = metricID.replaceAll("^gc_total\\{", "").replaceAll("\\}$", "");

for (String expectedTag : expectedTags) {
assertThat("The metric should contain a " + expectedTag + " tag", line,
assertThat("The metric should contain a " + expectedTag + " tag", tags,
containsString(expectedTag + "="));
}
/*
* example: gc_total{name="global",mp_scope="base",tier="integration",} 14.0 Expect only one space
*/
String[] tmp = line.split(" ");
assertEquals("Unexpected format: " + line, tmp.length, 2);

final String value = gcTotalPattern.matcher(line).replaceAll("$2");
Assert.assertTrue("gc.total value should be numeric and not negative",
Double.valueOf(tmp[1]).doubleValue() >= 0);
Double.valueOf(value).doubleValue() >= 0);

found = true;
}
Expand Down Expand Up @@ -820,25 +823,26 @@ public void testGcTimeMetrics() {
for (String line : lines) {
// explicitly check for the metric line wth value (i.e. the use of `{`)
if (line.contains("gc_time_seconds_total{")) {
final Pattern gcTimeTotalPattern = Pattern.compile("(gc_time_seconds_total\\{.*?\\}) (\\d+\\.\\d+)");
assertThat("Line format should be gc_time_seconds_total\\{.*?\\} \\d+\\.\\d+",
gcTimeTotalPattern.matcher(line).matches());

final String metricID = gcTimeTotalPattern.matcher(line).replaceAll("$1");
final String tags = metricID.replaceAll("^gc_time_seconds_total\\{", "").replaceAll("\\}$", "");

for (String expectedTag : expectedTags) {
assertThat("The metric should contain a " + expectedTag + " tag", line,
assertThat("The metric should contain a " + expectedTag + " tag", tags,
containsString(expectedTag + "="));
}
/*
* example: gc_time_total{name="scavenge",mp_scope="base",tier="integration",} 264.0 Expect only one
* space
*/
String[] tmp = line.split(" ");
assertEquals("Unexpected format: " + line, tmp.length, 2);

Assert.assertTrue("gc.total value should be numeric and not negative",
Double.valueOf(tmp[1]).doubleValue() >= 0);
final String value = gcTimeTotalPattern.matcher(line).replaceAll("$2");
Assert.assertTrue("gc.time.seconds.total value should be numeric and not negative",
Double.valueOf(value).doubleValue() >= 0);

found = true;
}
}

Assert.assertTrue("At least one metric named gc.total is expected", found);
Assert.assertTrue("At least one metric named gc.time.seconds.total is expected", found);
}

/**
Expand Down

0 comments on commit 58a1e93

Please sign in to comment.