use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestSimpleTransactionControlFilter method testGetFilteredListOfServers.
@Test
public void testGetFilteredListOfServers() {
Invocation invocation = Mockito.mock(Invocation.class);
filter.setInvocation(invocation);
List<Server> servers = new ArrayList<>();
servers.add(server);
List<Server> filteredServers = filter.getFilteredListOfServers(servers);
Assert.assertEquals(1, filteredServers.size());
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class Invoker method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Invocation invocation = InvocationFactory.forConsumer(config, schemaMeta, method.getName(), null);
ConsumerOperationMeta consumerOperation = consumerOperationMap.get(method.getName());
consumerOperation.getArgsMapper().toInvocation(args, invocation);
Response response = InvokerUtils.innerSyncInvoke(invocation);
if (response.isSuccessed()) {
return consumerOperation.getResponseMapper().mapResponse(response);
}
throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
// return InvokerUtils.invoke(invocation);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestLoadbalanceHandler method testLoadbalanceHandlerHandleWithSendWithRetry.
@Test
public void testLoadbalanceHandlerHandleWithSendWithRetry() throws Exception {
boolean status = true;
LoadbalanceHandler lh = new LoadbalanceHandler();
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
Mockito.when(invocation.getConfigTransportName()).thenReturn("baadshah");
Map<String, LoadBalancer> loadBalancerMap = new ConcurrentHashMap<String, LoadBalancer>();
loadBalancerMap.put("baadshah", lb);
try {
Deencapsulation.setField(lh, "loadBalancerMap", loadBalancerMap);
Deencapsulation.invoke(lh, "sendWithRetry", invocation, asyncResp, lb);
lh.handle(invocation, asyncResp);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestLoadbalanceHandler method testLoadbalanceHandlerHandleWithLoadBalancerHandler.
@Test
public void testLoadbalanceHandlerHandleWithLoadBalancerHandler() throws Exception {
boolean status = true;
new MockUp<LoadbalanceHandler>() {
@Mock
private LoadBalancer createLoadBalancer(String appId, String microserviceName, String microserviceVersionRule, String transportName) {
return lb;
}
};
LoadbalanceHandler lh = new LoadbalanceHandler();
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getConfigTransportName()).thenReturn("baadshah");
Mockito.when(invocation.getMicroserviceVersionRule()).thenReturn("VERSION_RULE_LATEST");
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
new MockUp<Configuration>() {
@Mock
public boolean isRetryEnabled(String microservice) {
return true;
}
};
SyncResponseExecutor orginExecutor = new SyncResponseExecutor();
Mockito.when(invocation.getResponseExecutor()).thenReturn(orginExecutor);
List<ExecutionListener<Invocation, Response>> listeners = new ArrayList<>(0);
@SuppressWarnings("unchecked") ExecutionListener<Invocation, Response> listener = Mockito.mock(ExecutionListener.class);
ExecutionListener<Invocation, Response> e = null;
listeners.add(e);
listeners.add(listener);
try {
lh.handle(invocation, asyncResp);
} catch (Exception ex) {
status = false;
}
Assert.assertTrue(status);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestLoadbalanceHandler method testSetTransactionControlFilter.
@Test
public void testSetTransactionControlFilter() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
LoadbalanceHandler lbHandler = new LoadbalanceHandler();
LoadBalancer myLB = new LoadBalancer(serverList, rule);
lbHandler.setTransactionControlFilter(myLB, invocation);
Assert.assertEquals(1, myLB.getFilterSize());
Assert.assertTrue(myLB.containsFilter(TransactionControlFilter.class.getName()));
lbHandler.setTransactionControlFilter(myLB, invocation);
Assert.assertEquals(1, myLB.getFilterSize());
}
Aggregations