Search in sources :

Example 1 with InvocationStartEvent

use of org.apache.servicecomb.core.event.InvocationStartEvent in project incubator-servicecomb-java-chassis by apache.

the class Invocation method onStart.

public void onStart() {
    this.startTime = System.nanoTime();
    EventManager.post(new InvocationStartEvent(this));
    // old logic, need to be deleted
    EventBus.getInstance().triggerEvent(new InvocationStartedEvent(getMicroserviceQualifiedName(), invocationType, startTime));
}
Also used : InvocationStartEvent(org.apache.servicecomb.core.event.InvocationStartEvent) InvocationStartedEvent(org.apache.servicecomb.core.metrics.InvocationStartedEvent)

Example 2 with InvocationStartEvent

use of org.apache.servicecomb.core.event.InvocationStartEvent in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayServerInvoke method test.

@Test
public void test() {
    Holder<InvocationStartEvent> startHolder = new Holder<>();
    Holder<InvocationFinishEvent> finishHolder = new Holder<>();
    Object subscriber = new Object() {

        @Subscribe
        public void onStart(InvocationStartEvent event) {
            startHolder.value = event;
        }

        @Subscribe
        public void onFinish(InvocationFinishEvent event) {
            finishHolder.value = event;
        }
    };
    EventManager.register(subscriber);
    MockUtil.getInstance().mockHighwayCodec();
    SchemaMeta schemaMeta = unitTestMeta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
    operationMeta.setExecutor(new ReactiveExecutor());
    HighwayServerInvoke highwayServerInvoke = new HighwayServerInvoke();
    highwayServerInvoke.setMicroserviceMetaManager(unitTestMeta.getMicroserviceMetaManager());
    RequestHeader requestHeader = MockUtil.getInstance().requestHeader;
    // 初始化失败
    requestHeader.setDestMicroservice(null);
    Assert.assertFalse(highwayServerInvoke.init(connection, 0, null, null));
    // 初始化成功
    requestHeader.setDestMicroservice(schemaMeta.getMicroserviceName());
    requestHeader.setSchemaId(schemaMeta.getSchemaId());
    requestHeader.setOperationName(operationMeta.getOperationId());
    Assert.assertTrue(highwayServerInvoke.init(connection, 0, requestHeader, null));
    // exe失败
    MockUtil.getInstance().decodeRequestSucc = false;
    highwayServerInvoke.execute();
    EventManager.unregister(subscriber);
    Assert.assertEquals(true, Buffer.buffer(netSocketBuffer).toString().startsWith("CSE.TCP"));
    Assert.assertSame(highwayServerInvoke.invocation, startHolder.value.getInvocation());
    Assert.assertSame(highwayServerInvoke.invocation, finishHolder.value.getInvocation());
    Assert.assertTrue(highwayServerInvoke.invocation.getStartExecutionTime() != 0);
}
Also used : InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Holder(javax.xml.ws.Holder) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) InvocationStartEvent(org.apache.servicecomb.core.event.InvocationStartEvent) Test(org.junit.Test)

Example 3 with InvocationStartEvent

use of org.apache.servicecomb.core.event.InvocationStartEvent in project incubator-servicecomb-java-chassis by apache.

the class TestAbstractRestInvocation method scheduleInvocationNormal.

@Test
public void scheduleInvocationNormal(@Mocked OperationMeta operationMeta) {
    long time = 123;
    new MockUp<System>() {

        @Mock
        long nanoTime() {
            return time;
        }
    };
    Holder<InvocationStartEvent> eventHolder = new Holder<>();
    Object subscriber = new Object() {

        @Subscribe
        public void onStart(InvocationStartEvent event) {
            eventHolder.value = event;
        }
    };
    EventManager.register(subscriber);
    Executor executor = new ReactiveExecutor();
    requestEx = new AbstractHttpServletRequest() {
    };
    requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
    new Expectations() {

        {
            restOperation.getOperationMeta();
            result = operationMeta;
            operationMeta.getExecutor();
            result = executor;
        }
    };
    Holder<Boolean> result = new Holder<>();
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected void runOnExecutor() {
            result.value = true;
        }
    };
    restInvocation.requestEx = requestEx;
    restInvocation.restOperationMeta = restOperation;
    restInvocation.scheduleInvocation();
    EventManager.unregister(subscriber);
    Assert.assertTrue(result.value);
    Assert.assertEquals(time, invocation.getStartTime());
    Assert.assertSame(invocation, eventHolder.value.getInvocation());
}
Also used : Expectations(mockit.Expectations) Holder(javax.xml.ws.Holder) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) MockUp(mockit.MockUp) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) Executor(java.util.concurrent.Executor) AbstractHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest) InvocationStartEvent(org.apache.servicecomb.core.event.InvocationStartEvent) Test(org.junit.Test)

Aggregations

InvocationStartEvent (org.apache.servicecomb.core.event.InvocationStartEvent)3 Holder (javax.xml.ws.Holder)2 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)2 Test (org.junit.Test)2 Executor (java.util.concurrent.Executor)1 Expectations (mockit.Expectations)1 MockUp (mockit.MockUp)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)1 InvocationStartedEvent (org.apache.servicecomb.core.metrics.InvocationStartedEvent)1 AbstractHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest)1 RequestHeader (org.apache.servicecomb.transport.highway.message.RequestHeader)1