Search in sources :

Example 1 with DataCenterInfo

use of org.apache.servicecomb.serviceregistry.api.registry.DataCenterInfo in project incubator-servicecomb-java-chassis by apache.

the class TestZoneAwareServerListFilterExt method testZoneAwareServerListFilterExt.

@Test
public void testZoneAwareServerListFilterExt(@Mocked RegistryUtils registryUtils) {
    MicroserviceInstance myself = new MicroserviceInstance();
    DataCenterInfo info = new DataCenterInfo();
    info.setName("test");
    info.setRegion("test-Region");
    info.setAvailableZone("test-zone");
    myself.setDataCenterInfo(info);
    MicroserviceInstance allmatchInstance = new MicroserviceInstance();
    info = new DataCenterInfo();
    info.setName("test");
    info.setRegion("test-Region");
    info.setAvailableZone("test-zone");
    allmatchInstance.setDataCenterInfo(info);
    MicroserviceInstance regionMatchInstance = new MicroserviceInstance();
    info = new DataCenterInfo();
    info.setName("test");
    info.setRegion("test-Region");
    info.setAvailableZone("test-zone2");
    regionMatchInstance.setDataCenterInfo(info);
    MicroserviceInstance noneMatchInstance = new MicroserviceInstance();
    info = new DataCenterInfo();
    info.setName("test");
    info.setRegion("test-Region2");
    info.setAvailableZone("test-zone2");
    noneMatchInstance.setDataCenterInfo(info);
    new Expectations() {

        {
            RegistryUtils.getMicroserviceInstance();
            result = myself;
        }
    };
    ZoneAwareServerListFilterExt filter = new ZoneAwareServerListFilterExt();
    List<Server> servers = new ArrayList<>();
    CseServer noneMatchServer = new MockUp<CseServer>() {

        @Mock
        public String toString() {
            return "noneMatchServer";
        }

        @Mock
        public String getHost() {
            return "noneMatchServer";
        }

        @Mock
        public MicroserviceInstance getInstance() {
            return noneMatchInstance;
        }
    }.getMockInstance();
    CseServer regionMatchregionMatchServer = new MockUp<CseServer>() {

        @Mock
        public String toString() {
            return "regionMatchregionMatchServer";
        }

        @Mock
        public String getHost() {
            return "regionMatchregionMatchServer";
        }

        @Mock
        public MicroserviceInstance getInstance() {
            return regionMatchInstance;
        }
    }.getMockInstance();
    CseServer allmatchServer = new MockUp<CseServer>() {

        @Mock
        public String toString() {
            return "allmatchServer";
        }

        @Mock
        public String getHost() {
            return "allmatchServer";
        }

        @Mock
        public MicroserviceInstance getInstance() {
            return allmatchInstance;
        }
    }.getMockInstance();
    servers.add(noneMatchServer);
    List<Server> result = filter.getFilteredListOfServers(servers);
    Assert.assertEquals(result.size(), 1);
    Assert.assertEquals(result.get(0), noneMatchServer);
    servers.add(regionMatchregionMatchServer);
    result = filter.getFilteredListOfServers(servers);
    Assert.assertEquals(result.size(), 1);
    Assert.assertEquals(result.get(0), regionMatchregionMatchServer);
    servers.add(allmatchServer);
    result = filter.getFilteredListOfServers(servers);
    Assert.assertEquals(result.size(), 1);
    Assert.assertEquals(result.get(0), allmatchServer);
}
Also used : Expectations(mockit.Expectations) CseServer(org.apache.servicecomb.loadbalance.CseServer) Server(com.netflix.loadbalancer.Server) CseServer(org.apache.servicecomb.loadbalance.CseServer) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DataCenterInfo(org.apache.servicecomb.serviceregistry.api.registry.DataCenterInfo) Mock(mockit.Mock) Test(org.junit.Test)

Aggregations

Server (com.netflix.loadbalancer.Server)1 ArrayList (java.util.ArrayList)1 Expectations (mockit.Expectations)1 Mock (mockit.Mock)1 CseServer (org.apache.servicecomb.loadbalance.CseServer)1 DataCenterInfo (org.apache.servicecomb.serviceregistry.api.registry.DataCenterInfo)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 Test (org.junit.Test)1