// Path: src/main/java/com/baidu/unbiz/multiengine/endpoint/supervisor/DefaultEndpointSupervisor.java
// public class DefaultEndpointSupervisor implements EndpointSupervisor {
//     private static final Logger LOG = AopLogFactory.getLogger(DefaultEndpointSupervisor.class);
// 
//     private static List<TaskServer> taskServers;
//     private GossipSupport gossipSupport;
//     private HeartbeatSupport heartbeatSupport;
// 
//     private String exportPort;
//     private String serverHost;
// 
//     public DefaultEndpointSupervisor() {
//         taskServers = new CopyOnWriteArrayList<TaskServer>();
//         gossipSupport = new GossipSupport();
//         heartbeatSupport = new HeartbeatSupport() {
//             @Override
//             public void tryRestartEndpoint(TaskClient taskClient) {
//                 doTryRestartEndpoint(taskClient);
//             }
//         };
//     }
// 
//     public static List<HostConf> getTaskHostConf() {
//         List<HostConf> hostConfs = new ArrayList<HostConf>();
//         // fixme
// //        for(TaskServer taskServer : taskServers){
// //            hostConfs.internalAdd(taskServer.getHostConf());
// //        }
//         hostConfs.addAll(EndpointPool.getTaskHostConf());
//         return hostConfs;
//     }
// 
//     public static List<HostConf> mergeTaskServer(List<HostConf> otherHost) {
//         List<HostConf> hostConfs = getTaskHostConf();
//         otherHost.removeAll(hostConfs);
//         EndpointPool.add(otherHost);
//         return hostConfs;
//     }
// 
//     /**
//      * default: heartbeat and gossip
//      */
//     @Override
//     public void init() {
//         List<HostConf> exportHosts = HostConf.resolvePort(exportPort);
//         for (HostConf hostConf : exportHosts) {
//             TaskServer taskServer = TaskServerFactory.createTaskServer(hostConf);
//             taskServer.start();
//             taskServers.add(taskServer);
//         }
//         List<HostConf> clientHost = HostConf.resolveHost(this.serverHost);
//         EndpointPool.init(clientHost);
// 
//         heartbeatSupport.scheduleHeartbeat();
//         gossipSupport.scheduleGossip();
//     }
// 
//     @Override
//     public void stop() {
//         EndpointPool.stop();
//         if (CollectionUtils.isEmpty(taskServers)) {
//             return;
//         }
//         for (TaskServer taskServer : taskServers) {
//             taskServer.stop();
//         }
// 
//         heartbeatSupport.shutdownScheduler();
//         gossipSupport.shutdownScheduler();
//     }
// 
//     protected void doTryRestartEndpoint(TaskClient taskClient) {
//         try {
//             taskClient.restart();
//         } catch (Exception e) {
//             // do nothing
//         }
//     }
// 
//     public String getServerHost() {
//         return serverHost;
//     }
// 
//     public void setServerHost(String serverHost) {
//         this.serverHost = serverHost;
//     }
// 
//     public String getExportPort() {
//         return exportPort;
//     }
// 
//     public void setExportPort(String exportPort) {
//         this.exportPort = exportPort;
//     }
// }
// 
// Path: src/test/java/com/baidu/unbiz/multiengine/utils/TestUtils.java
// public class TestUtils {
//     public static final long VERY_LONG_TIME = 2000 * 1000;
// 
//     public static void dumySleep(long time) {
//         try {
//             Thread.sleep(time);
//         } catch (InterruptedException e) {
//             // do nothing
//         }
//     }
// }


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baidu.unbiz.multiengine.endpoint.supervisor.DefaultEndpointSupervisor;
import com.baidu.unbiz.multiengine.utils.TestUtils;
package com.baidu.unbiz.multiengine.demo.test;



