Search in sources :

Example 1 with SchemaMeta

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

the class TestConsumerSchemaFactory method testConnectToConsumerDiff.

@Test
public void testConnectToConsumerDiff() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta("schema");
    Map<String, ConsumerOperationMeta> consumerOperationMap = new HashMap<>();
    consumerSchemaFactory.connectToConsumer(schemaMeta, Intf.class, consumerOperationMap);
    Assert.assertEquals(1, consumerOperationMap.size());
    ConsumerOperationMeta consumerOperationMeta = consumerOperationMap.get("add");
    Assert.assertEquals(ConsumerArgumentToBodyField.class, consumerOperationMeta.getArgsMapper().getArgumentMapper(0).getClass());
    Assert.assertEquals(ConsumerResponseSame.class, consumerOperationMeta.getResponseMapper().getClass());
}
Also used : HashMap(java.util.HashMap) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) Test(org.junit.Test)

Example 2 with SchemaMeta

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

the class ClientVerticle method send.

protected void send(Long event) {
    User user = new User();
    TestRequest request = new TestRequest();
    request.setUser(user);
    request.setIndex(idx);
    request.setData(PojoClient.buffer);
    SchemaMeta schemaMeta = config.getMicroserviceMeta().ensureFindSchemaMeta("server");
    Object[] args = new Object[] { request };
    Invocation invocation = InvocationFactory.forConsumer(config, schemaMeta, "wrapParam", args);
    InvokerUtils.reactiveInvoke(invocation, ar -> {
        if (ar.isSuccessed()) {
            User result = ar.getResult();
            if (result.getIndex() != idx) {
                System.out.printf("error result:%s, expect idx %d\n", result, idx);
            }
        } else {
            CommonExceptionData data = (CommonExceptionData) ((InvocationException) ar.getResult()).getErrorData();
            System.out.println(data.getMessage());
        }
        send(null);
    });
}
Also used : User(io.servicecomb.demo.server.User) Invocation(io.servicecomb.core.Invocation) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) TestRequest(io.servicecomb.demo.server.TestRequest)

Example 3 with SchemaMeta

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

the class TestDynamicSchemaLoader method testRegisterSchemas.

@Test
public void testRegisterSchemas() {
    DynamicSchemaLoader.INSTANCE.registerSchemas("classpath*:test/test/schema.yaml");
    SchemaMeta schemaMeta = microserviceMetaManager.ensureFindSchemaMeta("ms", "schema");
    Assert.assertEquals("cse.gen.app.ms.schema", schemaMeta.getPackageName());
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) Test(org.junit.Test)

Example 4 with SchemaMeta

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

the class MockUtil method mockMicroserviceMeta.

public void mockMicroserviceMeta() {
    new MockUp<MicroserviceMeta>() {

        @Mock
        public SchemaMeta ensureFindSchemaMeta(String schemaId) {
            SchemaMeta lSchemaMeta = Mockito.mock(SchemaMeta.class);
            Mockito.when(lSchemaMeta.getSwaggerIntf()).thenAnswer(new Answer<Class<? extends TestPojoConsumerProvider>>() {

                @Override
                public Class<? extends TestPojoConsumerProvider> answer(InvocationOnMock invocation) throws Throwable {
                    return TestPojoConsumerProvider.class;
                }
            });
            return lSchemaMeta;
        }

        @Mock
        public SchemaMeta ensureFindSchemaMeta(Class<?> schemaIntf) {
            return Mockito.mock(SchemaMeta.class);
        }
    };
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MockUp(mockit.MockUp) TestPojoConsumerProvider(io.servicecomb.provider.pojo.TestPojoConsumerProvider)

Example 5 with SchemaMeta

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

the class GrpcServerInvoke method doInit.

private void doInit(RoutingContext routingContext) throws Exception {
    String schemaId = routingContext.pathParam("schema");
    String operationName = routingContext.pathParam("operation");
    MicroserviceMeta microserviceMeta = microserviceMetaManager.ensureFindValue(routingContext.request().getHeader(Const.DEST_MICROSERVICE));
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
    this.routingContext = routingContext;
    this.operationMeta = schemaMeta.ensureFindOperation(operationName);
    this.operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

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