Search in sources :

Example 6 with Invocation

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());
}
Also used : Invocation(io.servicecomb.core.Invocation) Server(com.netflix.loadbalancer.Server) CseServer(io.servicecomb.loadbalance.CseServer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with Invocation

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);
}
Also used : Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta)

Example 8 with 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);
}
Also used : Invocation(io.servicecomb.core.Invocation) AsyncResponse(io.servicecomb.core.AsyncResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 9 with Invocation

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);
}
Also used : Invocation(io.servicecomb.core.Invocation) SyncResponseExecutor(io.servicecomb.core.provider.consumer.SyncResponseExecutor) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) ExecutionListener(com.netflix.loadbalancer.reactive.ExecutionListener) AsyncResponse(io.servicecomb.core.AsyncResponse) Response(io.servicecomb.core.Response) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 10 with Invocation

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());
}
Also used : Invocation(io.servicecomb.core.Invocation) Test(org.junit.Test)

Aggregations

Invocation (io.servicecomb.core.Invocation)70 Test (org.junit.Test)55 OperationMeta (io.servicecomb.core.definition.OperationMeta)29 Response (io.servicecomb.core.Response)20 AsyncResponse (io.servicecomb.core.AsyncResponse)19 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)10 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)9 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)9 MockUp (mockit.MockUp)9 InvocationException (io.servicecomb.core.exception.InvocationException)8 Endpoint (io.servicecomb.core.Endpoint)7 IpPort (io.servicecomb.foundation.common.net.IpPort)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 HttpClientResponse (io.vertx.core.http.HttpClientResponse)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 Buffer (io.vertx.core.buffer.Buffer)5 HttpClient (io.vertx.core.http.HttpClient)4 ArrayList (java.util.ArrayList)4 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)3