Search in sources :

Example 1 with InstanceInfoGenerator

use of com.netflix.discovery.util.InstanceInfoGenerator in project eureka by Netflix.

the class DiscoveryClientEventBusTest method testCacheRefreshEvent.

@Test
public void testCacheRefreshEvent() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    // Initial full fetch
    Applications initialApps = instanceGen.takeDelta(1);
    when(requestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    // Activates the client
    discoveryClientResource.getClient();
    // Delta update
    Applications delta = instanceGen.takeDelta(1);
    when(requestHandler.getDelta()).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(10, TimeUnit.SECONDS), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) Test(org.junit.Test)

Example 2 with InstanceInfoGenerator

use of com.netflix.discovery.util.InstanceInfoGenerator in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull.

@Test
public void testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    // Full fetch with one item
    InstanceInfo first = instanceGen.first();
    Applications initial = toApplications(first);
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_")));
    // Delta with one add
    InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo1").setStatus(InstanceStatus.DOWN).setDataCenterInfo(null).build();
    InstanceInfo third = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo2").setStatus(InstanceStatus.UP).setDataCenterInfo(new DataCenterInfo() {

        @Override
        public Name getName() {
            return null;
        }
    }).build();
    Applications delta = toApplications(second, third);
    delta.setAppsHashCode("DOWN_1_UP_2_");
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_2_")));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 3 with InstanceInfoGenerator

use of com.netflix.discovery.util.InstanceInfoGenerator in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testEurekaClientPeriodicCacheRefresh.

@Test
public void testEurekaClientPeriodicCacheRefresh() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(3, 1).build();
    Applications initialApps = instanceGen.takeDelta(1);
    // Full fetch
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(countInstances(client.getApplications()), is(equalTo(1)));
    // Delta 1
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.takeDelta(1)).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    // Delta 2
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.takeDelta(1)).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(countInstances(client.getApplications()), is(equalTo(3)));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) Test(org.junit.Test)

Example 4 with InstanceInfoGenerator

use of com.netflix.discovery.util.InstanceInfoGenerator 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 5 with InstanceInfoGenerator

use of com.netflix.discovery.util.InstanceInfoGenerator in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testAppsHashCodeAfterRefresh.

@Test
public void testAppsHashCodeAfterRefresh() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    // Full fetch with one item
    InstanceInfo first = instanceGen.first();
    Applications initial = toApplications(first);
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_")));
    // Delta with one add
    InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setStatus(InstanceStatus.DOWN).build();
    Applications delta = toApplications(second);
    delta.setAppsHashCode("DOWN_1_UP_1_");
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_1_")));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Aggregations

InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)8 InstanceInfo (com.netflix.appinfo.InstanceInfo)5 Applications (com.netflix.discovery.shared.Applications)5 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)5 Test (org.junit.Test)5 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)4 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)4 Before (org.junit.Before)3 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)1 EurekaAccept (com.netflix.appinfo.EurekaAccept)1 DiscoveryClientResource (com.netflix.discovery.junit.resource.DiscoveryClientResource)1 Application (com.netflix.discovery.shared.Application)1 Key (com.netflix.eureka.registry.Key)1 Response (javax.ws.rs.core.Response)1 Matchers.anyString (org.mockito.Matchers.anyString)1