use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestIpPortManager method testGetAvailableAddress.
@Test
public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config, @Injectable InstanceCacheManager cacheManager, @Injectable InstanceCache cache) {
ArrayList<IpPort> ipPortList = new ArrayList<>();
ipPortList.add(new IpPort("127.0.0.1", 9980));
ipPortList.add(new IpPort("127.0.0.1", 9981));
new Expectations() {
{
config.getIpPort();
result = ipPortList;
config.getTransport();
result = "rest";
config.isRegistryAutoDiscovery();
result = true;
}
};
IpPortManager manager = new IpPortManager(config, cacheManager);
IpPort address1 = manager.getAvailableAddress();
if (address1.getPort() == 9980) {
Assert.assertEquals("127.0.0.1", address1.getHostOrIp());
Assert.assertEquals(9980, address1.getPort());
} else {
Assert.assertEquals("127.0.0.1", address1.getHostOrIp());
Assert.assertEquals(9981, address1.getPort());
}
IpPort address2 = manager.getNextAvailableAddress(address1);
if (address1.getPort() == 9980) {
Assert.assertEquals("127.0.0.1", address2.getHostOrIp());
Assert.assertEquals(9981, address2.getPort());
} else {
Assert.assertEquals("127.0.0.1", address2.getHostOrIp());
Assert.assertEquals(9980, address2.getPort());
}
IpPort address3 = manager.getAvailableAddress();
if (address1.getPort() == 9980) {
Assert.assertEquals("127.0.0.1", address3.getHostOrIp());
Assert.assertEquals(9981, address3.getPort());
} else {
Assert.assertEquals("127.0.0.1", address3.getHostOrIp());
Assert.assertEquals(9980, address3.getPort());
}
Map<String, List<CacheEndpoint>> addresses = new HashMap<>();
List<CacheEndpoint> instances = new ArrayList<>();
instances.add(new CacheEndpoint("http://127.0.0.1:9982", null));
addresses.put("rest", instances);
new Expectations() {
{
cacheManager.getOrCreate("default", "SERVICECENTER", "latest");
result = cache;
cache.getOrCreateTransportMap();
result = addresses;
}
};
manager.initAutoDiscovery();
IpPort address4 = manager.getNextAvailableAddress(address3);
if (address1.getPort() == 9980) {
Assert.assertEquals("127.0.0.1", address4.getHostOrIp());
Assert.assertEquals(9982, address4.getPort());
} else {
address4 = manager.getNextAvailableAddress(address1);
Assert.assertEquals("127.0.0.1", address4.getHostOrIp());
Assert.assertEquals(9982, address4.getPort());
}
IpPort address5 = manager.getNextAvailableAddress(address4);
Assert.assertEquals("127.0.0.1", address5.getHostOrIp());
Assert.assertEquals(9980, address5.getPort());
}
use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestCseServer method testEqualsMethod.
@Test
public void testEqualsMethod() {
Assert.assertFalse(cs.equals((Object) "abcd"));
CseServer other = new CseServer(transport, new CacheEndpoint("1234", null));
Assert.assertFalse(cs.equals(other));
other = new CseServer(transport, new CacheEndpoint("abcd", null));
Assert.assertTrue(cs.equals(other));
}
use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestSessionSticknessRule method testRuleFullOperation.
@Test
public void testRuleFullOperation() {
SessionStickinessRule rule = new SessionStickinessRule();
LoadBalancer mockedLb = mock(LoadBalancer.class);
Transport transport = mock(Transport.class);
CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8889", null));
Object key = Mockito.mock(Object.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<Server> allServers = Arrays.asList(mockedServer);
when(mockedLb.getReachableServers()).thenReturn(allServers);
when(mockedLb.getAllServers()).thenReturn(allServers);
rule.setLoadBalancer(mockedLb);
Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
Server s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
}
Aggregations