use of com.alipay.lookout.api.Registry 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());
}
use of com.alipay.lookout.api.Registry 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());
}
use of com.alipay.lookout.api.Registry 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);
}
}
}
use of com.alipay.lookout.api.Registry 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();
}
use of com.alipay.lookout.api.Registry 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();
}
}
Aggregations