use of org.apache.servicecomb.registry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_success.
@Test
public void send_success(@Injectable LoadBalancer loadBalancer) {
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", instance1);
ServiceCombServer server = new ServiceCombServer(null, restTransport, cacheEndpoint);
LoadBalancerStats stats = new LoadBalancerStats("test");
new Expectations(loadBalancer) {
{
loadBalancer.chooseServer(invocation);
result = server;
loadBalancer.getLoadBalancerStats();
result = stats;
}
};
sendResponse = Response.ok("success");
Holder<String> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = resp.getResult();
}, loadBalancer);
Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getActiveRequestsCount());
Assert.assertEquals("success", result.value);
}
use of org.apache.servicecomb.registry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestServiceCombServer method testEqualsMethod.
@Test
public void testEqualsMethod() {
Assert.assertFalse(cs.equals((Object) "abcd"));
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
ServiceCombServer other = new ServiceCombServer(null, transport, new CacheEndpoint("1234", instance1));
Assert.assertFalse(cs.equals(other));
MicroserviceInstance instance2 = new MicroserviceInstance();
instance2.setInstanceId("123456");
other = new ServiceCombServer(null, transport, new CacheEndpoint("abcd", instance2));
Assert.assertTrue(cs.equals(other));
}
use of org.apache.servicecomb.registry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class IsolationDiscoveryFilterTest method before.
@Before
public void before() {
discoveryContext = new DiscoveryContext();
discoveryContext.setInputParameters(invocation);
discoveryTreeNode = new DiscoveryTreeNode();
Mockito.doAnswer(a -> a.getArguments()[0]).when(transport).parseAddress(Mockito.anyString());
data = new HashMap<>();
for (int i = 0; i < 3; ++i) {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("i" + i);
String endpoint = "rest://127.0.0.1:" + i;
instance.setEndpoints(Collections.singletonList(endpoint));
data.put(instance.getInstanceId(), instance);
ServiceCombServer serviceCombServer = new ServiceCombServer(invocation.getMicroserviceName(), transport, new CacheEndpoint(endpoint, instance));
ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(serviceCombServer);
}
discoveryTreeNode.data(data);
filter = new IsolationDiscoveryFilter();
TestServiceCombServerStats.releaseTryingChance();
}
use of org.apache.servicecomb.registry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class TestServiceCombServer method setUp.
@Before
public void setUp() {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("123456");
cs = new ServiceCombServer(null, transport, new CacheEndpoint("abcd", instance));
}
use of org.apache.servicecomb.registry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class TestSessionSticknessRule method testRuleFullOperation.
@Test
public void testRuleFullOperation() {
SessionStickinessRule rule = new SessionStickinessRule();
LoadBalancer mockedLb = mock(LoadBalancer.class);
Transport transport = mock(Transport.class);
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
ServiceCombServer mockedServer = new ServiceCombServer(null, transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1));
Invocation invocation = mock(Invocation.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<ServiceCombServer> allServers = Arrays.asList(mockedServer);
rule.setLoadBalancer(mockedLb);
Server s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
}
Aggregations