Search in sources :

Example 1 with SwitchDomain

use of com.alibaba.nacos.naming.misc.SwitchDomain in project nacos by alibaba.

the class OperatorControllerTest method testSwitchDomainForNotSupportUpgrade.

@Test
public void testSwitchDomainForNotSupportUpgrade() {
    MockEnvironment environment = new MockEnvironment();
    EnvUtil.setEnvironment(environment);
    SwitchDomain switchDomain = operatorController.switches(new MockHttpServletRequest());
    SwitchDomain expected = new SwitchDomain();
    expected.update(switchDomain);
    expected.setDoubleWriteEnabled(false);
    Assert.assertEquals(expected.toString(), switchDomain.toString());
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 2 with SwitchDomain

use of com.alibaba.nacos.naming.misc.SwitchDomain in project nacos by alibaba.

the class ServerStatusManagerTest method testUpdaterFromSwitch.

@Test
public void testUpdaterFromSwitch() {
    SwitchDomain switchDomain = mock(SwitchDomain.class);
    String expect = ServerStatus.DOWN.toString();
    when(switchDomain.getOverriddenServerStatus()).thenReturn(expect);
    ServerStatusManager serverStatusManager = new ServerStatusManager(switchDomain);
    ServerStatusManager.ServerStatusUpdater updater = serverStatusManager.new ServerStatusUpdater();
    // then
    updater.run();
    // then
    ServerStatus serverStatus = serverStatusManager.getServerStatus();
    Assert.assertEquals(expect, serverStatus.toString());
}
Also used : SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) Test(org.junit.Test)

Example 3 with SwitchDomain

use of com.alibaba.nacos.naming.misc.SwitchDomain in project nacos by alibaba.

the class ServerStatusManagerTest method testUpdaterFromConsistency1.

@Test
public void testUpdaterFromConsistency1() throws NoSuchFieldException, IllegalAccessException {
    SwitchDomain switchDomain = mock(SwitchDomain.class);
    ServerStatusManager serverStatusManager = new ServerStatusManager(switchDomain);
    Field field = ServerStatusManager.class.getDeclaredField("consistencyService");
    field.setAccessible(true);
    ConsistencyService consistencyService = mock(ConsistencyService.class);
    when(consistencyService.isAvailable()).thenReturn(true);
    field.set(serverStatusManager, consistencyService);
    ServerStatusManager.ServerStatusUpdater updater = serverStatusManager.new ServerStatusUpdater();
    // then
    updater.run();
    // then
    Assert.assertEquals(ServerStatus.UP, serverStatusManager.getServerStatus());
}
Also used : Field(java.lang.reflect.Field) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) ConsistencyService(com.alibaba.nacos.naming.consistency.ConsistencyService) Test(org.junit.Test)

Example 4 with SwitchDomain

use of com.alibaba.nacos.naming.misc.SwitchDomain in project nacos by alibaba.

the class OperatorControllerTest method testSwitchDomain.

@Test
public void testSwitchDomain() {
    SwitchDomain switchDomain = operatorController.switches(new MockHttpServletRequest());
    Assert.assertEquals(this.switchDomain, switchDomain);
}
Also used : SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 5 with SwitchDomain

use of com.alibaba.nacos.naming.misc.SwitchDomain 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)

Aggregations

SwitchDomain (com.alibaba.nacos.naming.misc.SwitchDomain)9 Test (org.junit.Test)5 Before (org.junit.Before)3 ConsistencyService (com.alibaba.nacos.naming.consistency.ConsistencyService)2 Field (java.lang.reflect.Field)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 Member (com.alibaba.nacos.core.cluster.Member)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 HashSet (java.util.HashSet)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1