Java Code Examples for com.alipay.sofa.rpc.config.ServerConfig#destroy()

The following examples show how to use com.alipay.sofa.rpc.config.ServerConfig#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerConfigContainer.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
private void destroyServerConfig(ServerConfig serverConfig) {
    if (serverConfig != null) {
        Server server = serverConfig.getServer();
        if (server != null && server.hasNoEntry()) {
            serverConfig.destroy();
        }
    }
}
 
Example 2
Source File: ServerFactoryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Test
public void destroyServer() {
    ServerConfig serverConfig = new ServerConfig().setProtocol("test").setPort(1234);
    Server server = serverConfig.buildIfAbsent();
    Assert.assertNotNull(server);
    Assert.assertEquals(1, ServerFactory.getServers().size());
    serverConfig.destroy();
    Assert.assertEquals(0, ServerFactory.getServers().size());
    Assert.assertNull(serverConfig.getServer());
}
 
Example 3
Source File: FailoverClusterTest.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Test
public void testStick() {

    // 发布一个服务,每个请求要执行2秒
    ServerConfig serverConfig = new ServerConfig()
        .setStopTimeout(0)
        .setPort(22227)
        .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
        .setQueues(100).setCoreThreads(5).setMaxThreads(5);
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setRef(new HelloServiceImpl("77"))
        .setServer(serverConfig)
        .setRepeatedExportLimit(-1)
        .setRegister(false);
    providerConfig.export();

    // 再发布一个服务,不等待
    ServerConfig serverConfig2 = new ServerConfig()
        .setStopTimeout(0)
        .setPort(22228)
        .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
        .setQueues(100).setCoreThreads(5).setMaxThreads(5);
    ProviderConfig<HelloService> providerConfig2 = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setRef(new HelloServiceImpl("88"))
        .setServer(serverConfig2)
        .setRepeatedExportLimit(-1)
        .setRegister(false);
    providerConfig2.export();

    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setDirectUrl("bolt://127.0.0.1:22227;bolt://127.0.0.1:22228")
        .setTimeout(1000)
        .setCluster("failover")
        .setLoadBalancer("random")
        .setSticky(true)
        .setRegister(false);
    final HelloService helloService = consumerConfig.refer();

    int count2 = 0;
    String result = helloService.sayHello("xxx", 22);
    for (int i = 0; i < 10; i++) {
        try {
            Assert.assertEquals(result, helloService.sayHello("xxx", 22));
            count2++;
        } catch (Exception ignore) {
        }
    }
    Assert.assertEquals(count2, 10);

    String nextResult;
    if ("77".equals(result)) {
        serverConfig.destroy();
        nextResult = "88";
    } else {
        serverConfig2.destroy();
        nextResult = "77";
    }
    try {
        Assert.assertEquals(nextResult, helloService.sayHello("xxx", 22));
        count2++;
    } catch (Exception e) {
    }
    Assert.assertEquals(count2, 10);

}