Search in sources :

Example 11 with Metric

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

the class RpcLookoutTest method testFutureServiceStats.

/**
 * test provider service stats
 */
@Test
public void testFutureServiceStats() {
    // future
    for (int i = 0; i < 4; i++) {
        try {
            lookoutService.sayFuture("lookout_future");
            SofaResponseFuture.getResponse(3000, true);
        } catch (Exception e) {
            LOGGER.error("future error", e);
        }
    }
    try {
        TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String methodName = "sayFuture";
    Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
    if (metric == null) {
        Assert.fail("no provider metric was found null");
    }
    assertMethod(metric, true, 4, methodName, 0, 0);
    Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
    if (consumerMetric == null) {
        Assert.fail("no consumer metric was found null");
    }
    assertMethod(consumerMetric, false, 4, methodName, 1620, 534);
}
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)

Example 12 with Metric

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

the class RpcLookoutTest method after.

@After
public void after() {
    final Registry currentRegistry = Lookout.registry();
    // clear all metrics now
    Iterator<Metric> itar = currentRegistry.iterator();
    while (itar.hasNext()) {
        Metric metric = itar.next();
        Id id = metric.id();
        currentRegistry.removeMetric(id);
    }
    if (serverConfig != null) {
        serverConfig.destroy();
    }
    if (providerConfig != null) {
        providerConfig.unExport();
    }
    if (consumerConfig != null) {
        consumerConfig.unRefer();
    }
}
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 13 with Metric

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

the class RpcLookoutTest method testThreadPoolConfig.

/**
 * test thread pool config
 *
 * @throws Exception Exception
 */
@Test
public void testThreadPoolConfig() throws Exception {
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.config", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        // 判断ThreadPool启动配置
        Object obj = measurement.value();
        assertEquals(30, corePoolSize.get(obj));
        assertEquals(500, maxPoolSize.get(obj));
        assertEquals(600, queueSize.get(obj));
    }
}
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 14 with Metric

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

the class RpcLookoutTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    RpcRunningState.setUnitTestMode(false);
    try {
        Class clazz = RpcLookout.class;
        Class[] innerClazzs = clazz.getDeclaredClasses();
        for (Class cls : innerClazzs) {
            if (cls.getName().contains("ThreadPoolConfig")) {
                corePoolSize = cls.getDeclaredField("corePoolSize");
                corePoolSize.setAccessible(true);
                maxPoolSize = cls.getDeclaredField("maxPoolSize");
                maxPoolSize.setAccessible(true);
                queueSize = cls.getDeclaredField("queueSize");
                queueSize.setAccessible(true);
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    Registry registry = new DefaultRegistry();
    final Registry currentRegistry = Lookout.registry();
    if (currentRegistry == NoopRegistry.INSTANCE) {
        Lookout.setRegistry(registry);
    } else {
        // clear all metrics now
        Iterator<Metric> itar = currentRegistry.iterator();
        while (itar.hasNext()) {
            Metric metric = itar.next();
            Id id = metric.id();
            currentRegistry.removeMetric(id);
        }
    }
}
Also used : DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) 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) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) BeforeClass(org.junit.BeforeClass)

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