Search in sources :

Example 96 with MicroserviceInstance

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

the class LocalServiceRegistryClientImpl method updateInstanceProperties.

@Override
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
    Map<String, MicroserviceInstance> instanceMap = microserviceInstanceMap.get(microserviceId);
    if (instanceMap == null) {
        throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
    }
    MicroserviceInstance microserviceInstance = instanceMap.get(microserviceInstanceId);
    if (microserviceInstance == null) {
        throw new IllegalArgumentException(String.format("Invalid argument. microserviceId=%s, microserviceInstanceId=%s.", microserviceId, microserviceInstanceId));
    }
    if (instanceProperties != null) {
        microserviceInstance.getProperties().putAll(instanceProperties);
    }
    return true;
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 97 with MicroserviceInstance

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

the class TestPropertiesLoader method testInstancePropertiesLoader.

@Test
public void testInstancePropertiesLoader() {
    Microservice microservice = LocalServiceRegistryFactory.createLocal().getMicroservice();
    MicroserviceInstance instance = microservice.getInstance();
    Map<String, String> expectedMap = new HashMap<>();
    expectedMap.put("key0", "value0");
    expectedMap.put("ek0", "ev0");
    Assert.assertEquals(expectedMap, instance.getProperties());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 98 with MicroserviceInstance

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

the class TestSimpleMicroserviceInstancePing method testPing_more_endpoin.

@Test
public void testPing_more_endpoin() throws IOException {
    SimpleMicroserviceInstancePing ping = new SimpleMicroserviceInstancePing();
    MicroserviceInstance instance = new MicroserviceInstance();
    List<String> endpoints = new ArrayList<>();
    ServerSocket ss = new ServerSocket(35677);
    endpoints.add("http://localhost:35676");
    endpoints.add("http://localhost:35677");
    instance.setEndpoints(endpoints);
    Assert.assertTrue(ping.ping(instance));
    ss.close();
    Assert.assertFalse(ping.ping(instance));
}
Also used : ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) ServerSocket(java.net.ServerSocket) SimpleMicroserviceInstancePing(org.apache.servicecomb.registry.consumer.SimpleMicroserviceInstancePing) Test(org.junit.Test)

Example 99 with MicroserviceInstance

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

the class TestConsumers method registryMicroserviceMapping.

@Test
public void registryMicroserviceMapping() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    RegistrationManager.INSTANCE.registerMicroserviceMapping("3rd", "1.0.0", Arrays.asList(microserviceInstance), Hello.class);
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
    Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(microserviceInstance));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 100 with MicroserviceInstance

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

the class TestInstanceCache method beforeClass.

@BeforeClass
public static void beforeClass() {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setStatus(MicroserviceInstanceStatus.UP);
    List<String> endpoints = new ArrayList<>();
    endpoints.add("rest://127.0.0.1:8080");
    instance.setEndpoints(endpoints);
    instance.setInstanceId("1");
    instMap.put(instance.getInstanceId(), instance);
    instanceCache = new InstanceCache("testAppID", "testMicroServiceName", "1.0", instMap);
}
Also used : ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache) BeforeClass(org.junit.BeforeClass)

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