Search in sources :

Example 51 with MicroserviceInstance

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

the class TestCseDiscoveryClient method testCseDiscoveryClient.

@Test
public void testCseDiscoveryClient(@Mocked RegistryUtils registryUtils, @Injectable ServiceRegistryClient serviceRegistryClient, @Mocked DiscoveryTree discoveryTree, @Injectable DiscoveryTreeNode versionedCache) {
    List<Microservice> microserviceList = new ArrayList<>();
    Microservice service1 = new Microservice();
    service1.setServiceName("service1");
    microserviceList.add(service1);
    Microservice server2 = new Microservice();
    microserviceList.add(server2);
    server2.setServiceName("server2");
    Map<String, MicroserviceInstance> servers = new HashMap<>();
    List<String> endpoints = new ArrayList<>();
    endpoints.add("rest://localhost:3333");
    endpoints.add("rest://localhost:4444");
    MicroserviceInstance instance1 = new MicroserviceInstance();
    instance1.setServiceId("service1");
    instance1.setInstanceId("service1-instance1");
    instance1.setEndpoints(endpoints);
    servers.put("service1-instance1", instance1);
    new Expectations() {

        {
            RegistryUtils.getServiceRegistryClient();
            result = serviceRegistryClient;
            serviceRegistryClient.getAllMicroservices();
            result = microserviceList;
            discoveryTree.discovery((DiscoveryContext) any, anyString, anyString, anyString);
            result = versionedCache;
            versionedCache.data();
            result = servers;
        }
    };
    DiscoveryClient client = new CseDiscoveryClient();
    Assert.assertEquals("Spring Cloud CSE Discovery Client", client.description());
    Assert.assertEquals(null, client.getLocalServiceInstance());
    Assert.assertEquals(2, client.getServices().size());
    Assert.assertEquals("server2", client.getServices().get(1));
    Assert.assertEquals(2, client.getInstances("service1-instance1").size());
    Assert.assertEquals(4444, client.getInstances("service1-instance1").get(1).getPort());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) Test(org.junit.Test)

Example 52 with MicroserviceInstance

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

the class TestLoadbalanceHandler method getOrCreateLoadBalancer.

@Test
public void getOrCreateLoadBalancer() throws Exception {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("id");
    instance.getEndpoints().add("rest://localhost:8080");
    Map<String, MicroserviceInstance> instanceMap = new HashMap<>();
    instanceMap.put(instance.getInstanceId(), instance);
    VersionedCache instanceVersionedCache = new VersionedCache().autoCacheVersion().name("instanceCache").data(instanceMap);
    new Expectations() {

        {
            invocation.getConfigTransportName();
            result = "rest";
            instanceCacheManager.getOrCreateVersionedCache(anyString, anyString, anyString);
            result = instanceVersionedCache;
        }
    };
    LoadBalancer lb = handler.getOrCreateLoadBalancer(invocation);
    Assert.assertEquals(2, lb.getFilterSize());
    Assert.assertEquals("instanceCache/rest", lb.getName());
    Assert.assertEquals("[rest://localhost:8080]", Deencapsulation.getField(lb, "serverList").toString());
}
Also used : Expectations(mockit.Expectations) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 53 with MicroserviceInstance

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

the class TestCseServerDiscoveryFilter method createEndpointNormal.

@Test
public void createEndpointNormal() {
    new Expectations() {

        {
            transportManager.findTransport(anyString);
            result = trasport;
        }
    };
    MicroserviceInstance instance = new MicroserviceInstance();
    CseServer server = (CseServer) filter.createEndpoint(Const.RESTFUL, "rest://localhost:8080", instance);
    Assert.assertSame(instance, server.getInstance());
    Assert.assertSame(trasport, server.getEndpoint().getTransport());
    Assert.assertEquals("rest://localhost:8080", server.getEndpoint().getEndpoint());
}
Also used : Expectations(mockit.Expectations) CseServer(org.apache.servicecomb.loadbalance.CseServer) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 54 with MicroserviceInstance

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

the class TestSimpleTransactionControlFilter method setUp.

@Before
public void setUp() {
    filter = new SimpleTransactionControlFilter();
    Map<String, String> properties = new HashMap<>();
    properties.put("tag0", "value0");
    properties.put("tag1", "value1");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setProperties(properties);
    server = Mockito.mock(CseServer.class);
    Mockito.when(server.getInstance()).thenReturn(instance);
}
Also used : CseServer(org.apache.servicecomb.loadbalance.CseServer) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Before(org.junit.Before)

Example 55 with MicroserviceInstance

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

the class TestAuthHandlerBoot method testGenerateRSAKey.

@Test
public void testGenerateRSAKey() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    Microservice microservice = new Microservice();
    microservice.setInstance(microserviceInstance);
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.getMicroserviceInstance();
            result = microserviceInstance;
        }
    };
    AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
    BootEvent bootEvent = new BootEvent();
    bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
    authHandlerBoot.onBootEvent(bootEvent);
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPrivateKey());
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPublicKey());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) AuthHandlerBoot(org.apache.servicecomb.AuthHandlerBoot) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) 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