Search in sources :

Example 6 with Id

use of com.alipay.lookout.api.Id 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 7 with Id

use of com.alipay.lookout.api.Id 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 8 with Id

use of com.alipay.lookout.api.Id 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 9 with Id

use of com.alipay.lookout.api.Id 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)

Example 10 with Id

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

the class RpcLookout method collectClient.

/**
 * Collect the RPC client information.
 *
 * @param rpcClientMetricsModel client information model
 */
public void collectClient(RpcClientLookoutModel rpcClientMetricsModel) {
    try {
        Id methodConsumerId = createMethodConsumerId(rpcClientMetricsModel);
        MixinMetric methodConsumerMetric = Lookout.registry().mixinMetric(methodConsumerId);
        recordCounterAndTimer(methodConsumerMetric, rpcClientMetricsModel);
        recordSize(methodConsumerMetric, rpcClientMetricsModel);
    } catch (Throwable t) {
        LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
    }
}
Also used : MixinMetric(com.alipay.lookout.api.composite.MixinMetric) Id(com.alipay.lookout.api.Id)

Aggregations

Id (com.alipay.lookout.api.Id)12 Metric (com.alipay.lookout.api.Metric)5 NoopRegistry (com.alipay.lookout.api.NoopRegistry)5 Registry (com.alipay.lookout.api.Registry)5 DefaultRegistry (com.alipay.lookout.core.DefaultRegistry)5 MixinMetric (com.alipay.lookout.api.composite.MixinMetric)2 After (org.junit.After)2 BeforeClass (org.junit.BeforeClass)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 ArrayList (java.util.ArrayList)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1