Search in sources :

Example 11 with MicroserviceInstance

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

the class TestMicroserviceRegisterTask method setup.

@Before
public void setup() {
    eventBus = new EventBus();
    taskList = new ArrayList<>();
    eventBus.register(new Object() {

        @Subscribe
        public void onEvent(MicroserviceRegisterTask task) {
            taskList.add(task);
        }
    });
    microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceName("ms");
    microservice.setInstance(new MicroserviceInstance());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 12 with MicroserviceInstance

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

the class TestMicroserviceVersionRule method setInstances.

@Test
public void setInstances() {
    MicroserviceVersion v1 = MicroserviceVersionTestUtils.createMicroserviceVersion("1", "0.0.1");
    microserviceVersionRule.addMicroserviceVersion(v1);
    MicroserviceVersion v2 = MicroserviceVersionTestUtils.createMicroserviceVersion("2", "2.0.0");
    microserviceVersionRule.addMicroserviceVersion(v2);
    MicroserviceInstance instance1 = new MicroserviceInstance();
    instance1.setServiceId("1");
    instance1.setInstanceId("i1");
    MicroserviceInstance instance2 = new MicroserviceInstance();
    instance2.setServiceId("2");
    instance2.setInstanceId("i2");
    MicroserviceInstance instance3 = new MicroserviceInstance();
    instance3.setServiceId("3");
    instance3.setInstanceId("i3");
    InstanceCache orgCache = microserviceVersionRule.getInstanceCache();
    microserviceVersionRule.setInstances(Arrays.asList(instance1, instance2, instance3));
    Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(instance2));
    Assert.assertNotSame(orgCache, microserviceVersionRule.getInstanceCache());
    Assert.assertSame(microserviceVersionRule.getInstances(), microserviceVersionRule.getInstanceCache().getInstanceMap());
    Assert.assertSame(microserviceVersionRule.getInstances(), microserviceVersionRule.getVersionedCache().data());
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) InstanceCache(org.apache.servicecomb.serviceregistry.cache.InstanceCache) Test(org.junit.Test)

Example 13 with MicroserviceInstance

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

the class TestMicroserviceVersions method createInstance.

private void createInstance(String microserviceId) {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("i" + microserviceId);
    instance.setServiceId(microserviceId);
    instances.add(instance);
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)

Example 14 with MicroserviceInstance

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

the class TestAbstractTransportDiscoveryFilter method createDiscoveryTree_ignoreInvalid.

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

Example 15 with MicroserviceInstance

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

the class TestAbstractTransportDiscoveryFilter method createDiscoveryTree_allTransport.

@Test
public void createDiscoveryTree_allTransport() {
    MicroserviceInstance instance1 = createInstance("a", "b");
    MicroserviceInstance instance2 = createInstance("b");
    Map<String, MicroserviceInstance> instances = createMicroserviceInstances("name", instance1, instance2);
    parent.data(instances);
    result = filter.createDiscoveryTreeNode("", context, parent);
    Assert.assertEquals("parent/", result.name());
    List<String> expect = new ArrayList<>();
    expect.addAll(instance1.getEndpoints());
    expect.addAll(instance2.getEndpoints());
    Assert.assertThat(result.collectionData(), Matchers.contains(expect.toArray()));
}
Also used : ArrayList(java.util.ArrayList) 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