Search in sources :

Example 41 with Member

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 42 with Member

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);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) Member(com.alibaba.nacos.core.cluster.Member) StandardEnvironment(org.springframework.core.env.StandardEnvironment) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 43 with Member

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 44 with Member

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());
}
Also used : Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 45 with Member

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()));
}
Also used : Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Aggregations

Member (com.alibaba.nacos.core.cluster.Member)53 Test (org.junit.Test)17 NacosException (com.alibaba.nacos.api.exception.NacosException)11 HashMap (java.util.HashMap)11 Response (com.alibaba.nacos.api.remote.response.Response)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)6 Map (java.util.Map)5 ServerLoaderInfoResponse (com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse)4 NacosAsyncRestTemplate (com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate)4 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Before (org.junit.Before)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ServerAbilities (com.alibaba.nacos.api.ability.ServerAbilities)3 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)3 ServerRemoteAbility (com.alibaba.nacos.api.remote.ability.ServerRemoteAbility)3 RestResult (com.alibaba.nacos.common.model.RestResult)3 GenericType (com.alibaba.nacos.core.utils.GenericType)3