Search in sources :

Example 61 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.

the class AwsInstanceRegistryTest method testOverridesWithAsgEnabledThenDisabled.

@Test
public void testOverridesWithAsgEnabledThenDisabled() {
    // Regular registration first
    InstanceInfo myInstance = createLocalUpInstanceWithAsg(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registerInstanceLocally(myInstance);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
    // Now we disable the ASG and we should expect OUT_OF_SERVICE status.
    ((AwsInstanceRegistry) registry).getAwsAsgUtil().setStatus(myInstance.getASGName(), false);
    myInstance = createLocalUpInstanceWithAsg(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registerInstanceLocally(myInstance);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
    // Now we re-enable the ASG and we should expect UP status.
    ((AwsInstanceRegistry) registry).getAwsAsgUtil().setStatus(myInstance.getASGName(), true);
    myInstance = createLocalUpInstanceWithAsg(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registerInstanceLocally(myInstance);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 62 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.

the class InstanceRegistryTest method testStatusOverrideWithExistingLeaseOutOfService.

@Test
public void testStatusOverrideWithExistingLeaseOutOfService() throws Exception {
    // Without an override we expect to get the existing OUT_OF_SERVICE lease when we re-register with UP.
    // First, we are "out of service".
    InstanceInfo myInstance = createLocalOutOfServiceInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registerInstanceLocally(myInstance);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
    // Then, we re-register with "UP".
    InstanceInfo sameInstance = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registry.register(sameInstance, 10000000, false);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
    // Let's try again. We shouldn't see a difference.
    sameInstance = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registry.register(sameInstance, 10000000, false);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 63 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.

the class InstanceRegistryTest method testStatusOverrideSetAndRemoval.

@Test
public void testStatusOverrideSetAndRemoval() throws Exception {
    // Regular registration first
    InstanceInfo myInstance = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    registerInstanceLocally(myInstance);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
    // Override status
    boolean statusResult = registry.statusUpdate(LOCAL_REGION_APP_NAME, myInstance.getId(), InstanceStatus.OUT_OF_SERVICE, "0", false);
    assertThat("Couldn't override instance status", statusResult, is(true));
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
    // Register again with status UP (this is what health check is doing)
    registry.register(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME), 10000000, false);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
    // Now remove override
    statusResult = registry.deleteStatusOverride(LOCAL_REGION_APP_NAME, myInstance.getId(), InstanceStatus.DOWN, "0", false);
    assertThat("Couldn't remove status override", statusResult, is(true));
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.DOWN);
    // Register again with status UP (this is what health check is doing)
    registry.register(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME), 10000000, false);
    verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 64 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.

the class AbstractVIPResourceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(6, 1).build();
    testApplication = instanceInfos.toApplications().getRegisteredApplications().get(0);
    resource = new AbstractVIPResource(serverContext) {

        @Override
        protected Response getVipResponse(String version, String entityName, String acceptHeader, EurekaAccept eurekaAccept, Key.EntityType entityType) {
            return super.getVipResponse(version, entityName, acceptHeader, eurekaAccept, entityType);
        }
    };
    vipName = testApplication.getName() + "#VIP";
    for (InstanceInfo instanceInfo : testApplication.getInstances()) {
        InstanceInfo changed = new InstanceInfo.Builder(instanceInfo).setASGName(// null asgName to get around AwsAsgUtil check
        null).setVIPAddress(// use the same vip address for all the instances in this test
        vipName).build();
        registry.register(changed, false);
    }
}
Also used : Response(javax.ws.rs.core.Response) EurekaAccept(com.netflix.appinfo.EurekaAccept) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) InstanceInfo(com.netflix.appinfo.InstanceInfo) Key(com.netflix.eureka.registry.Key) Before(org.junit.Before)

Example 65 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.

the class AbstractVIPResourceTest method testMiniVipGet.

@Test
public void testMiniVipGet() throws Exception {
    Response response = resource.getVipResponse(Version.V2.name(), vipName, MediaType.APPLICATION_JSON, EurekaAccept.compact, Key.EntityType.VIP);
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Applications decodedApps = decoder.decode(json, Applications.class);
    Application decodedApp = decodedApps.getRegisteredApplications(testApplication.getName());
    // 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));
    }
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) 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