use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method setUp.
@Before
public void setUp() throws Exception {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
header = Mockito.mock(RequestHeader.class);
operationProtobuf = Mockito.mock(OperationProtobuf.class);
bodyBuffer = Mockito.mock(Buffer.class);
schema = Mockito.mock(WrapSchema.class);
schemaMeta = Mockito.mock(SchemaMeta.class);
operationMeta = Mockito.mock(OperationMeta.class);
lByteBuf = Mockito.mock(ByteBuf.class);
nioBuffer = Mockito.mock(ByteBuffer.class);
invocation = Mockito.mock(Invocation.class);
}
use of org.apache.servicecomb.core.definition.OperationMeta 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.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class OperationInstancesDiscoveryFilter method initOperationNodes.
protected Map<String, DiscoveryTreeNode> initOperationNodes(DiscoveryTreeNode parent, Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap) {
Map<String, DiscoveryTreeNode> tmpChildren = new ConcurrentHashMapEx<>();
versionMap.keySet().stream().sorted(Comparator.comparing(MicroserviceVersion::getVersion)).forEach(meta -> {
for (OperationMeta operationMeta : meta.getMicroserviceMeta().getOperations()) {
tmpChildren.computeIfAbsent(operationMeta.getMicroserviceQualifiedName(), qualifiedName -> {
VersionRule versionRule = VersionRuleUtils.getOrCreate(meta.getVersion().getVersion() + "+");
return new DiscoveryTreeNode().attribute(VERSION_RULE, versionRule).subName(parent, versionRule.getVersionRule()).data(new HashMap<>());
});
}
});
return tmpChildren;
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method testCompletableFuture.
@Test
public void testCompletableFuture() {
OperationMeta operationMeta = schemaMeta.ensureFindOperation("async");
Assert.assertThat(operationMeta.getExecutor(), Matchers.instanceOf(ReactiveExecutor.class));
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class ProducerSchemaFactory method getOrCreateProducerSchema.
// 只会在启动流程中调用
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) {
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName);
ProducerSchemaContext context = new ProducerSchemaContext();
context.setMicroserviceMeta(microserviceMeta);
context.setSchemaId(schemaId);
context.setProviderClass(producerClass);
context.setProducerInstance(producerInstance);
SchemaMeta schemaMeta = getOrCreateSchema(context);
SwaggerProducer producer = swaggerEnv.createProducer(producerInstance, schemaMeta.getSwagger());
Executor reactiveExecutor = BeanUtils.getBean(ExecutorManager.EXECUTOR_REACTIVE);
for (OperationMeta operationMeta : schemaMeta.getOperations()) {
SwaggerProducerOperation producerOperation = producer.findOperation(operationMeta.getOperationId());
operationMeta.putExtData(Const.PRODUCER_OPERATION, producerOperation);
if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
operationMeta.setExecutor(ExecutorManager.findExecutor(operationMeta, reactiveExecutor));
}
}
return schemaMeta;
}
Aggregations