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();
}
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());
}
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());
}
Aggregations