/** * Gets the list of all {@link Applications} from the registry in sorted * lexical order of {@link Application#getName()}. * * @return the list of {@link Applications} in lexical order. */ @Override public List<Application> getSortedApplications() { List<Application> apps = new ArrayList<Application>(getApplications().getRegisteredApplications()); Collections.sort(apps, APP_COMPARATOR); return apps; }
public static Set<String> selectApplicationNames(Applications applications) { Set<String> result = new HashSet<>(); for (Application app : applications.getRegisteredApplications()) { result.add(app.getName()); } return result; }
public static Set<String> applicationNames(Applications applications) { Set<String> names = new HashSet<String>(); for (Application application : applications.getRegisteredApplications()) { names.add(application.getName()); } return names; }
public static int countInstances(Applications applications) { int count = 0; for(Application application: applications.getRegisteredApplications()) { count += application.getInstances().size(); } return count; } }
@Override public List<InstanceInfo> getInstancesById(String id) { List<InstanceInfo> instancesList = new ArrayList<InstanceInfo>(); for (Application app : this.getApplications() .getRegisteredApplications()) { InstanceInfo instanceInfo = app.getByInstanceId(id); if (instanceInfo != null) { instancesList.add(instanceInfo); } } return instancesList; }
public static InstanceInfo takeFirst(Applications applications) { for (Application application : applications.getRegisteredApplications()) { if (!application.getInstances().isEmpty()) { return application.getInstances().get(0); } } return null; }
public static InstanceInfo selectInstance(Applications applications, String id) { for (Application application : applications.getRegisteredApplications()) { for (InstanceInfo instance : application.getInstances()) { if (instance.getId().equals(id)) { return instance; } } } return null; }
@Override public Boolean call() throws Exception { List<Application> applicationList = client.getApplications().getRegisteredApplications(); return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2; } }, 1, TimeUnit.MINUTES);
@Override public Boolean call() throws Exception { List<Application> applicationList = client.getApplications().getRegisteredApplications(); return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2; } }, 1, TimeUnit.MINUTES);
public static void copyApplications(Applications source, Applications result) { if (source != null) { for (Application app : source.getRegisteredApplications()) { result.addApplication(new Application(app.getName(), app.getInstances())); } } }
@Test public void testGetVipWithRemoteRegionRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress(); when(requestHandler.getVip(vipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress, REMOTE_REGION); verifyResponseOkWithEntity(vipApps, httpResponse); }
@Test public void testGetSecureVipWithRemoteRegionRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String secureVipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getSecureVipAddress(); when(requestHandler.getSecureVip(secureVipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getSecureVip(secureVipAddress, REMOTE_REGION); verifyResponseOkWithEntity(vipApps, httpResponse); }
@Test public void testGetVipRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress(); when(requestHandler.getVip(vipAddress)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress); verifyResponseOkWithEntity(vipApps, httpResponse); }
public static void copyInstances(Collection<InstanceInfo> instances, Applications result) { if (instances != null) { for (InstanceInfo instance : instances) { Application app = result.getRegisteredApplications(instance.getAppName()); if (app == null) { app = new Application(instance.getAppName()); result.addApplication(app); } app.addInstance(instance); } } }
@Test public void testGetAppsFromAllRemoteRegions() throws Exception { Applications apps = registry.getApplicationsFromAllRemoteRegions(); List<Application> registeredApplications = apps.getRegisteredApplications(); Assert.assertEquals("Apps size from remote regions do not match", 1, registeredApplications.size()); Application app = registeredApplications.iterator().next(); Assert.assertEquals("Added app did not return from remote registry", REMOTE_REGION_APP_NAME, app.getName()); Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size()); }
public static Applications toApplications(List<InstanceInfo> instances) { Applications result = new Applications(); for (InstanceInfo instance : instances) { Application app = result.getRegisteredApplications(instance.getAppName()); if (app == null) { app = new Application(instance.getAppName()); result.addApplication(app); } app.addInstance(instance); } return updateMeta(result); }
@Before public void setUp() { when(clientConfig.getEurekaServerURLContext()).thenReturn("context"); when(clientConfig.getRegion()).thenReturn("region"); applications = InstanceInfoGenerator.newBuilder(5, "eurekaRead", "someOther").build().toApplications(); vipAddress = applications.getRegisteredApplications("eurekaRead").getInstances().get(0).getVIPAddress(); when(clientFactory.newClient()).thenReturn(httpClient); when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, applications).build()); resolver = new EurekaHttpResolver(clientConfig, transportConfig, clientFactory, vipAddress); }
@Test public void testLocalOnly() throws Exception { setUp(false); Applications applications = client.getApplications(); List<Application> registeredApplications = applications.getRegisteredApplications(); System.out.println("***" + registeredApplications); Assert.assertNotNull("Local region apps not found.", registeredApplications); Assert.assertEquals("Local apps size not as expected.", 1, registeredApplications.size()); Assert.assertEquals("Local region apps not present.", LOCAL_REGION_APP_NAME, registeredApplications.get(0).getName()); }
@Test public void testGetAppsFromLocalRegionOnly() throws Exception { registerInstanceLocally(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME)); Applications apps = registry.getApplicationsFromLocalRegionOnly(); List<Application> registeredApplications = apps.getRegisteredApplications(); Assert.assertEquals("Apps size from local region do not match", 1, registeredApplications.size()); Application app = registeredApplications.iterator().next(); Assert.assertEquals("Added app did not return from local registry", LOCAL_REGION_APP_NAME, app.getName()); Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size()); }
@Test public void testRemoteEnabledAndQueried() throws Exception { setUp(true); Applications applications = client.getApplicationsForARegion(REMOTE_REGION); List<Application> registeredApplications = applications.getRegisteredApplications(); Assert.assertNotNull("Remote region apps not found.", registeredApplications); Assert.assertEquals("Remote apps size not as expected.", 1, registeredApplications.size()); Assert.assertEquals("Remote region apps not present.", REMOTE_REGION_APP_NAME, registeredApplications.get(0).getName()); }