use of org.apache.servicecomb.loadbalance.filter.TransactionControlFilter in project incubator-servicecomb-java-chassis by apache.
the class TestLoadBalancer method testGetAllServers.
@Test
public void testGetAllServers() {
List<Server> servers = new ArrayList<>();
Server server = Mockito.mock(Server.class);
servers.add(server);
loadBalancer.setServerList(servers);
TransactionControlFilter filter = Mockito.mock(TransactionControlFilter.class);
Mockito.when(filter.getFilteredListOfServers(servers)).thenReturn(servers);
Assert.assertEquals(servers, loadBalancer.getAllServers());
}
use of org.apache.servicecomb.loadbalance.filter.TransactionControlFilter in project incubator-servicecomb-java-chassis by apache.
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());
}
use of org.apache.servicecomb.loadbalance.filter.TransactionControlFilter in project incubator-servicecomb-java-chassis by apache.
the class LoadbalanceHandler method setTransactionControlFilter.
protected void setTransactionControlFilter(LoadBalancer lb, String microserviceName) {
final String filterName = TransactionControlFilter.class.getName();
String policyClsName = Configuration.INSTANCE.getFlowsplitFilterPolicy(microserviceName);
if (policyClsName.isEmpty()) {
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.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);
}
}
Aggregations