Search in sources :

Example 21 with OperationMeta

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);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(io.vertx.core.buffer.Buffer) Invocation(org.apache.servicecomb.core.Invocation) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) NotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 22 with OperationMeta

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);
}
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 23 with OperationMeta

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;
}
Also used : MicroserviceVersion(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersion) DiscoveryTreeNode(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ConcurrentHashMapEx(org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx) VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule)

Example 24 with OperationMeta

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));
}
Also used : ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 25 with OperationMeta

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;
}
Also used : Executor(java.util.concurrent.Executor) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Aggregations

OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)33 Test (org.junit.Test)14 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)12 Invocation (org.apache.servicecomb.core.Invocation)9 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)6 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)6 Endpoint (org.apache.servicecomb.core.Endpoint)5 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)5 OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)4 Response (org.apache.servicecomb.swagger.invocation.Response)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 Holder (javax.xml.ws.Holder)3 WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)3 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)3 URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)3 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)3 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)3 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)3 Buffer (io.vertx.core.buffer.Buffer)2