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

Improve Tests #114

Merged
merged 9 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ the `localhost` host to the inventory. Next, the test case makes a connection to
Then, it asserts whether the time that is needed to retrieve
the system properties for localhost is less than 4 seconds.

* The [hotspot=testInventoryAccessCountMetric file=0]`testInventoryAccessCountMetric()` test case validates the [hotspot=countedForList file=1]`@Counted` metric. The test case sends a request to the
`\http://localhost:9080/inventory/systems` URL to retrieve the whole inventory, and then it asserts
that this endpoint is accessed at least once.
* The [hotspot=testInventoryAccessCountMetric file=0]`testInventoryAccessCountMetric()` test case validates the [hotspot=countedForList file=1]`@Counted` metric.
The test case obtains the metric before and after a request to the `\http://localhost:9080/inventory/systems` URL.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested update

The test case obtains metric data before and after a request to the \http://localhost:9080/inventory/systems URL.

It asserts that the metric was increased after the access.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, I'm thinking update it to

It then asserts that the metric was increased after the URL was accessed.

If that makes sense to you? I had a harder time understanding exactly what this sentence meant.


* The [hotspot=testInventorySizeGaugeMetric file=0]`testInventorySizeGaugeMetric()` test case validates the [hotspot=gaugeForGetTotal file=1]`@Gauge` metric. The test case first ensures
that the localhost is in the inventory, then looks for the [hotspot=gaugeForGetTotal file=1]`@Gauge` metric and asserts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testPropertiesRequestTimeMetric() {
for (String metric : metrics) {
if (metric.startsWith(
"application_inventoryProcessingTime_rate_per_second")) {
float seconds = Float.parseFloat(metric.split(" ")[1]);
float seconds = Float.parseFloat(metric.split("\\s+")[1]);
assertTrue(4 > seconds);
}
}
Expand All @@ -106,13 +106,17 @@ public void testPropertiesRequestTimeMetric() {
// end::Order2[]
// tag::testInventoryAccessCountMetric[]
public void testInventoryAccessCountMetric() {
metrics = getMetrics();
Map<String, Integer> accessCountsBefore = getIntMetrics(metrics,
"application_inventoryAccessCount_total");
connectToEndpoint(baseHttpUrl + INVENTORY_HOSTS);
metrics = getMetrics();
for (String metric : metrics) {
if (metric.startsWith("application_inventoryAccessCount_total")) {
assertTrue(
1 <= Integer.parseInt(metric.split(" ")[metric.split(" ").length - 1]));
}
Map<String, Integer> accessCountsAfter = getIntMetrics(metrics,
"application_inventoryAccessCount_total");
for (String key : accessCountsBefore.keySet()) {
Integer accessCountBefore = accessCountsBefore.get(key);
Integer accessCountAfter = accessCountsAfter.get(key);
assertTrue(accessCountAfter > accessCountBefore);
}
}
// end::testInventoryAccessCountMetric[]
Expand All @@ -126,11 +130,10 @@ public void testInventoryAccessCountMetric() {
// tag::testInventorySizeGaugeMetric[]
public void testInventorySizeGaugeMetric() {
metrics = getMetrics();
for (String metric : metrics) {
if (metric.startsWith("application_inventorySizeGauge")) {
assertTrue(
1 <= Character.getNumericValue(metric.charAt(metric.length() - 1)));
}
Map<String, Integer> inventorySizeGauges = getIntMetrics(metrics,
"application_inventorySizeGauge");
for (Integer value : inventorySizeGauges.values()) {
assertTrue(1 <= value);
}
}
// end::testInventorySizeGaugeMetric[]
Expand Down Expand Up @@ -198,5 +201,18 @@ private Response getResponse(String url) {
private void assertResponse(String url, Response response) {
assertEquals(200, response.getStatus(), "Incorrect response code from " + url);
}

private Map<String, Integer> getIntMetrics(List<String> metrics, String metricName) {
Map<String, Integer> output = new HashMap<String, Integer>();
for (String metric : metrics) {
if (metric.startsWith(metricName)) {
String[] mSplit = metric.split("\\s+");
String key = mSplit[0];
Integer value = Integer.parseInt(mSplit[mSplit.length - 1]);
output.put(key, value);
}
}
return output;
}
}
// end::MetricsTest[]