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);
}
Aggregations