use of io.servicecomb.loadbalance.filter.TransactionControlFilter in project java-chassis by ServiceComb.
the class TestLoadBalancer method testGetAllServers.
@Test
public void testGetAllServers() {
List<Server> servers = new ArrayList<Server>();
Server server = Mockito.mock(Server.class);
servers.add(server);
Mockito.when(serverList.getInitialListOfServers()).thenReturn(servers);
TransactionControlFilter filter = Mockito.mock(TransactionControlFilter.class);
Mockito.when(filter.getFilteredListOfServers(servers)).thenReturn(servers);
Assert.assertEquals(servers, loadBalancer.getAllServers());
}
use of io.servicecomb.loadbalance.filter.TransactionControlFilter in project java-chassis by ServiceComb.
the class LoadbalanceHandler method setTransactionControlFilter.
protected void setTransactionControlFilter(LoadBalancer lb, Invocation invocation) {
final String filterName = TransactionControlFilter.class.getName();
String policyClsName = Configuration.INSTANCE.getFlowsplitFilterPolicy(invocation.getMicroserviceName());
if (policyClsName.isEmpty()) {
lb.removeFilter(filterName);
return;
}
if (lb.containsFilter(filterName)) {
return;
}
try {
Class<?> policyCls = Class.forName(policyClsName);
if (!TransactionControlFilter.class.isAssignableFrom(policyCls)) {
String errMsg = String.format("Define instance filter %s in yaml, but not extends abstract class TransactionControlFilter.", policyClsName);
LOGGER.error(errMsg);
throw new Error(errMsg);
}
TransactionControlFilter transactionControlFilter = (TransactionControlFilter) policyCls.newInstance();
transactionControlFilter.setInvocation(invocation);
transactionControlFilter.setLoadBalancerStats(lb.getLoadBalancerStats());
lb.putFilter(filterName, transactionControlFilter);
} catch (Throwable e) {
String errMsg = "Fail to create instance of class: " + policyClsName;
LOGGER.error(errMsg);
throw new Error(errMsg, e);
}
}
use of io.servicecomb.loadbalance.filter.TransactionControlFilter in project java-chassis by ServiceComb.
the class TestLoadBalancer method testFilter.
@Test
public void testFilter() {
Assert.assertEquals(0, loadBalancer.getFilterSize());
TransactionControlFilter filter = new SimpleTransactionControlFilter();
loadBalancer.putFilter("test", filter);
Assert.assertEquals(1, loadBalancer.getFilterSize());
Assert.assertTrue(loadBalancer.containsFilter("test"));
loadBalancer.removeFilter("test");
Assert.assertEquals(0, loadBalancer.getFilterSize());
Assert.assertFalse(loadBalancer.containsFilter("test"));
}
Aggregations