Search in sources :

Example 36 with MicroserviceInstance

use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.

the class TestAbstractTransportDiscoveryFilter method createDiscoveryTree_oneTransport.

@Test
public void createDiscoveryTree_oneTransport() {
    MicroserviceInstance instance1 = createInstance("a", "b");
    MicroserviceInstance instance2 = createInstance("b");
    Map<String, MicroserviceInstance> instances = createMicroserviceInstances("name", instance1, instance2);
    parent.data(instances);
    result = filter.createDiscoveryTreeNode("a", context, parent);
    Assert.assertEquals("parent/a", result.name());
    Assert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().get(0)));
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 37 with MicroserviceInstance

use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.

the class TestAbstractTransportDiscoveryFilter method createEndpointNull.

@Test
public void createEndpointNull() {
    disableCreate = true;
    MicroserviceInstance instance1 = createInstance("a", "b");
    Map<String, MicroserviceInstance> instances = createMicroserviceInstances("name", instance1);
    parent.data(instances);
    result = filter.createDiscoveryTreeNode("", context, parent);
    Assert.assertEquals("parent/", result.name());
    Assert.assertThat(result.collectionData(), Matchers.empty());
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 38 with MicroserviceInstance

use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.

the class TestAbstractTransportDiscoveryFilter method createInstance.

private MicroserviceInstance createInstance(String... schemas) {
    String id = UUID.randomUUID().toString();
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId(id);
    for (int idx = 0; idx < schemas.length; idx++) {
        String schema = schemas[idx];
        instance.getEndpoints().add(String.format("%s://%s:%d", schema, id, 8080 + idx));
    }
    return instance;
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)

Example 39 with MicroserviceInstance

use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method findServiceInstance_twoSelectOne.

@Test
public void findServiceInstance_twoSelectOne() {
    Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    mockRegisterMicroservice(appId, microserviceName, "2.0.0");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId(v1.getServiceId());
    registryClient.registerMicroserviceInstance(instance);
    List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, "1.0.0");
    Assert.assertThat(result, Matchers.contains(instance));
    MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, "1.0.0", "0");
    List<MicroserviceInstance> results = microserviceInstances.getInstancesResponse().getInstances();
    Assert.assertThat(results, Matchers.contains(instance));
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 40 with MicroserviceInstance

use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method testFindServiceInstance.

@Test
public void testFindServiceInstance() {
    Microservice microservice = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId(microservice.getServiceId());
    String instanceId = registryClient.registerMicroserviceInstance(instance);
    Assert.assertNotNull(registryClient.findServiceInstance(microservice.getServiceId(), instanceId));
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Aggregations

MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)56 Test (org.junit.Test)30 Expectations (mockit.Expectations)16 ArrayList (java.util.ArrayList)15 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)15 HashMap (java.util.HashMap)11 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)7 Before (org.junit.Before)5 EventBus (com.google.common.eventbus.EventBus)4 Server (com.netflix.loadbalancer.Server)4 BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)4 CseServer (org.apache.servicecomb.loadbalance.CseServer)4 Subscribe (com.google.common.eventbus.Subscribe)3 Map (java.util.Map)3 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)3 MicroserviceInstanceRegisterTask (org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask)3 URI (java.net.URI)2 List (java.util.List)2 RSAProviderTokenManager (org.apache.servicecomb.authentication.provider.RSAProviderTokenManager)2 SchemaListenerManager (org.apache.servicecomb.core.definition.loader.SchemaListenerManager)2