Search in sources :

Example 1 with NodeMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor in project otter by alibaba.

the class BaseLoadBalanceTest method init.

@BeforeClass
public void init() {
    // 初始化节点
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            return channel;
        }

        @Mock
        public Long getCurrentNid() {
            return 1L;
        }
    });
    node1.setId(1L);
    node2.setId(2L);
    node3.setId(3L);
    node4.setId(4L);
    zookeeper = getZookeeper();
    nodeEvent = new NodeArbitrateEvent();
    nodeMonitor = new NodeMonitor();
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) NodeMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor) Mock(mockit.Mock) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with NodeMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor in project otter by alibaba.

the class NodeMonitorTest method testAliveNodes_dead.

@Test
public void testAliveNodes_dead() {
    NodeMonitor nodeMonitor = new NodeMonitor();
    // 关闭一个节点
    nodeEvent.destory(node1.getId());
    // 需要间隔一定的时间,zookeeper需要推送数据到NodeMonitor,时间间隔在10ms以内
    sleep();
    List<Long> nodes = nodeMonitor.getAliveNodes();
    want.bool(nodes.size() == 3).is(true);
    want.number(nodes.get(0)).isEqualTo(node2.getId());
    want.number(nodes.get(1)).isEqualTo(node3.getId());
    want.number(nodes.get(2)).isEqualTo(node4.getId());
    // 开启一个节点
    nodeEvent.init(node1.getId());
    // 关闭一个节点
    nodeEvent.destory(node3.getId());
    sleep();
    nodes = nodeMonitor.getAliveNodes();
    want.bool(nodes.size() == 3).is(true);
    want.number(nodes.get(0)).isEqualTo(node1.getId());
    want.number(nodes.get(1)).isEqualTo(node2.getId());
    want.number(nodes.get(2)).isEqualTo(node4.getId());
}
Also used : NodeMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 3 with NodeMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor in project otter by alibaba.

the class NodeMonitorTest method testAliveNodes_all.

@Test
public void testAliveNodes_all() {
    NodeMonitor nodeMonitor = new NodeMonitor();
    List<Long> nodes = nodeMonitor.getAliveNodes();
    want.bool(nodes.size() == 4).is(true);
    want.number(nodes.get(0)).isEqualTo(node1.getId());
    want.number(nodes.get(1)).isEqualTo(node2.getId());
    want.number(nodes.get(2)).isEqualTo(node3.getId());
    want.number(nodes.get(3)).isEqualTo(node4.getId());
}
Also used : NodeMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Aggregations

NodeMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor)3 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)2 Test (org.testng.annotations.Test)2 NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)1 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)1 Mock (mockit.Mock)1 BeforeClass (org.testng.annotations.BeforeClass)1