use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class RaftPeerSetTest method testRaftPeerChange.
@Test
public void testRaftPeerChange() {
final AtomicBoolean notifyReceived = new AtomicBoolean(false);
RaftPeerSetCopy peerSetCopy = new RaftPeerSetCopy(memberManager, () -> {
notifyReceived.set(true);
});
Collection<Member> firstEvent = Arrays.asList(Member.builder().ip("127.0.0.1").port(80).build(), Member.builder().ip("127.0.0.2").port(81).build(), Member.builder().ip("127.0.0.3").port(82).build());
peerSetCopy.changePeers(firstEvent);
Assert.assertTrue(notifyReceived.get());
notifyReceived.set(false);
Collection<Member> secondEvent = Arrays.asList(Member.builder().ip("127.0.0.1").port(80).build(), Member.builder().ip("127.0.0.2").port(81).build(), Member.builder().ip("127.0.0.3").port(82).build(), Member.builder().ip("127.0.0.4").port(83).build());
peerSetCopy.changePeers(secondEvent);
Assert.assertTrue(notifyReceived.get());
notifyReceived.set(false);
Collection<Member> thirdEvent = Arrays.asList(Member.builder().ip("127.0.0.1").port(80).build(), Member.builder().ip("127.0.0.2").port(81).build(), Member.builder().ip("127.0.0.5").port(82).build());
peerSetCopy.changePeers(thirdEvent);
Assert.assertTrue(notifyReceived.get());
notifyReceived.set(false);
Collection<Member> fourEvent = Arrays.asList(Member.builder().ip("127.0.0.1").port(80).build(), Member.builder().ip("127.0.0.2").port(81).build());
peerSetCopy.changePeers(fourEvent);
Assert.assertTrue(notifyReceived.get());
notifyReceived.set(false);
Collection<Member> fiveEvent = Arrays.asList(Member.builder().ip("127.0.0.1").port(80).build(), Member.builder().ip("127.0.0.3").port(81).build());
peerSetCopy.changePeers(fiveEvent);
Assert.assertTrue(notifyReceived.get());
notifyReceived.set(false);
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class DistroMapperTest method setUp.
@Before
public void setUp() {
ConcurrentSkipListMap<String, Member> serverList = new ConcurrentSkipListMap<>();
EnvUtil.setEnvironment(new StandardEnvironment());
serverList.put(ip1, Member.builder().ip(ip1).port(port).build());
serverList.put(ip2, Member.builder().ip(ip2).port(port).build());
serverList.put(ip3, Member.builder().ip(ip3).port(port).build());
EnvUtil.setLocalAddress(ip4);
serverList.put(EnvUtil.getLocalAddress(), Member.builder().ip(EnvUtil.getLocalAddress()).port(port).build());
HashSet<Member> set = new HashSet<>(serverList.values());
switchDomain = new SwitchDomain();
distroMapper = new DistroMapper(memberManager, switchDomain);
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ClusterVersionJudgementTest method testPartMemberUpdateToNewVersion.
@Test
public void testPartMemberUpdateToNewVersion() {
// Firstly, make a cluster with a part of new version servers.
Collection<Member> allMembers = manager.allMembers();
AtomicInteger count = new AtomicInteger();
allMembers.forEach(member -> {
if (count.get() == 0) {
member.setExtendInfo(oldVersionMeta);
} else {
count.incrementAndGet();
member.setExtendInfo(newVersionMeta);
}
});
judgement = new ClusterVersionJudgement(manager);
judgement.judge();
Assert.assertFalse(judgement.allMemberIsNewVersion());
// Secondly, make all in the cluster to be new version servers.
allMembers.forEach(member -> member.setExtendInfo(newVersionMeta));
judgement = new ClusterVersionJudgement(manager);
judgement.judge();
Assert.assertTrue(judgement.allMemberIsNewVersion());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterControllerTest method testSelf.
@Test
public void testSelf() {
Member self = new Member();
Mockito.when(serverMemberManager.getSelf()).thenReturn(self);
RestResult<Member> result = nacosClusterController.self();
Assert.assertEquals(self, result.getData());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterControllerTest method testReport.
@Test
public void testReport() {
Mockito.when(serverMemberManager.update(Mockito.any())).thenReturn(true);
Member member = new Member();
member.setIp("1.1.1.1");
member.setPort(8848);
member.setAddress("test");
RestResult<String> result = nacosClusterController.report(member);
Assert.assertTrue(Boolean.parseBoolean(result.getData()));
}
Aggregations