public Applications build() { return new Applications(appsHashCode, version, applications); } }
@Override public Applications fetchRegistry() { if (null == localRegionApps) { return new Applications(); } return localRegionApps; }
public static Applications toApplications(Map<String, Application> applicationMap) { Applications applications = new Applications(); for (Application application : applicationMap.values()) { applications.addApplication(application); } return updateMeta(applications); }
public static Applications toApplications(Map<String, Application> applicationMap) { Applications applications = new Applications(); for (Application application : applicationMap.values()) { applications.addApplication(application); } return updateMeta(applications); }
public static Applications copyApplications(Applications source) { Applications result = new Applications(); copyApplications(source, result); return updateMeta(result); }
public static Applications deepCopyApplications(Applications source) { Applications result = new Applications(); for (Application application : source.getRegisteredApplications()) { result.addApplication(deepCopyApplication(application)); } return updateMeta(result); }
public Applications takeDelta(int count) { if (currentIt == null) { currentIt = serviceIterator(); allApplications = new Applications(); } List<InstanceInfo> instanceBatch = new ArrayList<InstanceInfo>(); for (int i = 0; i < count; i++) { InstanceInfo next = currentIt.next(); next.setActionType(ActionType.ADDED); instanceBatch.add(next); } Applications nextBatch = EurekaEntityFunctions.toApplications(toApplicationMap(instanceBatch)); allApplications = mergeApplications(allApplications, nextBatch); nextBatch.setAppsHashCode(allApplications.getAppsHashCode()); return nextBatch; }
@Before public void setUp() throws Exception { reset(requestHandler); when(requestHandler.register(any(InstanceInfo.class))).thenReturn(EurekaHttpResponse.status(204)); when(requestHandler.cancel(anyString(), anyString())).thenReturn(EurekaHttpResponse.status(200)); when(requestHandler.getDelta()).thenReturn( anEurekaHttpResponse(200, new Applications()).type(MediaType.APPLICATION_JSON_TYPE).build() ); }
@Before public void setUp() throws Exception { reset(requestHandler); when(requestHandler.cancel(anyString(), anyString())).thenReturn(EurekaHttpResponse.status(200)); when(requestHandler.getDelta()).thenReturn( anEurekaHttpResponse(200, new Applications()).type(MediaType.APPLICATION_JSON_TYPE).build() ); }
@Before public void setUp() throws Exception { reset(requestHandler); when(requestHandler.register(any(InstanceInfo.class))).thenReturn(EurekaHttpResponse.status(204)); when(requestHandler.cancel(anyString(), anyString())).thenReturn(EurekaHttpResponse.status(200)); when(requestHandler.getDelta()).thenReturn( anEurekaHttpResponse(200, new Applications()).type(MediaType.APPLICATION_JSON_TYPE).build() ); }
private void setupBackupMock() { Application localApp = createLocalApps(); Applications localApps = new Applications(); localApps.addApplication(localApp); backupRegistry.setLocalRegionApps(localApps); Application remoteApp = createRemoteApps(); Applications remoteApps = new Applications(); remoteApps.addApplication(remoteApp); backupRegistry.getRemoteRegionVsApps().put(REMOTE_REGION, remoteApps); }
public static Applications mergeApplications(Applications first, Applications second) { Set<String> firstNames = selectApplicationNames(first); Set<String> secondNames = selectApplicationNames(second); Set<String> allNames = new HashSet<String>(firstNames); allNames.addAll(secondNames); Applications merged = new Applications(); for (String appName : allNames) { if (firstNames.contains(appName)) { if (secondNames.contains(appName)) { merged.addApplication(mergeApplication(first.getRegisteredApplications(appName), second.getRegisteredApplications(appName))); } else { merged.addApplication(copyApplication(first.getRegisteredApplications(appName))); } } else { merged.addApplication(copyApplication(second.getRegisteredApplications(appName))); } } return updateMeta(merged); }
protected String getDeltaAppsHashCode(boolean includeRemote) { Applications allApps = new Applications(); for (Application application : applicationMap.values()) { allApps.addApplication(application); } if (includeRemote) { for (Application application : remoteRegionApps.values()) { allApps.addApplication(application); } } addDeltaApps(includeRemote, allApps); return allApps.getReconcileHashCode(); }
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); }
@Test public void testNonRedirectedRequestsAreServedByFirstClient() throws Exception { when(factory.newClient(Matchers.<EurekaEndpoint>anyVararg())).thenReturn(sourceClient); when(sourceClient.getApplications()).thenReturn( anEurekaHttpResponse(200, new Applications()).type(MediaType.APPLICATION_JSON_TYPE).build() ); RedirectingEurekaHttpClient httpClient = new RedirectingEurekaHttpClient(SERVICE_URL, factory, dnsService); httpClient.getApplications(); verify(factory, times(1)).newClient(Matchers.<EurekaEndpoint>anyVararg()); verify(sourceClient, times(1)).getApplications(); }
public void setupRedirect() { when(factory.newClient(Matchers.<EurekaEndpoint>anyVararg())).thenReturn(sourceClient, redirectedClient); when(sourceClient.getApplications()).thenReturn( anEurekaHttpResponse(302, Applications.class) .headers(HttpHeaders.LOCATION, "http://another.discovery.test/eureka/v2/apps") .build() ); when(dnsService.resolveIp("another.discovery.test")).thenReturn("192.168.0.1"); when(redirectedClient.getApplications()).thenReturn( anEurekaHttpResponse(200, new Applications()).type(MediaType.APPLICATION_JSON_TYPE).build() ); }
@Test public void testNoValidDataFromRemoteServer() { Applications newApplications = new Applications(); for (Application application : applications.getRegisteredApplications()) { if (!application.getInstances().get(0).getVIPAddress().equals(vipAddress)) { newApplications.addApplication(application); } } when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, newApplications).build()); List<AwsEndpoint> endpoints = resolver.getClusterEndpoints(); assertThat(endpoints.isEmpty(), is(true)); verify(httpClient, times(1)).shutdown(); }
@Test public void testApplicationsHashAndVersion() { Applications applications = new Applications("appsHashCode", 1L, Collections.emptyList()); assertEquals(1L, (long)applications.getVersion()); assertEquals("appsHashCode", applications.getAppsHashCode()); }
@Override public Applications fetchRegistry(String[] includeRemoteRegions) { Applications toReturn = new Applications(); for (Application application : localRegionApps.getRegisteredApplications()) { toReturn.addApplication(application); } for (String region : includeRemoteRegions) { Applications applications = remoteRegionVsApps.get(region); if (null != applications) { for (Application application : applications.getRegisteredApplications()) { toReturn.addApplication(application); } } } return toReturn; }
@Test public void testVersionAndAppHash() { Applications apps = new Applications(); assertEquals(-1L, (long)apps.getVersion()); assertNull(apps.getAppsHashCode()); apps.setVersion(101L); apps.setAppsHashCode("UP_5_DOWN_6_"); assertEquals(101L, (long)apps.getVersion()); assertEquals("UP_5_DOWN_6_", apps.getAppsHashCode()); }