Search in sources :

Example 1 with MetricConsumer

use of com.yahoo.jdisc.application.MetricConsumer in project vespa by vespa-engine.

the class ForwardingMetricConsumerTest method requireThatAllMethodsAreForwarded.

@Test
public void requireThatAllMethodsAreForwarded() {
    MetricConsumer fooConsumer = Mockito.mock(MetricConsumer.class);
    Metric.Context fooCtx = Mockito.mock(Metric.Context.class);
    Mockito.when(fooConsumer.createContext(Mockito.<Map<String, ?>>any())).thenReturn(fooCtx);
    MetricConsumer barConsumer = Mockito.mock(MetricConsumer.class);
    Metric.Context barCtx = Mockito.mock(Metric.Context.class);
    Mockito.when(barConsumer.createContext(Mockito.<Map<String, ?>>any())).thenReturn(barCtx);
    MetricConsumer fwdConsumer = new ForwardingMetricConsumer(new MetricConsumer[] { fooConsumer, barConsumer });
    Map<String, ?> properties = new HashMap<>();
    Metric.Context ctx = fwdConsumer.createContext(properties);
    assertNotNull(ctx);
    Mockito.verify(fooConsumer, Mockito.times(1)).createContext(properties);
    Mockito.verify(barConsumer, Mockito.times(1)).createContext(properties);
    fwdConsumer.add("a", 69, ctx);
    Mockito.verify(fooConsumer, Mockito.times(1)).add("a", 69, fooCtx);
    Mockito.verify(barConsumer, Mockito.times(1)).add("a", 69, barCtx);
    fwdConsumer.set("b", 96, ctx);
    Mockito.verify(fooConsumer, Mockito.times(1)).set("b", 96, fooCtx);
    Mockito.verify(barConsumer, Mockito.times(1)).set("b", 96, barCtx);
}
Also used : MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) HashMap(java.util.HashMap) Metric(com.yahoo.jdisc.Metric) Test(org.junit.Test)

Example 2 with MetricConsumer

use of com.yahoo.jdisc.application.MetricConsumer in project vespa by vespa-engine.

the class MetricConsumerProviderTest method requireThatSingleConsumerIsNotDelegated.

@Test
public void requireThatSingleConsumerIsNotDelegated() {
    MetricConsumer consumer = Mockito.mock(MetricConsumer.class);
    MetricConsumerProvider provider = MetricConsumerProviders.newSingletonFactories(consumer);
    assertSame(consumer, provider.newInstance());
}
Also used : MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) Test(org.junit.Test)

Example 3 with MetricConsumer

use of com.yahoo.jdisc.application.MetricConsumer in project vespa by vespa-engine.

the class StateMonitorBenchmarkTest method requireThatHealthMonitorDoesNotBlockMetricThreads.

@Test
public void requireThatHealthMonitorDoesNotBlockMetricThreads() throws Exception {
    StateMonitor monitor = new StateMonitor(new HealthMonitorConfig(new HealthMonitorConfig.Builder()), new SystemTimer());
    Provider<MetricConsumer> provider = MetricConsumerProviders.wrap(monitor);
    performUpdates(provider, 8);
    for (int i = 1; i <= NUM_THREADS; i *= 2) {
        long millis = performUpdates(provider, i);
        System.err.format("%2d threads, %5d millis => %9d ups\n", i, millis, (int) ((i * NUM_UPDATES) / (millis / 1000.0)));
    }
    monitor.deconstruct();
}
Also used : MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) HealthMonitorConfig(com.yahoo.container.jdisc.config.HealthMonitorConfig) SystemTimer(com.yahoo.jdisc.core.SystemTimer) Test(org.junit.Test)

Example 4 with MetricConsumer

use of com.yahoo.jdisc.application.MetricConsumer in project vespa by vespa-engine.

the class MetricConsumerProviderTest method requireThatMultipleConsumersAreDelegated.

@Test
public void requireThatMultipleConsumersAreDelegated() {
    MetricConsumer foo = Mockito.mock(MetricConsumer.class);
    MetricConsumer bar = Mockito.mock(MetricConsumer.class);
    MetricConsumerProvider provider = MetricConsumerProviders.newSingletonFactories(foo, bar);
    MetricConsumer consumer = provider.newInstance();
    assertNotSame(foo, consumer);
    assertNotSame(bar, consumer);
    consumer.add("foo", 6, null);
    Mockito.verify(foo, Mockito.times(1)).add("foo", 6, null);
    Mockito.verify(bar, Mockito.times(1)).add("foo", 6, null);
}
Also used : MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) Test(org.junit.Test)

Example 5 with MetricConsumer

use of com.yahoo.jdisc.application.MetricConsumer in project vespa by vespa-engine.

the class MetricConsumerProviderTest method requireThatDefaultConsumerFactoryIsStateMetric.

@Test
public void requireThatDefaultConsumerFactoryIsStateMetric() {
    MetricConsumer consumer = MetricConsumerProviders.newDefaultInstance().newInstance();
    assertEquals("StateMetricConsumer", consumer.getClass().getSimpleName());
}
Also used : MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) Test(org.junit.Test)

Aggregations

MetricConsumer (com.yahoo.jdisc.application.MetricConsumer)6 Test (org.junit.Test)6 Metric (com.yahoo.jdisc.Metric)2 HealthMonitorConfig (com.yahoo.container.jdisc.config.HealthMonitorConfig)1 SystemTimer (com.yahoo.jdisc.core.SystemTimer)1 HashMap (java.util.HashMap)1