Search in sources :

Example 86 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project riposte by Nike-Inc.

the class EurekaVipAddressRoundRobinServiceTest method getActiveInstanceInfoForVipAddress_uses_provided_executor_for_future_if_provided_one.

@Test
public void getActiveInstanceInfoForVipAddress_uses_provided_executor_for_future_if_provided_one() {
    // given
    InstanceInfo iiMock = mock(InstanceInfo.class);
    doReturn(Optional.of(iiMock)).when(serviceSpy).getActiveInstanceInfoForVipAddressBlocking(vip);
    Executor executorSpy = spy(new SpyableExecutor());
    // when
    CompletableFuture<Optional<InstanceInfo>> result = serviceSpy.getActiveInstanceInfoForVipAddress(vip, Optional.of(executorSpy));
    // then
    assertThat(result.join()).isEqualTo(Optional.of(iiMock));
    verify(executorSpy).execute(any(Runnable.class));
}
Also used : Executor(java.util.concurrent.Executor) Optional(java.util.Optional) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 87 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project riposte by Nike-Inc.

the class EurekaVipAddressRoundRobinServiceTest method getActiveInstanceInfoForVipAddressBlocking_uses_round_robin_strategy_per_vip.

@Test
public void getActiveInstanceInfoForVipAddressBlocking_uses_round_robin_strategy_per_vip() {
    // given
    String vip1 = UUID.randomUUID().toString();
    String vip2 = UUID.randomUUID().toString();
    int vip1Counter = 0;
    int vip2Counter = 0;
    int numVip1Instances = 3;
    int numVip2Instances = 5;
    List<InstanceInfo> vip1Instances = generateListWithMockInstanceInfos(numVip1Instances);
    List<InstanceInfo> vip2Instances = generateListWithMockInstanceInfos(numVip2Instances);
    doReturn(vip1Instances).when(discoveryClientMock).getInstancesByVipAddress(vip1, false);
    doReturn(vip2Instances).when(discoveryClientMock).getInstancesByVipAddress(vip2, false);
    for (int i = 0; i < 1000; i++) {
        // when
        InstanceInfo v1Instance = serviceSpy.getActiveInstanceInfoForVipAddressBlocking(vip1).get();
        InstanceInfo v2Instance = serviceSpy.getActiveInstanceInfoForVipAddressBlocking(vip2).get();
        // then
        int expectedV1Index = vip1Counter % numVip1Instances;
        int expectedV2Index = vip2Counter % numVip2Instances;
        assertThat(v1Instance).isEqualTo(vip1Instances.get(expectedV1Index));
        assertThat(v2Instance).isEqualTo(vip2Instances.get(expectedV2Index));
        vip1Counter++;
        vip2Counter++;
    }
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 88 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project riposte by Nike-Inc.

the class EurekaVipAddressRoundRobinServiceTest method getActiveInstanceInfosForVipAddress_returns_future_that_returns_data_from_getActiveInstanceInfosForVipAddressBlocking.

@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void getActiveInstanceInfosForVipAddress_returns_future_that_returns_data_from_getActiveInstanceInfosForVipAddressBlocking(boolean useExecutor) {
    // given
    InstanceInfo iiMock = mock(InstanceInfo.class);
    List<InstanceInfo> expectedInstances = Collections.singletonList(iiMock);
    doReturn(expectedInstances).when(serviceSpy).getActiveInstanceInfosForVipAddressBlocking(vip);
    Optional<Executor> executorOpt = useExecutor ? Optional.of(Executors.newSingleThreadExecutor()) : Optional.empty();
    // when
    CompletableFuture<List<InstanceInfo>> result = serviceSpy.getActiveInstanceInfosForVipAddress(vip, executorOpt);
    // then
    assertThat(result.join()).isEqualTo(expectedInstances);
}
Also used : Executor(java.util.concurrent.Executor) ArrayList(java.util.ArrayList) List(java.util.List) InstanceInfo(com.netflix.appinfo.InstanceInfo) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 89 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project riposte by Nike-Inc.

the class EurekaVipAddressRoundRobinServiceTest method getActiveInstanceInfosForVipAddressBlocking_retrieves_active_InstanceInfos_by_vip_from_discovery_client.

@Test
public void getActiveInstanceInfosForVipAddressBlocking_retrieves_active_InstanceInfos_by_vip_from_discovery_client() {
    // given
    InstanceInfo active1 = mock(InstanceInfo.class);
    InstanceInfo active2 = mock(InstanceInfo.class);
    InstanceInfo down = mock(InstanceInfo.class);
    InstanceInfo outOfService = mock(InstanceInfo.class);
    InstanceInfo starting = mock(InstanceInfo.class);
    InstanceInfo unknown = mock(InstanceInfo.class);
    doReturn(InstanceInfo.InstanceStatus.UP).when(active1).getStatus();
    doReturn(InstanceInfo.InstanceStatus.UP).when(active2).getStatus();
    doReturn(InstanceInfo.InstanceStatus.DOWN).when(down).getStatus();
    doReturn(InstanceInfo.InstanceStatus.OUT_OF_SERVICE).when(outOfService).getStatus();
    doReturn(InstanceInfo.InstanceStatus.STARTING).when(starting).getStatus();
    doReturn(InstanceInfo.InstanceStatus.UNKNOWN).when(unknown).getStatus();
    List<InstanceInfo> allInstancesForVip = Arrays.asList(active1, down, outOfService, active2, starting, unknown);
    doReturn(allInstancesForVip).when(discoveryClientMock).getInstancesByVipAddress(vip, false);
    // when
    List<InstanceInfo> result = serviceSpy.getActiveInstanceInfosForVipAddressBlocking(vip);
    // then
    List<InstanceInfo> expected = Arrays.asList(active1, active2);
    assertThat(result).isEqualTo(expected);
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 90 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project riposte by Nike-Inc.

the class EurekaVipAddressRoundRobinServiceTest method generateListWithMockInstanceInfos.

private List<InstanceInfo> generateListWithMockInstanceInfos(int numInstanceInfos) {
    List<InstanceInfo> instanceInfos = new ArrayList<>();
    for (int i = 0; i < numInstanceInfos; i++) {
        InstanceInfo iiMock = mock(InstanceInfo.class);
        doReturn(InstanceInfo.InstanceStatus.UP).when(iiMock).getStatus();
        instanceInfos.add(iiMock);
    }
    return instanceInfos;
}
Also used : ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

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