Search in sources :

Example 21 with SchemaMeta

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

the class TestConsumerSchemaFactory method testConnectToConsumerSame.

@Test
public void testConnectToConsumerSame() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta("schema");
    Map<String, ConsumerOperationMeta> consumerOperationMap = new HashMap<>();
    consumerSchemaFactory.connectToConsumer(schemaMeta, null, consumerOperationMap);
    Assert.assertEquals(1, consumerOperationMap.size());
    ConsumerOperationMeta consumerOperationMeta = consumerOperationMap.get("add");
    Assert.assertEquals(ConsumerArgumentSame.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 22 with SchemaMeta

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

the class UnitTestMeta method getOrCreateSchemaMeta.

public SchemaMeta getOrCreateSchemaMeta(String appId, String microserviceName, String schemaId, Class<?> impl) {
    String longName = appId + ":" + microserviceName;
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(longName);
    SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(schemaId);
    if (schemaMeta != null) {
        return schemaMeta;
    }
    Swagger swagger = UnitTestSwaggerUtils.generateSwagger(impl).getSwagger();
    return schemaLoader.registerSchema(microserviceMeta, schemaId, swagger);
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 23 with SchemaMeta

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

the class ProducerProviderManager method init.

public void init() throws Exception {
    for (ProducerProvider provider : producerProviderList) {
        provider.init();
    }
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(RegistryUtils.getMicroservice().getServiceName());
    for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) {
        String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger());
        RegistryUtils.getMicroservice().addSchema(schemaMeta.getSchemaId(), content);
    }
}
Also used : ProducerProvider(io.servicecomb.core.ProducerProvider) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 24 with SchemaMeta

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

the class TestConsumer method testInvocation.

@Test
public void testInvocation() {
    OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
    SchemaMeta oSchemaMeta = Mockito.mock(SchemaMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    List<Handler> oHandlerList = new ArrayList<>();
    Mockito.when(oSchemaMeta.getProviderHandlerChain()).thenReturn(oHandlerList);
    Mockito.when(oSchemaMeta.getMicroserviceName()).thenReturn("TMK");
    Mockito.when(oOperationMeta.getSchemaMeta()).thenReturn(oSchemaMeta);
    Endpoint oEndpoint = Mockito.mock(Endpoint.class);
    Transport oTransport = Mockito.mock(Transport.class);
    Mockito.when(oEndpoint.getTransport()).thenReturn(oTransport);
    Mockito.when(oOperationMeta.getOperationId()).thenReturn("TMK");
    Invocation oInvocation = new Invocation(oEndpoint, oOperationMeta, null);
    Assert.assertNotNull(oInvocation.getTransport());
    Assert.assertNotNull(oInvocation.getInvocationType());
    oInvocation.setResponseExecutor(Mockito.mock(Executor.class));
    Assert.assertNotNull(oInvocation.getResponseExecutor());
    Assert.assertNotNull(oInvocation.getSchemaMeta());
    Assert.assertNotNull(oInvocation.getOperationMeta());
    Assert.assertNull(oInvocation.getArgs());
    Assert.assertNotNull(oInvocation.getEndpoint());
    oInvocation.setEndpoint(null);
    Map<String, String> map = oInvocation.getContext();
    Assert.assertNotNull(map);
    String str = oInvocation.getSchemaId();
    Assert.assertEquals(null, str);
    String str1 = oInvocation.getMicroserviceName();
    Assert.assertEquals("TMK", str1);
    Map<String, Object> mapp = oInvocation.getHandlerContext();
    Assert.assertNotNull(mapp);
    Assert.assertEquals(true, oInvocation.getHandlerIndex() >= 0);
    oInvocation.setHandlerIndex(8);
    Assert.assertEquals("TMK", oInvocation.getOperationName());
    Assert.assertEquals("TMK", oInvocation.getMicroserviceName());
    boolean validAssert;
    try {
        validAssert = true;
        oInvocation.next(asyncResp);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : ArrayList(java.util.ArrayList) Executor(java.util.concurrent.Executor) SyncResponseExecutor(io.servicecomb.core.provider.consumer.SyncResponseExecutor) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 25 with SchemaMeta

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

the class HighwayServerInvoke method doInit.

private void doInit(NetSocket netSocket, long msgId, RequestHeader header, Buffer bodyBuffer) throws Exception {
    this.netSocket = netSocket;
    this.msgId = msgId;
    this.header = header;
    MicroserviceMeta microserviceMeta = microserviceMetaManager.ensureFindValue(header.getDestMicroservice());
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta(header.getSchemaId());
    this.operationMeta = schemaMeta.ensureFindOperation(header.getOperationName());
    this.operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    this.bodyBuffer = bodyBuffer;
}
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