use of com.netflix.spectator.api.ManualClock in project java-chassis by ServiceComb.
the class TestMetricsRestPublisher method measure_normal.
@Test
public void measure_normal() {
Clock clock = new ManualClock();
GlobalRegistry globalRegistry = new GlobalRegistry();
Registry registry = new DefaultRegistry(clock);
registry.timer(registry.createId("name", "t1", "v1", "t2", "v2"));
globalRegistry.add(registry);
EventBus eventBus = new EventBus();
publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
Map<String, Double> result = publisher.measure();
Assert.assertEquals(2, result.size());
Assert.assertEquals(0, result.get("name(statistic=count,t1=v1,t2=v2)"), 0);
Assert.assertEquals(0, result.get("name(statistic=totalTime,t1=v1,t2=v2)"), 0);
}
use of com.netflix.spectator.api.ManualClock in project incubator-servicecomb-java-chassis by apache.
the class TestPublishModelFactory method prepareRegistry.
protected Registry prepareRegistry() {
CompositeRegistry globalRegistry = SpectatorUtils.createCompositeRegistry(null);
Registry registry = new DefaultRegistry(new ManualClock());
EventBus eventBus = new EventBus();
DefaultMetricsInitializer metricsInitializer = new DefaultMetricsInitializer() {
protected Registry createRegistry(MetricsBootstrapConfig config) {
return registry;
}
};
metricsInitializer.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
new MockUp<System>() {
@Mock
long nanoTime() {
return 10;
}
};
invocationType = InvocationType.CONSUMER;
new MockUp<Invocation>() {
@Mock
InvocationType getInvocationType() {
return invocationType;
}
@Mock
boolean isConsumer() {
return InvocationType.CONSUMER.equals(invocationType);
}
@Mock
String getRealTransportName() {
return Const.RESTFUL;
}
@Mock
String getMicroserviceQualifiedName() {
return "m.s.o";
}
@Mock
long getStartExecutionTime() {
return 5;
}
};
new Expectations() {
{
response.getStatusCode();
result = 200;
}
};
InvocationFinishEvent finishEvent = new InvocationFinishEvent(invocation, response);
eventBus.post(finishEvent);
invocationType = InvocationType.PRODUCER;
eventBus.post(finishEvent);
return registry;
}
use of com.netflix.spectator.api.ManualClock in project java-chassis by ServiceComb.
the class TestPrometheusPublisher method collect.
@Test
public void collect() throws IllegalAccessException, IOException {
new Expectations(RegistrationManager.INSTANCE) {
{
RegistrationManager.INSTANCE.getAppId();
result = "testAppId";
}
};
ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:0");
publisher.init(globalRegistry, null, null);
Registry registry = new DefaultRegistry(new ManualClock());
globalRegistry.add(registry);
Counter counter = registry.counter("count.name", "tag1", "tag1v", "tag2", "tag2v");
counter.increment();
HTTPServer httpServer = (HTTPServer) FieldUtils.readField(publisher, "httpServer", true);
com.sun.net.httpserver.HttpServer server = (HttpServer) FieldUtils.readField(httpServer, "server", true);
URL url = new URL("http://localhost:" + server.getAddress().getPort() + "/metrics");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
try (InputStream is = conn.getInputStream()) {
Assert.assertEquals("# HELP ServiceComb_Metrics ServiceComb Metrics\n" + "# TYPE ServiceComb_Metrics untyped\n" + "count_name{appId=\"testAppId\",tag1=\"tag1v\",tag2=\"tag2v\",} 1.0\n", IOUtils.toString(is, StandardCharsets.UTF_8));
}
publisher.destroy();
}
Aggregations