Search in sources :

Example 1 with DefaultRegistry

use of com.alipay.lookout.core.DefaultRegistry in project sofa-rpc by sofastack.

the class ConsumerSubTest method testSubLookout.

@Test
public void testSubLookout() {
    Registry registry = new DefaultRegistry();
    if (Lookout.registry() == NoopRegistry.INSTANCE) {
        Lookout.setRegistry(registry);
    }
    LookoutModule lookoutModule = new LookoutModule();
    Assert.assertEquals(true, lookoutModule.needLoad());
    lookoutModule.install();
    ConsumerConfig consumerConfig = new ConsumerConfig();
    consumerConfig.setInterfaceId("a");
    EventBus.post(new ConsumerSubEvent(consumerConfig));
    try {
        TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    RpcLookoutId rpcLookoutId = new RpcLookoutId();
    InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchConsumerSubId());
    final Object value = result.value();
    Assert.assertTrue(value instanceof ConsumerConfig);
    consumerConfig = (ConsumerConfig) value;
    Assert.assertEquals("a", consumerConfig.getInterfaceId());
}
Also used : ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) RpcLookoutId(com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) InfoWrapper(com.alipay.lookout.core.InfoWrapper) Test(org.junit.Test)

Example 2 with DefaultRegistry

use of com.alipay.lookout.core.DefaultRegistry in project sofa-rpc by sofastack.

the class ProviderPubTest method testPubLookout.

@Test
public void testPubLookout() {
    Registry registry = new DefaultRegistry();
    if (Lookout.registry() == NoopRegistry.INSTANCE) {
        Lookout.setRegistry(registry);
    }
    LookoutModule lookoutModule = new LookoutModule();
    Assert.assertEquals(true, lookoutModule.needLoad());
    lookoutModule.install();
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setInterfaceId("a");
    EventBus.post(new ProviderPubEvent(providerConfig));
    try {
        TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    RpcLookoutId rpcLookoutId = new RpcLookoutId();
    InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchProviderPubId());
    final Object value = result.value();
    Assert.assertTrue(value instanceof ProviderConfig);
    providerConfig = (ProviderConfig) value;
    Assert.assertEquals("a", providerConfig.getInterfaceId());
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) RpcLookoutId(com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) InfoWrapper(com.alipay.lookout.core.InfoWrapper) Test(org.junit.Test)

Example 3 with DefaultRegistry

use of com.alipay.lookout.core.DefaultRegistry 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 4 with DefaultRegistry

use of com.alipay.lookout.core.DefaultRegistry 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

NoopRegistry (com.alipay.lookout.api.NoopRegistry)4 Registry (com.alipay.lookout.api.Registry)4 DefaultRegistry (com.alipay.lookout.core.DefaultRegistry)4 Id (com.alipay.lookout.api.Id)2 Metric (com.alipay.lookout.api.Metric)2 InfoWrapper (com.alipay.lookout.core.InfoWrapper)2 RpcLookoutId (com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)1 ProviderPubEvent (com.alipay.sofa.rpc.event.ProviderPubEvent)1 AfterClass (org.junit.AfterClass)1