Search in sources :

Example 21 with MetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.

the class ConsulMetaDataCollectorTest method testGetProviderMetaData.

@Test
public void testGetProviderMetaData() {
    MetadataIdentifier identifier = buildIdentifier(true);
    Map<String, String> params = new HashMap<>();
    params.put("key1", "value1");
    params.put("key2", "true");
    FullServiceDefinition definition = ServiceDefinitionBuilder.buildFullDefinition(ServiceA.class, params);
    String metadata = gson.toJson(definition);
    consulMetaDataCollector.getClient().setKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), metadata);
    String providerMetaData = consulMetaDataCollector.getProviderMetaData(identifier);
    Assert.assertEquals(metadata, providerMetaData);
    FullServiceDefinition retDef = gson.fromJson(providerMetaData, FullServiceDefinition.class);
    Assert.assertEquals(ServiceA.class.getCanonicalName(), retDef.getCanonicalName());
    Assert.assertEquals(ClassUtils.getCodeSource(ServiceA.class), retDef.getCodeSource());
    Assert.assertEquals(params, retDef.getParameters());
    // method def assertions
    Assert.assertNotNull(retDef.getMethods());
    Assert.assertEquals(3, retDef.getMethods().size());
    List<String> methodNames = retDef.getMethods().stream().map(MethodDefinition::getName).sorted().collect(Collectors.toList());
    Assert.assertEquals("method1", methodNames.get(0));
    Assert.assertEquals("method2", methodNames.get(1));
    Assert.assertEquals("method3", methodNames.get(2));
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) HashMap(java.util.HashMap) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) Test(org.junit.Test)

Example 22 with MetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.

the class ConsulMetaDataCollectorTest method buildIdentifier.

private MetadataIdentifier buildIdentifier(boolean isProducer) {
    MetadataIdentifier identifier = new MetadataIdentifier();
    identifier.setApplication(String.format("metadata-%s-test", isProducer ? "provider" : "consumer"));
    identifier.setGroup("group");
    identifier.setServiceInterface(ServiceA.class.getName());
    identifier.setSide(isProducer ? PROVIDER_SIDE : CONSUMER_SIDE);
    identifier.setVersion("1.0.0");
    return identifier;
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)

Aggregations

MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)22 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)12 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)11 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)10 URL (org.apache.dubbo.common.URL)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)6 Gson (com.google.gson.Gson)5 GetResponse (io.etcd.jetcd.kv.GetResponse)2 Consumer (org.apache.dubbo.admin.model.domain.Consumer)2 Provider (org.apache.dubbo.admin.model.domain.Provider)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)2 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)2 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)2 RpcException (org.apache.dubbo.rpc.RpcException)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Jedis (redis.clients.jedis.Jedis)2 JsonParseException (com.google.gson.JsonParseException)1