/**
 * Created by wangchongjie on 16/4/18.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/applicationContext-test2.xml")
public class TestMultiProcessServer3 {

    private DefaultEndpointSupervisor supervisor = new DefaultEndpointSupervisor();

    @Before
    public void init() {
        supervisor.setExportPort("8803");
        supervisor.setServerHost("127.0.0.1:8801;127.0.0.1:8803");
        supervisor.init();
    }

    @After
    public void clean() {
        supervisor.stop();
    }

    /**
     * 测试分布式并行执行task
     */
    @Test
    public void runServer() {
// Path: src/main/java/com/baidu/unbiz/multiengine/endpoint/supervisor/DefaultEndpointSupervisor.java
// public class DefaultEndpointSupervisor implements EndpointSupervisor {
//     private static final Logger LOG = AopLogFactory.getLogger(DefaultEndpointSupervisor.class);
// 
//     private static List<TaskServer> taskServers;
//     private GossipSupport gossipSupport;
//     private HeartbeatSupport heartbeatSupport;
// 
//     private String exportPort;
//     private String serverHost;
// 
//     public DefaultEndpointSupervisor() {
//         taskServers = new CopyOnWriteArrayList<TaskServer>();
//         gossipSupport = new GossipSupport();
//         heartbeatSupport = new HeartbeatSupport() {
//             @Override
//             public void tryRestartEndpoint(TaskClient taskClient) {
//                 doTryRestartEndpoint(taskClient);
//             }
//         };
//     }
// 
//     public static List<HostConf> getTaskHostConf() {
//         List<HostConf> hostConfs = new ArrayList<HostConf>();
//         // fixme
// //        for(TaskServer taskServer : taskServers){
// //            hostConfs.internalAdd(taskServer.getHostConf());
// //        }
//         hostConfs.addAll(EndpointPool.getTaskHostConf());
//         return hostConfs;
//     }
// 
//     public static List<HostConf> mergeTaskServer(List<HostConf> otherHost) {
//         List<HostConf> hostConfs = getTaskHostConf();
//         otherHost.removeAll(hostConfs);
//         EndpointPool.add(otherHost);
//         return hostConfs;
//     }
// 
//     /**
//      * default: heartbeat and gossip
//      */
//     @Override
//     public void init() {
//         List<HostConf> exportHosts = HostConf.resolvePort(exportPort);
//         for (HostConf hostConf : exportHosts) {
//             TaskServer taskServer = TaskServerFactory.createTaskServer(hostConf);
//             taskServer.start();
//             taskServers.add(taskServer);
//         }
//         List<HostConf> clientHost = HostConf.resolveHost(this.serverHost);
//         EndpointPool.init(clientHost);
// 
//         heartbeatSupport.scheduleHeartbeat();
//         gossipSupport.scheduleGossip();
//     }
// 
//     @Override
//     public void stop() {
//         EndpointPool.stop();
//         if (CollectionUtils.isEmpty(taskServers)) {
//             return;
//         }
//         for (TaskServer taskServer : taskServers) {
//             taskServer.stop();
//         }
// 
//         heartbeatSupport.shutdownScheduler();
//         gossipSupport.shutdownScheduler();
//     }
// 
//     protected void doTryRestartEndpoint(TaskClient taskClient) {
//         try {
//             taskClient.restart();
//         } catch (Exception e) {
//             // do nothing
//         }
//     }
// 
//     public String getServerHost() {
//         return serverHost;
//     }
// 
//     public void setServerHost(String serverHost) {
//         this.serverHost = serverHost;
//     }
// 
//     public String getExportPort() {
//         return exportPort;
//     }
// 
//     public void setExportPort(String exportPort) {
//         this.exportPort = exportPort;
//     }
// }
// 
// Path: src/test/java/com/baidu/unbiz/multiengine/utils/TestUtils.java
// public class TestUtils {
//     public static final long VERY_LONG_TIME = 2000 * 1000;
// 
//     public static void dumySleep(long time) {
//         try {
//             Thread.sleep(time);
//         } catch (InterruptedException e) {
//             // do nothing
//         }
//     }
// }


// Path: src/test/java/com/baidu/unbiz/multiengine/demo/test/TestMultiProcessServer3.java
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baidu.unbiz.multiengine.endpoint.supervisor.DefaultEndpointSupervisor;
import com.baidu.unbiz.multiengine.utils.TestUtils;

package com.baidu.unbiz.multiengine.demo.test;



/**
 * Created by wangchongjie on 16/4/18.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/applicationContext-test2.xml")
public class TestMultiProcessServer3 {

    private DefaultEndpointSupervisor supervisor = new DefaultEndpointSupervisor();

    @Before
    public void init() {
        supervisor.setExportPort("8803");
        supervisor.setServerHost("127.0.0.1:8801;127.0.0.1:8803");
        supervisor.init();
    }

    @After
    public void clean() {
        supervisor.stop();
    }

    /**
     * 测试分布式并行执行task
     */
    @Test
    public void runServer() {
        TestUtils.dumySleep(TestUtils.VERY_LONG_TIME);