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"));
}
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"));
}
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;
}
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());
}
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;
}
Aggregations