summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-01-29 15:03:32 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2018-01-29 15:03:32 +0100
commit8ee36a5019ed848f0359a8c69d92118f543b1e69 (patch)
tree9b23fe0d1fb9e08dc66688f47bd346460c587284
parent7af5ec2c5ecbb9d742fc162d19850f3583bbafc1 (diff)
Verify whether a new snapshot was expected or not
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java51
1 files changed, 28 insertions, 23 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java
index a4c993f8c39..41b195baeb3 100644
--- a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java
@@ -102,13 +102,13 @@ public class StateHandlerTest {
public void testReportIncludesMetricsAfterSnapshot() throws Exception {
metric.add("foo", 1, null);
metric.set("bar", 4, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json1 = requestAsJson("http://localhost/state/v1/metrics");
assertEquals(json1.toString(), "up", json1.get("status").get("code").asText());
assertEquals(json1.toString(), 2, json1.get("metrics").get("values").size());
metric.add("fuz", 1, metric.createContext(new HashMap<>(0)));
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json2 = requestAsJson("http://localhost/state/v1/metrics");
assertEquals(json2.toString(), "up", json2.get("status").get("code").asText());
assertEquals(json2.toString(), 3, json2.get("metrics").get("values").size());
@@ -129,7 +129,7 @@ public class StateHandlerTest {
metric.add(metricName, 2, metricContext);
// Change it to a gauge metric
metric.set(metricName, 9, metricContext);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
MetricValue resultingMetric = monitor.snapshot().iterator().next().getValue().get(metricName);
assertEquals(GaugeMetric.class, resultingMetric.getClass());
assertEquals("Value was reset and produces the last gauge value",
@@ -142,7 +142,7 @@ public class StateHandlerTest {
// Change it to a count metric
metric.add(metricName, 1, metricContext);
metric.add(metricName, 2, metricContext);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
MetricValue resultingMetric = monitor.snapshot().iterator().next().getValue().get(metricName);
assertEquals(CountMetric.class, resultingMetric.getClass());
assertEquals("Value was reset, and changed to add semantics giving 1+2",
@@ -156,7 +156,7 @@ public class StateHandlerTest {
metric.set("bar", 5, null);
metric.set("bar", 7, null);
metric.set("bar", 2, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertEquals(json.toString(), "up", json.get("status").get("code").asText());
assertEquals(json.toString(), 1, json.get("metrics").get("values").size());
@@ -170,7 +170,7 @@ public class StateHandlerTest {
metric.add("foo", 1, null);
metric.add("foo", 2, null);
metric.add("foo", 1, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertEquals(json.toString(), "up", json.get("status").get("code").asText());
assertEquals(json.toString(), 1, json.get("metrics").get("values").size());
@@ -181,7 +181,7 @@ public class StateHandlerTest {
@Test
public void testReadabilityOfJsonReport() throws Exception {
metric.add("foo", 1, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
assertEquals("{\n" +
" \"metrics\": {\n" +
" \"snapshot\": {\n" +
@@ -206,7 +206,7 @@ public class StateHandlerTest {
metric.set("bar", 3, ctx);
metric.set("bar", 4, ctx);
metric.set("bar", 5, ctx);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
assertEquals("{\n" +
" \"metrics\": {\n" +
" \"snapshot\": {\n" +
@@ -245,10 +245,10 @@ public class StateHandlerTest {
public void testNotAggregatingCountsBeyondSnapshots() throws Exception {
metric.add("foo", 1, null);
metric.add("foo", 1, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
metric.add("foo", 2, null);
metric.add("foo", 1, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertEquals(json.toString(), "up", json.get("status").get("code").asText());
assertEquals(json.toString(), 1, json.get("metrics").get("values").size());
@@ -261,13 +261,13 @@ public class StateHandlerTest {
metric.add("foo", 1, null);
metric.set("bar", 3, null);
// At this time we should not have done any snapshotting
- incrementCurrentTime(SNAPSHOT_INTERVAL - 1);
+ incrementCurrentTimeAndAssertNoSnapshot(SNAPSHOT_INTERVAL - 1);
{
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertFalse(json.toString(), json.get("metrics").has("snapshot"));
}
// At this time first snapshot should have been generated
- incrementCurrentTime(1);
+ incrementCurrentTimeAndAssertSnapshot(1);
{
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertTrue(json.toString(), json.get("metrics").has("snapshot"));
@@ -275,7 +275,7 @@ public class StateHandlerTest {
assertEquals(300.0, json.get("metrics").get("snapshot").get("to").asDouble(), 0.00001);
}
// No new snapshot at this time
- incrementCurrentTime(SNAPSHOT_INTERVAL - 1);
+ incrementCurrentTimeAndAssertNoSnapshot(SNAPSHOT_INTERVAL - 1);
{
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertTrue(json.toString(), json.get("metrics").has("snapshot"));
@@ -283,7 +283,7 @@ public class StateHandlerTest {
assertEquals(300.0, json.get("metrics").get("snapshot").get("to").asDouble(), 0.00001);
}
// A new snapshot
- incrementCurrentTime(1);
+ incrementCurrentTimeAndAssertSnapshot(1);
{
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertTrue(json.toString(), json.get("metrics").has("snapshot"));
@@ -296,10 +296,10 @@ public class StateHandlerTest {
public void testFreshStartOfValuesBeyondSnapshot() throws Exception {
metric.set("bar", 4, null);
metric.set("bar", 5, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
metric.set("bar", 4, null);
metric.set("bar", 2, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
assertEquals(json.toString(), "up", json.get("status").get("code").asText());
assertEquals(json.toString(), 1, json.get("metrics").get("values").size());
@@ -310,8 +310,8 @@ public class StateHandlerTest {
@Test
public void snapshotsPreserveLastGaugeValue() throws Exception {
metric.set("bar", 4, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
JsonNode metricValues = getFirstMetricValueNode(json);
assertEquals(json.toString(), 4, metricValues.get("last").asDouble(), 0.001);
@@ -333,10 +333,10 @@ public class StateHandlerTest {
@Test
public void gaugeSnapshotsTracksCountMinMaxAvgPerPeriod() throws Exception {
metric.set("bar", 10000, null); // Ensure any cross-snapshot noise is visible
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
metric.set("bar", 20, null);
metric.set("bar", 40, null);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/all");
JsonNode metricValues = getFirstMetricValueNode(json);
assertEquals(json.toString(), 40, metricValues.get("last").asDouble(), 0.001);
@@ -361,7 +361,7 @@ public class StateHandlerTest {
metric.set("serverTotalSuccessfulResponseLatency", 20, context1);
metric.set("serverTotalSuccessfulResponseLatency", 40, context2);
metric.add("random", 3, context1);
- incrementCurrentTime(SNAPSHOT_INTERVAL);
+ incrementCurrentTimeAndAssertSnapshot(SNAPSHOT_INTERVAL);
JsonNode json = requestAsJson("http://localhost/state/v1/health");
assertEquals(json.toString(), "up", json.get("status").get("code").asText());
assertEquals(json.toString(), 2, json.get("metrics").get("values").size());
@@ -392,9 +392,14 @@ public class StateHandlerTest {
assertEquals(Vtag.currentVersion.toString(), version.asText());
}
- private void incrementCurrentTime(long val) {
+ private void incrementCurrentTimeAndAssertSnapshot(long val) {
currentTimeMillis.addAndGet(val);
- monitor.checkTime();
+ assertTrue("Expected a new snapshot to be generated", monitor.checkTime());
+ }
+
+ private void incrementCurrentTimeAndAssertNoSnapshot(long val) {
+ currentTimeMillis.addAndGet(val);
+ assertFalse("Expected no snapshot", monitor.checkTime());;
}
private String requestAsString(String requestUri) throws Exception {