use of org.apache.servicecomb.core.executor.ReactiveExecutor in project incubator-servicecomb-java-chassis by apache.
the class TestExecutors method testFixedThreadExecutor.
@Test
public void testFixedThreadExecutor() {
FixedThreadExecutor oFixedThreadExecutor = new FixedThreadExecutor();
oFixedThreadExecutor.execute(new Runnable() {
@Override
public void run() {
}
});
Map<Long, Executor> threadExecutorMap = Deencapsulation.getField(oFixedThreadExecutor, "threadExecutorMap");
Assert.assertEquals(true, (threadExecutorMap.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() {
strThreadTest = "thread Ran";
}
});
Assert.assertEquals("thread Ran", strThreadTest);
}
use of org.apache.servicecomb.core.executor.ReactiveExecutor in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocationException.
@Test
public void scheduleInvocationException(@Mocked OperationMeta operationMeta) {
Executor executor = new ReactiveExecutor();
requestEx = new AbstractHttpServletRequest() {
};
requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
}
};
Holder<Throwable> result = new Holder<>();
Error error = new Error("run on executor");
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
throw error;
}
@Override
public void sendFailResponse(Throwable throwable) {
result.value = throwable;
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
restInvocation.scheduleInvocation();
Assert.assertSame(error, result.value);
}
use of org.apache.servicecomb.core.executor.ReactiveExecutor in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayClient method doTestSend.
private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, HighwayClientConnection tcpClient, Object decodedResponse) throws Exception {
new MockUp<VertxUtils>() {
@Mock
<VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException {
return true;
}
};
new MockUp<ClientPoolManager<HighwayClientConnectionPool>>() {
@Mock
public HighwayClientConnectionPool findClientPool(boolean sync) {
return pool;
}
};
new MockUp<ProtobufManager>() {
@Mock
public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) throws Exception {
return operationProtobuf;
}
};
new MockUp<HighwayClientConnectionPool>() {
@Mock
HighwayClientConnection findOrCreateClient(String endpoint) {
return tcpClient;
}
};
new MockUp<HighwayCodec>() {
@Mock
public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf, long msgId) throws Exception {
return null;
}
@Mock
Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Throwable {
if (Response.class.isInstance(decodedResponse)) {
return (Response) decodedResponse;
}
throw (Throwable) decodedResponse;
}
};
client.init(vertx);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
Mockito.when(invocation.getEndpoint().getEndpoint()).thenReturn("endpoint");
Mockito.when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor());
Holder<Object> result = new Holder<>();
client.send(invocation, ar -> {
result.value = ar.getResult();
});
return result.value;
}
use of org.apache.servicecomb.core.executor.ReactiveExecutor 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);
}
use of org.apache.servicecomb.core.executor.ReactiveExecutor in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method init.
@BeforeClass
public static void init() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
RegistryUtils.setServiceRegistry(serviceRegistry);
ConverterMgr converterMgr = new ConverterMgr();
ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
producerArgsMapperFactory.setConverterMgr(converterMgr);
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader() {
@Override
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
}
};
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
producerSchemaFactory.setSwaggerEnv(swaggerEnv);
ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
Executor reactiveExecutor = new ReactiveExecutor();
Executor normalExecutor = (cmd) -> {
};
new MockUp<BeanUtils>() {
@SuppressWarnings("unchecked")
@Mock
<T> T getBean(String name) {
if (ExecutorManager.EXECUTOR_REACTIVE.equals(name)) {
return (T) reactiveExecutor;
}
return (T) normalExecutor;
}
};
// ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
// BeanUtils.setContext(applicationContext);
// Mockito.when(applicationContext.getBean(ExecutorManager.EXECUTOR_REACTIVE)).thenReturn(new ReactiveExecutor());
UnitTestMeta.init();
schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Aggregations