Search in sources :

Example 6 with ReactiveExecutor

use of org.apache.servicecomb.core.executor.ReactiveExecutor 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

ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)6 Holder (javax.xml.ws.Holder)5 Test (org.junit.Test)5 Executor (java.util.concurrent.Executor)4 MockUp (mockit.MockUp)3 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)3 Expectations (mockit.Expectations)2 Invocation (org.apache.servicecomb.core.Invocation)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 InvocationStartEvent (org.apache.servicecomb.core.event.InvocationStartEvent)2 AbstractHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest)2 Response (org.apache.servicecomb.swagger.invocation.Response)2 BeforeClass (org.junit.BeforeClass)2 ProtobufFeature (io.protostuff.runtime.ProtobufFeature)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Vertx (io.vertx.core.Vertx)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Mock (mockit.Mock)1 OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)1