want.number(nodes.get(3)).isEqualTo(node4.getId());
}
@Test
public void testAliveNodes_dead() {
NodeMonitor nodeMonitor = new NodeMonitor();
nodeEvent.destory(node1.getId()); // 关闭一个节点
sleep(); // 需要间隔一定的时间,zookeeper需要推送数据到NodeMonitor,时间间隔在10ms以内
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());
}