Search in sources :

Example 71 with InstanceInfo

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));
}
Also used : Response(javax.ws.rs.core.Response) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 72 with InstanceInfo

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");
    }
}
Also used : Response(javax.ws.rs.core.Response) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 73 with InstanceInfo

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;
}
Also used : EurekaConfigBasedInstanceInfoProvider(com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 74 with InstanceInfo

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();
            }
        }
    }
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 75 with InstanceInfo

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()));
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)192 Test (org.junit.Test)74 Application (com.netflix.discovery.shared.Application)35 Applications (com.netflix.discovery.shared.Applications)22 AmazonInfo (com.netflix.appinfo.AmazonInfo)21 ArrayList (java.util.ArrayList)19 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)11 Before (org.junit.Before)11 DiscoveryClient (com.netflix.discovery.DiscoveryClient)10 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)10 Lease (com.netflix.eureka.lease.Lease)9 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)7 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)6 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6