@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InstanceInfo other = (InstanceInfo) obj; if (getId() == null) { if (other.getId() != null) return false; } else if (!getId().equals(other.getId())) return false; return true; }
public static ReplicationInstance newReplicationInstanceOf(Action action, InstanceInfo instance) { switch (action) { case Register: return new ReplicationInstance( instance.getAppName(), instance.getId(), System.currentTimeMillis(), null, instance.getStatus().name(), instance, action); case Cancel: return new ReplicationInstance( instance.getAppName(), instance.getId(), System.currentTimeMillis(), null, null, null, action); case Heartbeat: return new ReplicationInstance( instance.getAppName(), instance.getId(), System.currentTimeMillis(), InstanceStatus.OUT_OF_SERVICE.name(), instance.getStatus().name(), instance, action); case StatusUpdate: return new ReplicationInstance( instance.getAppName(), instance.getId(), System.currentTimeMillis(), InstanceStatus.OUT_OF_SERVICE.name(), null, null, action); case DeleteStatusOverride: return new ReplicationInstance( instance.getAppName(), instance.getId(), System.currentTimeMillis(), InstanceStatus.OUT_OF_SERVICE.name(), null, null, action); } throw new IllegalStateException("Unexpected action " + action); }
private String fetchFortuneServiceUrl() { InstanceInfo instance = discoveryClient.getNextServerFromEureka("FORTUNE-SERVICE", false); logger.debug("instanceID: {}", instance.getId()); String fortuneServiceUrl = instance.getHomePageUrl(); logger.debug("fortune service url: {}", fortuneServiceUrl); return fortuneServiceUrl; }
@Test public void testMiniAppGet() throws Exception { Response response = applicationResource.getApplication( Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.compact.name()); String json = String.valueOf(response.getEntity()); DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class); Application decodedApp = decoder.decode(json, Application.class); // assert false as one is mini, so should NOT equal assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false)); for (InstanceInfo instanceInfo : testApplication.getInstances()) { InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId()); assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true)); } }
@Test public void testBadRegistration() throws Exception { InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getId()).thenReturn(null); Response response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getHostName()).thenReturn(null); response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getAppName()).thenReturn(""); response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getAppName()).thenReturn(applicationResource.getName() + "extraExtra"); response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getDataCenterInfo()).thenReturn(null); response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getDataCenterInfo()) .thenReturn( new DataCenterInfo() { @Override public Name getName() { return null; } }); response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); }
public void y() { InstanceInfo info = InstanceInfo.Builder.newBuilder() .setStatus(InstanceStatus.UP) .setAppName("testopenam") .setHostName("localhost") .setPort(8080) .setVIPAddress("testopenam") // .setMetadata(new HashMap() {{put("instanceId", "openam1");}}) .setDataCenterInfo(new InstanceIdDataCenterInfo("openam1")) .setHomePageUrl( "/OpenAM-12.0.0/isAlive.jsp", "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp") .setStatusPageUrl( "/OpenAM-12.0.0/isAlive.jsp", "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp") .setHealthCheckUrls( "/OpenAM-12.0.0/isAlive.jsp", "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp", null) .build(); info.getId(); PeerAwareInstanceRegistry.getInstance().register(info, false); }