Search in sources :

Example 56 with MicroserviceInstance

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

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.setInstanceId("testid");
    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.registry.api.registry.Microservice) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 57 with MicroserviceInstance

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

the class LocalServiceRegistryClientImplTest method undateMicroserviceInstanceStatus_illegal_status.

@SuppressWarnings("deprecation")
@Test
public void undateMicroserviceInstanceStatus_illegal_status() {
    List<MicroserviceInstance> m = registryClient.findServiceInstance("", "default", "ms2", DefinitionConst.VERSION_RULE_ALL);
    MicroserviceInstance instance = m.get(0);
    try {
        registryClient.undateMicroserviceInstanceStatus(instance.getServiceId(), instance.getInstanceId(), null);
        shouldThrowException();
    } catch (NullPointerException e) {
        Assert.assertEquals("Name is null", e.getMessage());
    }
    try {
        registryClient.undateMicroserviceInstanceStatus(instance.getServiceId(), instance.getInstanceId(), "IllegalStatus");
        shouldThrowException();
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("Invalid status: IllegalStatus", e.getMessage());
    }
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 58 with MicroserviceInstance

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

the class LocalServiceRegistryClientImplTest method testLoadRegistryFile.

@Test
public void testLoadRegistryFile() {
    Assert.assertNotNull(registryClient);
    Assert.assertThat(registryClient.getAllMicroservices().size(), Is.is(2));
    List<MicroserviceInstance> m = registryClient.findServiceInstance("", "default", "ms2", DefinitionConst.VERSION_RULE_ALL);
    Assert.assertEquals(1, m.size());
    MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("", "default", "ms2", DefinitionConst.VERSION_RULE_ALL, null);
    List<MicroserviceInstance> mi = microserviceInstances.getInstancesResponse().getInstances();
    Assert.assertEquals(1, mi.size());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 59 with MicroserviceInstance

use of org.apache.servicecomb.registry.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.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 60 with MicroserviceInstance

use of org.apache.servicecomb.registry.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.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Aggregations

MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)232 Test (org.junit.Test)136 ArrayList (java.util.ArrayList)60 HashMap (java.util.HashMap)42 Invocation (org.apache.servicecomb.core.Invocation)40 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)40 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)38 Expectations (mockit.Expectations)36 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)32 CacheEndpoint (org.apache.servicecomb.registry.cache.CacheEndpoint)30 List (java.util.List)22 Transport (org.apache.servicecomb.core.Transport)22 Before (org.junit.Before)22 Map (java.util.Map)18 TransportManager (org.apache.servicecomb.core.transport.TransportManager)18 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)18 MockUp (mockit.MockUp)16 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)14 ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)14 Server (com.netflix.loadbalancer.Server)12