Search in sources :

Example 1 with MicroserviceMeta

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

the class TestConsumerSchemaFactory method testGetOrCreateConsumer.

@Test
public void testGetOrCreateConsumer() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    OperationMeta operationMeta = microserviceMeta.ensureFindOperation("schema.add");
    Assert.assertEquals("add", operationMeta.getOperationId());
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 2 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta 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 3 with MicroserviceMeta

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

the class TestDefinition method testMicroServiceMeta.

@Test
public void testMicroServiceMeta() {
    MicroserviceMeta oMicroMeta = new MicroserviceMeta("micro1");
    Assert.assertEquals(0, oMicroMeta.getSchemaMetas().size());
    Assert.assertEquals(0, oMicroMeta.getOperations().size());
    Assert.assertEquals("micro1", oMicroMeta.getName());
    try {
        oMicroMeta.putExtData("key1", new String("value1"));
        Assert.assertNotEquals(null, oMicroMeta.getExtData("key1"));
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) Test(org.junit.Test)

Example 4 with MicroserviceMeta

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

the class PojoReferenceMeta method prepare.

private void prepare() {
    referenceConfig = CseContext.getInstance().getConsumerProviderManager().getReferenceConfig(microserviceName);
    MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
    if (StringUtils.isEmpty(schemaId)) {
        // 未指定schemaId,看看consumer接口是否等于契约接口
        schemaMeta = microserviceMeta.findSchemaMeta(consumerIntf);
        if (schemaMeta == null) {
            // 尝试用consumer接口名作为schemaId
            schemaId = consumerIntf.getName();
            schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
        }
    } else {
        schemaMeta = microserviceMeta.ensureFindSchemaMeta(schemaId);
    }
    if (consumerIntf == null) {
        consumerIntf = schemaMeta.getSwaggerIntf();
    }
    CseContext.getInstance().getConsumerSchemaFactory().connectToConsumer(schemaMeta, consumerIntf, consumerOperationMap);
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 5 with MicroserviceMeta

use of io.servicecomb.core.definition.MicroserviceMeta 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

MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)24 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)11 Test (org.junit.Test)8 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)6 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)5 OperationMeta (io.servicecomb.core.definition.OperationMeta)4 InvocationException (io.servicecomb.core.exception.InvocationException)3 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 HashMap (java.util.HashMap)3 OperationLocator (io.servicecomb.common.rest.locator.OperationLocator)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 Swagger (io.swagger.models.Swagger)2 ArrayList (java.util.ArrayList)2 Invocation (io.servicecomb.core.Invocation)1 ProducerProvider (io.servicecomb.core.ProducerProvider)1 ConsumerSchemaFactory (io.servicecomb.core.definition.schema.ConsumerSchemaFactory)1 ReferenceConfig (io.servicecomb.core.provider.consumer.ReferenceConfig)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 SwaggerGenerator (io.servicecomb.swagger.generator.core.SwaggerGenerator)1 Mock (mockit.Mock)1