use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.
the class IsolationDiscoveryFilterTest method discovery_isolate_error_instance.
@Test
public void discovery_isolate_error_instance() {
ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
for (int i = 0; i < 4; ++i) {
ServiceCombLoadBalancerStats.INSTANCE.markFailure(server0);
}
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
// by default 5 times continuous failure will cause isolation
ServiceCombLoadBalancerStats.INSTANCE.markFailure(server0);
Assert.assertFalse(ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0).isIsolated());
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
Assert.assertTrue(ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0).isIsolated());
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.
the class IsolationDiscoveryFilterTest method discovery_keep_minIsolationTime.
@Test
public void discovery_keep_minIsolationTime() {
ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
ServiceCombLoadBalancerStats.INSTANCE.markIsolated(server0, true);
ServiceCombLoadBalancerStats.INSTANCE.markSuccess(server0);
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
ServiceCombServerStats serviceCombServerStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0);
Deencapsulation.setField(serviceCombServerStats, "isolatedTime", System.currentTimeMillis() - Configuration.INSTANCE.getMinIsolationTime(invocation.getMicroserviceName()) - 1);
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.
the class IsolationDiscoveryFilterTest method discovery_not_try_isolated_instance_concurrently.
@Test
public void discovery_not_try_isolated_instance_concurrently() {
ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
ServiceCombServerStats serviceCombServerStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0);
for (int i = 0; i < 5; ++i) {
serviceCombServerStats.markFailure();
}
ServiceCombLoadBalancerStats.INSTANCE.markIsolated(server0, true);
letIsolatedInstancePassSingleTestTime(serviceCombServerStats);
Assert.assertTrue(ServiceCombServerStats.isolatedServerCanTry());
// The first invocation can occupy the trying chance
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
Assert.assertFalse(ServiceCombServerStats.isolatedServerCanTry());
// Other invocation cannot get trying chance concurrently
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
ServiceCombServerStats.checkAndReleaseTryingChance(// after the first invocation releases the trying chance
invocation);
// Other invocation can get the trying chance
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
Assert.assertFalse(ServiceCombServerStats.isolatedServerCanTry());
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.
the class TestServerDiscoveryFilter method createEndpointNormal.
@Test
public void createEndpointNormal(@Injectable DiscoveryContext context, @Injectable Invocation invocation) {
new Expectations(transportManager) {
{
transportManager.findTransport(anyString);
result = trasport;
context.getInputParameters();
result = invocation;
invocation.getMicroserviceName();
result = "test";
}
};
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("0000001");
ServiceCombServer server = (ServiceCombServer) filter.createEndpoint(context, Const.RESTFUL, "rest://localhost:8080", instance);
Assert.assertSame(instance, server.getInstance());
Assert.assertSame(trasport, server.getEndpoint().getTransport());
Assert.assertEquals("rest://localhost:8080", server.getEndpoint().getEndpoint());
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.
the class TestServerDiscoveryFilter method createEndpoint_TransportNotExist.
@Test
public void createEndpoint_TransportNotExist() {
new Expectations(transportManager) {
{
transportManager.findTransport(anyString);
result = null;
}
};
ServiceCombServer server = (ServiceCombServer) filter.createEndpoint(null, Const.RESTFUL, null, null);
Assert.assertNull(server);
}
Aggregations