use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.
the class FaultBaseTest method getProviderInfoByHost.
static ProviderInfo getProviderInfoByHost(ConsumerConfig consumerConfig, String host) {
ConsumerBootstrap consumerBootStrap = consumerConfig.getConsumerBootstrap();
AddressHolder addressHolder = consumerBootStrap.getCluster().getAddressHolder();
List<ProviderGroup> providerGroups = addressHolder.getProviderGroups();
for (ProviderGroup providerGroup : providerGroups) {
for (ProviderInfo providerInfo : providerGroup.getProviderInfos()) {
if (providerInfo.getHost().equals(host)) {
return providerInfo;
}
}
}
return null;
}
use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.
the class AbstractClusterTest method testDestroyWithDestroyHook.
@Test
public void testDestroyWithDestroyHook() {
ConsumerConfig consumerConfig = new ConsumerConfig().setProtocol("test").setBootstrap("test");
ConsumerBootstrap consumerBootstrap = new ConsumerBootstrap(consumerConfig) {
@Override
public Object refer() {
return null;
}
@Override
public void unRefer() {
}
@Override
public Object getProxyIns() {
return null;
}
@Override
public Cluster getCluster() {
return null;
}
@Override
public List<ProviderGroup> subscribe() {
return null;
}
@Override
public boolean isSubscribed() {
return false;
}
};
AbstractCluster abstractCluster = new AbstractCluster(consumerBootstrap) {
@Override
protected SofaResponse doInvoke(SofaRequest msg) throws SofaRpcException {
return null;
}
};
List<String> hookActionResult = new ArrayList<>(2);
Destroyable.DestroyHook destroyHook = new Destroyable.DestroyHook() {
@Override
public void preDestroy() {
hookActionResult.add("preDestroy");
}
@Override
public void postDestroy() {
hookActionResult.add("postDestroy");
}
};
abstractCluster.destroy(destroyHook);
Assert.assertEquals(2, hookActionResult.size());
Assert.assertEquals("preDestroy", hookActionResult.get(0));
Assert.assertEquals("postDestroy", hookActionResult.get(1));
}
use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.
the class LoadBalancerFactoryTest method getLoadBalancer.
@Test
public void getLoadBalancer() throws Exception {
ConsumerConfig consumerConfig = new ConsumerConfig().setBootstrap("test").setLoadBalancer("test");
ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
Assert.assertEquals(LoadBalancerFactory.getLoadBalancer(bootstrap).getClass(), TestLoadBalancer.class);
boolean error = false;
try {
consumerConfig.setLoadBalancer("xasdsa");
LoadBalancerFactory.getLoadBalancer(bootstrap);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(error);
}
use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.
the class DubboServerTest method testRegistrySync.
@Test
public // 同步调用,走服务注册中心
void testRegistrySync() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig().setStopTimeout(10).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2).setHost(SystemInfo.getLocalHost());
// 发布一个服务,每个请求要执行1秒
ApplicationConfig serverApplacation = new ApplicationConfig();
serverApplacation.setAppName("server");
List<RegistryConfig> registryConfigs = new ArrayList<RegistryConfig>();
RegistryConfig registryConfig;
registryConfig = new RegistryConfig().setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK).setAddress("127.0.0.1:2181").setSubscribe(true).setRegister(true);
List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
MethodConfig methodConfig = new MethodConfig();
methodConfig.setTimeout(3000);
methodConfig.setName("sayHello");
methodConfigs.add(methodConfig);
registryConfigs.add(registryConfig);
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl()).setServer(serverConfig).setRegister(true).setBootstrap("dubbo").setRegistry(registryConfigs).setApplication(serverApplacation);
providerConfig.export();
ApplicationConfig clientApplication = new ApplicationConfig();
clientApplication.setAppName("client");
ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setTimeout(30000).setRegister(true).setProtocol("dubbo").setApplication(clientApplication).setRegistry(registryConfigs).setMethods(methodConfigs).setInJVM(false);
final HelloService demoService = consumerConfig.refer();
String result = demoService.sayHello("xxx", 22);
Assert.assertNotNull(result);
ConsumerBootstrap bootstrap = consumerConfig.getConsumerBootstrap();
Assert.assertTrue(bootstrap instanceof DubboConsumerBootstrap);
Assert.assertTrue(bootstrap.isSubscribed());
Assert.assertNotNull(bootstrap.getProxyIns());
bootstrap.unRefer();
try {
bootstrap.getCluster();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof UnsupportedOperationException);
}
try {
bootstrap.subscribe();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof UnsupportedOperationException);
}
}
use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.
the class BoltClientProxyInvokerTest method testParseSerializeType.
@Test
public void testParseSerializeType() throws Exception {
ConsumerConfig consumerConfig = new ConsumerConfig().setProtocol("bolt");
ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
BoltClientProxyInvoker invoker = new BoltClientProxyInvoker(bootstrap);
byte actual = invoker.parseSerializeType(RpcConstants.SERIALIZE_HESSIAN2);
assertEquals(RemotingConstants.SERIALIZE_CODE_HESSIAN, actual);
}
Aggregations