Search in sources :

Example 6 with URL

use of com.networknt.registry.URL in project light-4j by networknt.

the class LocalFirstLoadBalanceTest method testSelect.

@Test
public void testSelect() throws Exception {
    List<URL> urls = new ArrayList<>();
    urls.add(new URLImpl("http", "127.0.0.10", 8081, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.1", 8081, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.11", 8082, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.12", 8083, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.115", 8084, "v1", new HashMap<String, String>()));
    URL url = loadBalance.select(urls, null);
    Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8081/v1"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl) Test(org.junit.Test)

Example 7 with URL

use of com.networknt.registry.URL in project light-4j by networknt.

the class LocalFirstLoadBalanceTest method testSelectFirstThenRoundRobin.

@Test
public void testSelectFirstThenRoundRobin() throws Exception {
    List<URL> urls = new ArrayList<>();
    urls.add(new URLImpl("http", "127.0.0.10", 8081, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.10", 8082, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.10", 8083, "v1", new HashMap<String, String>()));
    urls.add(new URLImpl("http", "127.0.0.10", 8084, "v1", new HashMap<String, String>()));
    // no local host URL available, go round-robin
    URL url = loadBalance.select(urls, null);
    Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.10:8082/v1"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl) Test(org.junit.Test)

Example 8 with URL

use of com.networknt.registry.URL in project light-4j by networknt.

the class ConsulTest method getMockUrl.

public static URL getMockUrl(String protocol, String address, int port, String serviceName) {
    Map<String, String> params = new HashMap<>();
    params.put("environment", "test1");
    URL url = new URLImpl(protocol, address, port, serviceName, params);
    return url;
}
Also used : HashMap(java.util.HashMap) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl)

Example 9 with URL

use of com.networknt.registry.URL in project light-4j by networknt.

the class DirectRegistryTest method testDirectRegistry.

@Test
public void testDirectRegistry() {
    Registry registry = (Registry) SingletonServiceFactory.getBean(Registry.class);
    URL subscribeUrl = URLImpl.valueOf("light://localhost:8080/token");
    List<URL> urls = registry.discover(subscribeUrl);
    Assert.assertEquals(1, urls.size());
    subscribeUrl = URLImpl.valueOf("light://localhost:8080/code");
    urls = registry.discover(subscribeUrl);
    Assert.assertEquals(2, urls.size());
}
Also used : Registry(com.networknt.registry.Registry) URL(com.networknt.registry.URL) Test(org.junit.Test)

Example 10 with URL

use of com.networknt.registry.URL in project light-4j by networknt.

the class AbstractRegistry method getCachedUrls.

List<URL> getCachedUrls(URL url) {
    Map<String, List<URL>> rsUrls = subscribedCategoryResponses.get(url);
    if (rsUrls == null || rsUrls.size() == 0) {
        return null;
    }
    List<URL> urls = new ArrayList<>();
    for (List<URL> us : rsUrls.values()) {
        for (URL tempUrl : us) {
            urls.add(tempUrl.createCopy());
        }
    }
    return urls;
}
Also used : URL(com.networknt.registry.URL)

Aggregations

URL (com.networknt.registry.URL)25 ArrayList (java.util.ArrayList)11 URLImpl (com.networknt.registry.URLImpl)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 FrameworkException (com.networknt.exception.FrameworkException)3 List (java.util.List)3 Map (java.util.Map)3 NotifyListener (com.networknt.registry.NotifyListener)2 Registry (com.networknt.registry.Registry)1 ServiceListener (com.networknt.registry.support.command.ServiceListener)1 Status (com.networknt.status.Status)1 ConcurrentHashSet (com.networknt.utility.ConcurrentHashSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1