Search in sources :

Example 1 with ReactiveExecutor

use of io.servicecomb.core.executor.ReactiveExecutor in project java-chassis by ServiceComb.

the class TestExecutors method testFixedThreadExecutor.

@Test
public void testFixedThreadExecutor() {
    FixedThreadExecutor oFixedThreadExecutor = new FixedThreadExecutor();
    oFixedThreadExecutor.execute(new Runnable() {

        @Override
        public void run() {
        }
    });
    Map<Long, Executor> threadExectorMap = Deencapsulation.getField(oFixedThreadExecutor, "threadExectorMap");
    Assert.assertEquals(true, (threadExectorMap.size() > 0));
    List<Executor> executorList = Deencapsulation.getField(oFixedThreadExecutor, "executorList");
    Assert.assertEquals(true, (executorList.size() > 1));
    ReactiveExecutor oReactiveExecutor = new ReactiveExecutor();
    oReactiveExecutor.execute(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            strThreadTest = "thread Ran";
        }
    });
    Assert.assertEquals("thread Ran", strThreadTest);
}
Also used : Executor(java.util.concurrent.Executor) FixedThreadExecutor(io.servicecomb.core.executor.FixedThreadExecutor) ReactiveExecutor(io.servicecomb.core.executor.ReactiveExecutor) FixedThreadExecutor(io.servicecomb.core.executor.FixedThreadExecutor) ReactiveExecutor(io.servicecomb.core.executor.ReactiveExecutor) Test(org.junit.Test)

Example 2 with ReactiveExecutor

use of io.servicecomb.core.executor.ReactiveExecutor in project java-chassis by ServiceComb.

the class TestHighwayServerInvoke method test.

@Test
public void test() {
    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(netSocket, 0, null, null));
    // 初始化成功
    requestHeader.setDestMicroservice(schemaMeta.getMicroserviceName());
    requestHeader.setSchemaId(schemaMeta.getSchemaId());
    requestHeader.setOperationName(operationMeta.getOperationId());
    Assert.assertTrue(highwayServerInvoke.init(netSocket, 0, requestHeader, null));
    // exe成功
    netSocketBuffer = null;
    highwayServerInvoke.execute();
    Assert.assertEquals(null, netSocketBuffer);
    // exe失败
    MockUtil.getInstance().decodeRequestSucc = false;
    highwayServerInvoke.execute();
    Assert.assertEquals(true, netSocketBuffer.toString().startsWith("CSE.TCP"));
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) ReactiveExecutor(io.servicecomb.core.executor.ReactiveExecutor) RequestHeader(io.servicecomb.transport.highway.message.RequestHeader) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Aggregations

ReactiveExecutor (io.servicecomb.core.executor.ReactiveExecutor)2 Test (org.junit.Test)2 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)1 FixedThreadExecutor (io.servicecomb.core.executor.FixedThreadExecutor)1 RequestHeader (io.servicecomb.transport.highway.message.RequestHeader)1 Executor (java.util.concurrent.Executor)1