Search in sources :

Example 11 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class AbstractSchemaFactory method getOrCreateSchema.

// 因为aop的存在,schemaInstance的class不一定等于schemaClass
protected SchemaMeta getOrCreateSchema(CONTEXT context) {
    MicroserviceMeta microserviceMeta = context.getMicroserviceMeta();
    SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(context.getSchemaId());
    if (schemaMeta == null) {
        schemaMeta = createSchema(context);
    }
    context.setSchemaMeta(schemaMeta);
    connectToProvider(context);
    return schemaMeta;
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 12 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class InvokerUtils method syncInvoke.

public static Object syncInvoke(String microserviceName, String microserviceVersion, String transport, String schemaId, String operationName, Object[] args) {
    ReferenceConfig referenceConfig = new ReferenceConfig(microserviceName, microserviceVersion, transport);
    SchemaMeta schemaMeta = referenceConfig.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
    Invocation invocation = InvocationFactory.forConsumer(referenceConfig, schemaMeta, operationName, args);
    return syncInvoke(invocation);
}
Also used : Invocation(io.servicecomb.core.Invocation) SchemaMeta(io.servicecomb.core.definition.SchemaMeta)

Example 13 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) NormalWrapSchema(io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) Test(org.junit.Test)

Example 14 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class MockUtil method mockRequestMeta.

public void mockRequestMeta() {
    new MockUp<RequestMeta>() {

        @Mock
        public OperationMeta getOperationMeta() throws Exception {
            OperationMeta om = new OperationMeta();
            om.init(new SchemaMeta(null, new MicroserviceMeta("test"), null), this.getClass().getMethods()[0], "path", "get", null);
            return om;
        }
    };
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 15 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class TestRestEngineSchemaListener method test.

@Test
public void test() {
    BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
    MicroserviceMeta mm = new MicroserviceMeta("app:ms");
    List<SchemaMeta> smList = new ArrayList<>();
    SwaggerGenerator generator = new SwaggerGenerator(context, Impl.class);
    Swagger swagger = generator.generate();
    SchemaMeta sm1 = new SchemaMeta(swagger, mm, "sid1");
    smList.add(sm1);
    RestEngineSchemaListener listener = new RestEngineSchemaListener();
    SchemaMeta[] smArr = smList.toArray(new SchemaMeta[smList.size()]);
    listener.onSchemaLoaded(smArr);
    // 重复调用,不应该出异常
    listener.onSchemaLoaded(smArr);
    ServicePathManager spm = ServicePathManager.getServicePathManager(mm);
    Assert.assertEquals(mm, spm.getMicroserviceMeta());
    Assert.assertNotNull(spm.getStaticPathOperationMap().get("Impl/add/"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SwaggerGenerator(io.servicecomb.swagger.generator.core.SwaggerGenerator) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ArrayList(java.util.ArrayList) ServicePathManager(io.servicecomb.common.rest.locator.ServicePathManager) Test(org.junit.Test)

Aggregations

SchemaMeta (io.servicecomb.core.definition.SchemaMeta)26 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)11 Test (org.junit.Test)10 OperationMeta (io.servicecomb.core.definition.OperationMeta)8 ArrayList (java.util.ArrayList)4 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)3 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)3 Invocation (io.servicecomb.core.Invocation)3 HashMap (java.util.HashMap)3 MockUp (mockit.MockUp)3 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)2 MicroserviceMetaManager (io.servicecomb.core.definition.MicroserviceMetaManager)2 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)2 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)2 Swagger (io.swagger.models.Swagger)2 Buffer (io.vertx.core.buffer.Buffer)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 Executor (java.util.concurrent.Executor)2 ArgsNotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1