Search in sources :

Example 1 with Metric

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

the class RestLookoutTest method testServiceStats.

/**
 * test provider service stats
 */
@Test
public void testServiceStats() {
    Assert.assertEquals(helloService.query(11), "hello world !null");
    // wait metrics info
    try {
        TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String methodName = "query";
    Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
    if (metric == null) {
        Assert.fail("no provider metric was found null");
    }
    assertMethod(metric, true, 1, methodName, 0, 0);
    // metrics for consumer
    Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
    if (consumerMetric == null) {
        Assert.fail("no consumer metric was found null");
    }
    assertMethod(consumerMetric, false, 1, methodName, 1203, 352);
}
Also used : Metric(com.alipay.lookout.api.Metric) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 2 with Metric

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

the class RestLookoutTest method beforeCurrentClass.

@BeforeClass
public static void beforeCurrentClass() {
    RpcRunningState.setUnitTestMode(false);
    JAXRSProviderManager.registerInternalProviderClass(LookoutRequestFilter.class);
    RpcRuntimeContext.putIfAbsent(RpcRuntimeContext.KEY_APPNAME, "TestLookOutServer");
    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) 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) BeforeClass(org.junit.BeforeClass)

Example 3 with Metric

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

the class RpcLookoutTest method before.

/**
 * invoke
 */
@Before
public void before() {
    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);
    }
    serverConfig = new ServerConfig().setPort(12201).setCoreThreads(30).setMaxThreads(500).setQueues(600).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    providerConfig = new ProviderConfig<LookoutService>().setInterfaceId(LookoutService.class.getName()).setRef(new LookoutServiceImpl()).setServer(serverConfig).setBootstrap("bolt").setRegister(false).setApplication(new ApplicationConfig().setAppName("TestLookOutServer"));
    providerConfig.export();
    MethodConfig methodConfigFuture = new MethodConfig().setName("sayFuture").setInvokeType("future");
    onReturn = new CountSofaResponseCallback();
    MethodConfig methodConfigCallback = new MethodConfig().setName("sayCallback").setInvokeType("callback").setOnReturn(onReturn);
    MethodConfig methodConfigOneway = new MethodConfig().setName("sayOneway").setInvokeType("oneway");
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    methodConfigs.add(methodConfigFuture);
    methodConfigs.add(methodConfigCallback);
    methodConfigs.add(methodConfigOneway);
    consumerConfig = new ConsumerConfig<LookoutService>().setInterfaceId(LookoutService.class.getName()).setProtocol("bolt").setBootstrap("bolt").setMethods(methodConfigs).setTimeout(3000).setRegister(false).setDirectUrl("bolt://127.0.0.1:12201?appName=TestLookOutServer").setApplication(new ApplicationConfig().setAppName("TestLookOutClient"));
    lookoutService = consumerConfig.refer();
}
Also used : ArrayList(java.util.ArrayList) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) Metric(com.alipay.lookout.api.Metric) Id(com.alipay.lookout.api.Id) Before(org.junit.Before)

Example 4 with Metric

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

the class RpcLookoutTest method testOnewayServiceStats.

/**
 * test provider service stats
 */
@Test
public void testOnewayServiceStats() {
    // oneway
    for (int i = 0; i < 6; i++) {
        try {
            lookoutService.sayOneway("lookout_oneway");
        } catch (Exception e) {
            LOGGER.error("oneway error", e);
        }
    }
    try {
        TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String methodName = "sayOneway";
    Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
    if (metric == null) {
        Assert.fail("no provider metric was found null");
    }
    assertMethod(metric, true, 6, 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, 6, methodName, 2430, 0);
}
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 5 with Metric

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

the class RpcLookoutTest method testSyncServiceStats.

/**
 * test provider service stats
 */
@Test
public void testSyncServiceStats() {
    System.out.println("start where is the log");
    // sync
    for (int i = 0; i < 3; i++) {
        try {
            lookoutService.saySync("lookout_sync");
            System.out.println("lookout_sync invoke success");
        } catch (Exception e) {
            LOGGER.error("sync error", e);
        }
    }
    try {
        TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
        LOGGER.error("wait InterruptedException", e);
    }
    String methodName = "saySync";
    Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
    Assert.assertNotEquals("metrics is null", null, metric);
    if (metric == null) {
        Assert.fail("no provider metric was found null");
    }
    assertMethod(metric, true, 3, 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, 3, methodName, 1203, 352);
}
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