use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class DefaultLoadBalancerServiceTest method removeSkipLoadBalancerOperationsOnErrors.
@Test
public void removeSkipLoadBalancerOperationsOnErrors() {
String firstJobId = UUID.randomUUID().toString();
String secondJobId = UUID.randomUUID().toString();
String loadBalancerId = "lb-" + UUID.randomUUID().toString();
JobLoadBalancer firstLoadBalancer = new JobLoadBalancer(firstJobId, loadBalancerId);
JobLoadBalancer secondLoadBalancer = new JobLoadBalancer(secondJobId, loadBalancerId);
defaultStubs();
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, firstJobId);
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, secondJobId);
when(v3JobOperations.getTasks(firstJobId)).thenThrow(new RuntimeException());
List<Task> tasks = LoadBalancerTests.buildTasksStarted(5, secondJobId);
when(v3JobOperations.getTasks(secondJobId)).thenReturn(tasks);
assertTrue(loadBalancerStore.addOrUpdateLoadBalancer(firstLoadBalancer, JobLoadBalancer.State.ASSOCIATED).await(100, TimeUnit.MILLISECONDS));
assertTrue(loadBalancerStore.addOrUpdateLoadBalancer(secondLoadBalancer, JobLoadBalancer.State.ASSOCIATED).await(100, TimeUnit.MILLISECONDS));
LoadBalancerConfiguration configuration = LoadBalancerTests.mockConfiguration(MIN_TIME_IN_QUEUE_MS);
DefaultLoadBalancerService service = new DefaultLoadBalancerService(runtime, configuration, client, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
AssertableSubscriber<Batch<TargetStateBatchable, String>> testSubscriber = service.events().test();
// first fails
assertTrue(service.removeLoadBalancer(firstJobId, loadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertFalse(service.getJobLoadBalancers(firstJobId).toBlocking().getIterator().hasNext());
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(0);
verify(client, never()).deregisterAll(any(), any());
verify(client, never()).registerAll(any(), any());
verifyNoReconcilerIgnore();
// second succeeds
assertTrue(service.removeLoadBalancer(secondJobId, loadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertFalse(service.getJobLoadBalancers(firstJobId).toBlocking().getIterator().hasNext());
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(1);
verify(client, never()).registerAll(eq(loadBalancerId), any());
verify(client).deregisterAll(eq(loadBalancerId), argThat(targets -> targets != null && targets.size() == tasks.size()));
verifyReconcilerIgnore(loadBalancerId, LoadBalancerTests.ipAddresses(tasks));
}
Aggregations