diff options
author | gjoranv <gv@oath.com> | 2018-10-24 11:06:39 +0200 |
---|---|---|
committer | gjoranv <gv@oath.com> | 2018-10-31 12:40:12 +0100 |
commit | a7cf143f91aa3d07efc79b683d9c996fb406129a (patch) | |
tree | 7ec655cf23036764e19302e0223f5f435909e00f /container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java | |
parent | af146b406da7911a0e035ea3bf184680b31bac9b (diff) |
Add new handler for obtaining metrics snapshot in "packets" format
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java | 99 |
1 files changed, 1 insertions, 98 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 41b195baeb3..b3a19e77391 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 @@ -2,92 +2,24 @@ package com.yahoo.container.jdisc.state; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.inject.AbstractModule; import com.yahoo.component.Vtag; -import com.yahoo.container.core.ApplicationMetadataConfig; -import com.yahoo.container.jdisc.config.HealthMonitorConfig; import com.yahoo.jdisc.Metric; -import com.yahoo.jdisc.Response; -import com.yahoo.jdisc.Timer; -import com.yahoo.jdisc.application.ContainerBuilder; -import com.yahoo.jdisc.application.MetricConsumer; -import com.yahoo.jdisc.handler.BufferedContentChannel; -import com.yahoo.jdisc.handler.ContentChannel; -import com.yahoo.jdisc.handler.ResponseHandler; -import com.yahoo.jdisc.test.TestDriver; -import com.yahoo.metrics.MetricsPresentationConfig; import com.yahoo.vespa.defaults.Defaults; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; /** * @author Simon Thoresen Hult */ -public class StateHandlerTest { - - private final static long SNAPSHOT_INTERVAL = TimeUnit.SECONDS.toMillis(300); - private final static long META_GENERATION = 69; - private TestDriver driver; - private StateMonitor monitor; - private Metric metric; - private final AtomicLong currentTimeMillis = new AtomicLong(0); - - @Before - public void startTestDriver() { - Timer timer = this.currentTimeMillis::get; - this.driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() { - @Override - protected void configure() { - bind(Timer.class).toInstance(timer); - } - }); - ContainerBuilder builder = driver.newContainerBuilder(); - HealthMonitorConfig healthMonitorConfig = - new HealthMonitorConfig( - new HealthMonitorConfig.Builder() - .snapshot_interval(TimeUnit.MILLISECONDS.toSeconds(SNAPSHOT_INTERVAL))); - ThreadFactory threadFactory = ignored -> mock(Thread.class); - this.monitor = new StateMonitor(healthMonitorConfig, timer, threadFactory); - builder.guiceModules().install(new AbstractModule() { - - @Override - protected void configure() { - bind(StateMonitor.class).toInstance(monitor); - bind(MetricConsumer.class).toProvider(MetricConsumerProviders.wrap(monitor)); - bind(ApplicationMetadataConfig.class).toInstance(new ApplicationMetadataConfig( - new ApplicationMetadataConfig.Builder().generation(META_GENERATION))); - bind(MetricsPresentationConfig.class) - .toInstance(new MetricsPresentationConfig(new MetricsPresentationConfig.Builder())); - } - }); - builder.serverBindings().bind("http://*/*", builder.getInstance(StateHandler.class)); - driver.activateContainer(builder); - metric = builder.getInstance(Metric.class); - } - - @After - public void stopTestDriver() { - assertTrue(driver.close()); - } +public class StateHandlerTest extends StateHandlerTestBase { @Test public void testReportPriorToFirstSnapshot() throws Exception { @@ -392,37 +324,8 @@ public class StateHandlerTest { assertEquals(Vtag.currentVersion.toString(), version.asText()); } - private void incrementCurrentTimeAndAssertSnapshot(long val) { - currentTimeMillis.addAndGet(val); - 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 { - final BufferedContentChannel content = new BufferedContentChannel(); - Response response = driver.dispatchRequest(requestUri, new ResponseHandler() { - - @Override - public ContentChannel handleResponse(Response response) { - return content; - } - }).get(60, TimeUnit.SECONDS); - assertNotNull(response); - assertEquals(Response.Status.OK, response.getStatus()); - StringBuilder str = new StringBuilder(); - Reader in = new InputStreamReader(content.toStream(), StandardCharsets.UTF_8); - for (int c; (c = in.read()) != -1; ) { - str.append((char)c); - } - return str.toString(); - } - - private JsonNode requestAsJson(String requestUri) throws Exception { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readTree(mapper.getFactory().createParser(requestAsString(requestUri))); - } } |