Search in sources :

Example 56 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class TestSessionSticknessRule method testRuleFullOperation.

@Test
public void testRuleFullOperation() {
    SessionStickinessRule rule = new SessionStickinessRule();
    LoadBalancer mockedLb = mock(LoadBalancer.class);
    Transport transport = mock(Transport.class);
    MicroserviceInstance instance1 = new MicroserviceInstance();
    instance1.setInstanceId("1234");
    ServiceCombServer mockedServer = new ServiceCombServer(null, transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1));
    Invocation invocation = mock(Invocation.class);
    LoadBalancerStats stats = mock(LoadBalancerStats.class);
    Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
    Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation);
    mockedServer.setAlive(true);
    mockedServer.setReadyToServe(true);
    List<ServiceCombServer> allServers = Arrays.asList(mockedServer);
    rule.setLoadBalancer(mockedLb);
    Server s = rule.choose(allServers, invocation);
    Assert.assertEquals(s, mockedServer);
    s = rule.choose(allServers, invocation);
    Assert.assertEquals(s, mockedServer);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Server(com.netflix.loadbalancer.Server) CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Transport(org.apache.servicecomb.core.Transport) Test(org.junit.Test)

Example 57 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class TestSessionSticknessRule method testServerWithoutTimeoutAndWithThreshold.

@Test
public void testServerWithoutTimeoutAndWithThreshold() {
    boolean status = true;
    SessionStickinessRule ss = new SessionStickinessRule();
    Invocation invocation = mock(Invocation.class);
    ServiceCombServer server = mock(ServiceCombServer.class);
    List<ServiceCombServer> servers = new ArrayList<>();
    servers.add(server);
    Deencapsulation.setField(ss, "lastServer", server);
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isTimeOut() {
            return false;
        }
    };
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isErrorThresholdMet() {
            return true;
        }
    };
    try {
        ss.choose(servers, invocation);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 58 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class ZipkinProviderDelegateTest method testGetterOnGetOtherContent.

@Test
public void testGetterOnGetOtherContent() {
    Getter<Invocation, String> getter = Deencapsulation.getField(ZipkinProviderDelegate.class, "INVOCATION_STRING_GETTER");
    Invocation invocation = Mockito.mock(Invocation.class);
    Map<String, String> context = new HashMap<>();
    Mockito.when(invocation.getContext()).thenReturn(context);
    final String key = "key";
    String value = getter.get(invocation, key);
    Assert.assertNull(value);
    final String expectedValue = "value";
    context.put(key, expectedValue);
    value = getter.get(invocation, key);
    Assert.assertEquals(expectedValue, value);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 59 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class SlowInvocationLogger method onInvocationFinish.

@Subscribe
@AllowConcurrentEvents
public void onInvocationFinish(InvocationFinishEvent event) {
    Invocation invocation = event.getInvocation();
    OperationConfig operationConfig = invocation.getOperationMeta().getConfig();
    if (!operationConfig.isSlowInvocationEnabled() || invocation.getInvocationStageTrace().calcTotalTime() < operationConfig.getNanoSlowInvocation()) {
        return;
    }
    if (!invocation.isConsumer()) {
        logSlowProducer(invocation, event.getResponse(), operationConfig);
        return;
    }
    if (invocation.isEdge()) {
        logSlowEdge(invocation, event.getResponse(), operationConfig);
        return;
    }
    logSlowConsumer(invocation, event.getResponse(), operationConfig);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) OperationConfig(org.apache.servicecomb.core.definition.OperationConfig) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 60 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Invocation (org.apache.servicecomb.core.Invocation)204 Test (org.junit.Test)125 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)52 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)37 Response (org.apache.servicecomb.swagger.invocation.Response)37 Before (org.junit.Before)29 MockUp (mockit.MockUp)26 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)23 Expectations (mockit.Expectations)20 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)20 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)19 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)18 Transport (org.apache.servicecomb.core.Transport)18 RoutingContext (io.vertx.ext.web.RoutingContext)17 Map (java.util.Map)17 ServerAccessLogEvent (org.apache.servicecomb.core.event.ServerAccessLogEvent)17 List (java.util.List)16 Endpoint (org.apache.servicecomb.core.Endpoint)16 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)15