Search in sources :

Example 1 with TransactionControlFilter

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());
}
Also used : Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) SimpleTransactionControlFilter(org.apache.servicecomb.loadbalance.filter.SimpleTransactionControlFilter) TransactionControlFilter(org.apache.servicecomb.loadbalance.filter.TransactionControlFilter) Test(org.junit.Test)

Example 2 with TransactionControlFilter

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());
}
Also used : SimpleTransactionControlFilter(org.apache.servicecomb.loadbalance.filter.SimpleTransactionControlFilter) TransactionControlFilter(org.apache.servicecomb.loadbalance.filter.TransactionControlFilter) SimpleTransactionControlFilter(org.apache.servicecomb.loadbalance.filter.SimpleTransactionControlFilter) Test(org.junit.Test)

Example 3 with TransactionControlFilter

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);
    }
}
Also used : TransactionControlFilter(org.apache.servicecomb.loadbalance.filter.TransactionControlFilter)

Aggregations

TransactionControlFilter (org.apache.servicecomb.loadbalance.filter.TransactionControlFilter)3 SimpleTransactionControlFilter (org.apache.servicecomb.loadbalance.filter.SimpleTransactionControlFilter)2 Test (org.junit.Test)2 Server (com.netflix.loadbalancer.Server)1 ArrayList (java.util.ArrayList)1