Search in sources :

Example 86 with Invocation

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

the class TestInvocationStageTrace method producer.

@Test
public void producer() {
    invocation = new Invocation(endpoint, operationMeta, args);
    stageTrace = new InvocationStageTrace(invocation);
    stageTrace.start(1);
    nanoTime = 2;
    stageTrace.startSchedule();
    nanoTime = 3;
    stageTrace.startExecution();
    nanoTime = 4;
    stageTrace.startServerFiltersRequest();
    nanoTime = 5;
    stageTrace.startHandlersRequest();
    nanoTime = 6;
    stageTrace.startBusinessMethod();
    nanoTime = 7;
    stageTrace.finishBusiness();
    nanoTime = 8;
    stageTrace.finishHandlersResponse();
    nanoTime = 9;
    stageTrace.finishServerFiltersResponse();
    nanoTime = 10;
    stageTrace.finish();
    Assert.assertEquals(1, stageTrace.getStart());
    Assert.assertEquals(2, stageTrace.getStartSchedule());
    Assert.assertEquals(3, stageTrace.getStartExecution());
    Assert.assertEquals(4, stageTrace.getStartServerFiltersRequest());
    Assert.assertEquals(5, stageTrace.getStartHandlersRequest());
    Assert.assertEquals(6, stageTrace.getStartBusinessMethod());
    Assert.assertEquals(7, stageTrace.getFinishBusiness());
    Assert.assertEquals(8, stageTrace.getFinishHandlersResponse());
    Assert.assertEquals(9, stageTrace.getFinishServerFiltersResponse());
    Assert.assertEquals(10, stageTrace.getFinish());
    Assert.assertEquals(1f, stageTrace.calcInvocationPrepareTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcThreadPoolQueueTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcServerFiltersRequestTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcHandlersRequestTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcBusinessTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcHandlersResponseTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcServerFiltersResponseTime(), 0.1f);
    Assert.assertEquals(1f, stageTrace.calcSendResponseTime(), 0.1f);
    Assert.assertEquals(9f, stageTrace.calcTotalTime(), 0.1f);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Test(org.junit.Test)

Example 87 with Invocation

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

the class ProcessingTimeStrategyTest method should_do_nothing_when_not_first_node_of_a_process.

@Test
void should_do_nothing_when_not_first_node_of_a_process() {
    Invocation invocation = new Invocation();
    invocation.setLocalContext(ImmutableMap.of(CHAIN_START_TIME, 10L, CHAIN_PROCESSING, 0L));
    Throwable throwable = catchThrowable(() -> strategy.start(invocation));
    assertThat(throwable).isNull();
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test)

Example 88 with Invocation

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

the class ProcessingTimeStrategyTest method should_init_when_start_as_first_chain_node.

@Test
void should_init_when_start_as_first_chain_node() {
    Invocation invocation = new Invocation();
    invocation.getInvocationStageTrace().start(10);
    strategy.start(invocation);
    assertThat(invocation.<Long>getLocalContext(CHAIN_START_TIME)).isEqualTo(10L);
    assertThat(invocation.<Long>getLocalContext(CHAIN_PROCESSING)).isEqualTo(0L);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Test(org.junit.jupiter.api.Test)

Example 89 with Invocation

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

the class PassingTimeStrategyTest method should_init_when_start_as_first_chain_node.

@Test
void should_init_when_start_as_first_chain_node() {
    Invocation invocation = new Invocation();
    invocation.getInvocationStageTrace().setStartTimeMillis(10);
    strategy.start(invocation);
    assertThat(invocation.getContext(CHAIN_START_TIME)).isEqualTo("10");
    assertThat(invocation.<Long>getLocalContext(CHAIN_START_TIME)).isEqualTo(10L);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Test(org.junit.jupiter.api.Test)

Example 90 with Invocation

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

the class PassingTimeStrategyTest method should_init_when_start_as_first_node_of_a_process_but_not_first_of_a_chain.

@Test
void should_init_when_start_as_first_node_of_a_process_but_not_first_of_a_chain() {
    Invocation invocation = new Invocation();
    invocation.setContext(ImmutableMap.of(CHAIN_START_TIME, "10"));
    strategy.start(invocation);
    assertThat(invocation.getContext(CHAIN_START_TIME)).isEqualTo("10");
    assertThat(invocation.<Long>getLocalContext(CHAIN_START_TIME)).isEqualTo(10L);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Test(org.junit.jupiter.api.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