Search in sources :

Example 6 with Metric

use of com.alipay.lookout.api.Metric in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolQueueSize.

/**
 * test thread pool queue size
 */
@Test
public void testThreadPoolQueueSize() {
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.queue.size", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(0, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 7 with Metric

use of com.alipay.lookout.api.Metric in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolIdleCount.

/**
 * test thread pool idle count
 */
@Test
public void testThreadPoolIdleCount() {
    // sync invoke some time
    for (int i = 0; i < 3; i++) {
        try {
            lookoutService.saySync("lookout_sync");
        } catch (Exception e) {
            LOGGER.error("sync error", e);
        }
    }
    try {
        TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.idle.count", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(3, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 8 with Metric

use of com.alipay.lookout.api.Metric in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolActiveCount.

/**
 * test thread pool active count
 *
 * @throws Exception Exception
 */
@Test
public void testThreadPoolActiveCount() throws Exception {
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.active.count", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(0, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 9 with Metric

use of com.alipay.lookout.api.Metric in project sofa-rpc by sofastack.

the class RestLookoutTest method afterMethod.

@After
public void afterMethod() {
    // clear all metrics now
    Registry currentRegistry = Lookout.registry();
    Iterator<Metric> itar = currentRegistry.iterator();
    while (itar.hasNext()) {
        Metric metric = itar.next();
        Id id = metric.id();
        currentRegistry.removeMetric(id);
    }
    if (providerConfig != null) {
        providerConfig.unExport();
    }
    if (consumerConfig != null) {
        consumerConfig.unRefer();
    }
    if (serverConfig != null) {
        serverConfig.destroy();
    }
}
Also used : Metric(com.alipay.lookout.api.Metric) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) Id(com.alipay.lookout.api.Id) After(org.junit.After)

Example 10 with Metric

use of com.alipay.lookout.api.Metric in project sofa-rpc by sofastack.

the class RpcLookoutTest method testCallbackServiceStats.

/**
 * test provider service stats
 */
@Test
public void testCallbackServiceStats() {
    // callback
    for (int i = 0; i < 5; i++) {
        try {
            lookoutService.sayCallback("lookout_callback");
        } catch (Exception e) {
            LOGGER.error("callback error", e);
        }
    }
    for (int i = 0; i < 10; i++) {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
        }
        if (onReturn.getSize() == 5) {
            break;
        }
    }
    String methodName = "sayCallback";
    Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
    if (metric == null) {
        Assert.fail("no provider metric was found null");
    }
    assertMethod(metric, true, 5, methodName, 0, 0);
    Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
    if (consumerMetric == null) {
        Assert.fail("no consumer eetric was found null");
    }
    assertMethod(consumerMetric, false, 5, methodName, 2045, 720);
}
Also used : Metric(com.alipay.lookout.api.Metric) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Aggregations

Metric (com.alipay.lookout.api.Metric)14 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)9 Test (org.junit.Test)9 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)6 Id (com.alipay.lookout.api.Id)5 NoopRegistry (com.alipay.lookout.api.NoopRegistry)5 Registry (com.alipay.lookout.api.Registry)5 DefaultRegistry (com.alipay.lookout.core.DefaultRegistry)5 Measurement (com.alipay.lookout.api.Measurement)4 After (org.junit.After)2 BeforeClass (org.junit.BeforeClass)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 ArrayList (java.util.ArrayList)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1