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));
}
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++;
}
}
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);
}
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);
}
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;
}
Aggregations