Search in sources :

Example 1 with InvocationFinishEvent

use of org.apache.servicecomb.core.event.InvocationFinishEvent 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 2 with InvocationFinishEvent

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

the class Invocation method onFinish.

public void onFinish(Response response) {
    EventManager.post(new InvocationFinishEvent(this, response));
    // old logic, need to be deleted
    triggerFinishedEvent(response.getStatusCode());
}
Also used : InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent)

Example 3 with InvocationFinishEvent

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

the class TestPublishModelFactory method prepareRegistry.

protected Registry prepareRegistry() {
    CompositeRegistry globalRegistry = SpectatorUtils.createCompositeRegistry(null);
    Registry registry = new DefaultRegistry(new ManualClock());
    EventBus eventBus = new EventBus();
    DefaultMetricsInitializer metricsInitializer = new DefaultMetricsInitializer() {

        protected Registry createRegistry(MetricsBootstrapConfig config) {
            return registry;
        }
    };
    metricsInitializer.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    new MockUp<System>() {

        @Mock
        long nanoTime() {
            return 10;
        }
    };
    invocationType = InvocationType.CONSUMER;
    new MockUp<Invocation>() {

        @Mock
        InvocationType getInvocationType() {
            return invocationType;
        }

        @Mock
        boolean isConsumer() {
            return InvocationType.CONSUMER.equals(invocationType);
        }

        @Mock
        String getRealTransportName() {
            return Const.RESTFUL;
        }

        @Mock
        String getMicroserviceQualifiedName() {
            return "m.s.o";
        }

        @Mock
        long getStartExecutionTime() {
            return 5;
        }
    };
    new Expectations() {

        {
            response.getStatusCode();
            result = 200;
        }
    };
    InvocationFinishEvent finishEvent = new InvocationFinishEvent(invocation, response);
    eventBus.post(finishEvent);
    invocationType = InvocationType.PRODUCER;
    eventBus.post(finishEvent);
    return registry;
}
Also used : Expectations(mockit.Expectations) ManualClock(com.netflix.spectator.api.ManualClock) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) MockUp(mockit.MockUp) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) EventBus(com.google.common.eventbus.EventBus) DefaultMetricsInitializer(org.apache.servicecomb.metrics.core.DefaultMetricsInitializer)

Aggregations

InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)3 EventBus (com.google.common.eventbus.EventBus)1 CompositeRegistry (com.netflix.spectator.api.CompositeRegistry)1 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)1 ManualClock (com.netflix.spectator.api.ManualClock)1 Registry (com.netflix.spectator.api.Registry)1 Holder (javax.xml.ws.Holder)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 InvocationStartEvent (org.apache.servicecomb.core.event.InvocationStartEvent)1 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)1 MetricsBootstrapConfig (org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig)1 DefaultMetricsInitializer (org.apache.servicecomb.metrics.core.DefaultMetricsInitializer)1 RequestHeader (org.apache.servicecomb.transport.highway.message.RequestHeader)1 Test (org.junit.Test)1