use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ApplicationResourceTest method testBadRegistration.
@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));
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ApplicationResourceTest method testBadRegistrationOfDataCenterInfo.
@Test
public void testBadRegistrationOfDataCenterInfo() throws Exception {
try {
// test 400 when configured to return client error
ConfigurationManager.getConfigInstance().setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "true");
InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
when(instanceInfo.getDataCenterInfo()).thenReturn(new TestDataCenterInfo());
Response response = applicationResource.addInstance(instanceInfo, false + "");
assertThat(response.getStatus(), is(400));
// test backfill of data for AmazonInfo
ConfigurationManager.getConfigInstance().setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "false");
instanceInfo = spy(InstanceInfoGenerator.takeOne());
assertThat(instanceInfo.getDataCenterInfo(), instanceOf(AmazonInfo.class));
// clear the Id
((AmazonInfo) instanceInfo.getDataCenterInfo()).getMetadata().remove(AmazonInfo.MetaDataKey.instanceId.getName());
response = applicationResource.addInstance(instanceInfo, false + "");
assertThat(response.getStatus(), is(204));
} finally {
ConfigurationManager.getConfigInstance().clearProperty("eureka.experimental.registration.validation.dataCenterInfoId");
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ExampleEurekaService method initializeApplicationInfoManager.
private static synchronized ApplicationInfoManager initializeApplicationInfoManager(EurekaInstanceConfig instanceConfig) {
if (applicationInfoManager == null) {
InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
}
return applicationInfoManager;
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ExampleServiceBase method waitForRegistrationWithEureka.
private void waitForRegistrationWithEureka(EurekaClient eurekaClient) {
// my vip address to listen on
String vipAddress = configInstance.getStringProperty("eureka.vipAddress", "sampleservice.mydomain.net").get();
InstanceInfo nextServerInfo = null;
while (nextServerInfo == null) {
try {
nextServerInfo = eurekaClient.getNextServerFromEureka(vipAddress, false);
} catch (Throwable e) {
System.out.println("Waiting ... verifying service registration with eureka ...");
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class JerseyReplicationClientTest method testHeartbeatReplicationWithResponseBody.
@Test
public void testHeartbeatReplicationWithResponseBody() throws Exception {
InstanceInfo remoteInfo = new InstanceInfo(this.instanceInfo);
remoteInfo.setStatus(InstanceStatus.DOWN);
byte[] responseBody = toGzippedJson(remoteInfo);
serverMockClient.when(request().withMethod("PUT").withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true")).withPath("/eureka/v2/apps/" + this.instanceInfo.getAppName() + '/' + this.instanceInfo.getId())).respond(response().withStatusCode(Status.CONFLICT.getStatusCode()).withHeader(header("Content-Type", MediaType.APPLICATION_JSON)).withHeader(header("Content-Encoding", "gzip")).withBody(responseBody));
EurekaHttpResponse<InstanceInfo> response = replicationClient.sendHeartBeat(this.instanceInfo.getAppName(), this.instanceInfo.getId(), this.instanceInfo, null);
assertThat(response.getStatusCode(), is(equalTo(Status.CONFLICT.getStatusCode())));
assertThat(response.getEntity(), is(notNullValue()));
}
Aggregations