Search in sources :

Example 11 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer in project titus-control-plane by Netflix.

the class DefaultLoadBalancerServiceTest method backfillsCurrentTargetsToStore.

@Test(timeout = 30_000)
public void backfillsCurrentTargetsToStore() {
    String jobId = UUID.randomUUID().toString();
    String associatedId = "lb-" + UUID.randomUUID().toString();
    String dissociatedId = "lb-" + UUID.randomUUID().toString();
    String removedId = "lb-" + UUID.randomUUID().toString();
    LoadBalancerConfiguration configuration = LoadBalancerTests.mockConfiguration(MIN_TIME_IN_QUEUE_MS);
    when(configuration.isTargetsToStoreBackfillEnabled()).thenReturn(true);
    when(configuration.getStoreBackfillConcurrencyLimit()).thenReturn(10);
    when(configuration.getStoreBackfillTimeoutMs()).thenReturn(5000L);
    // current load balancer state (targets)
    when(client.getLoadBalancer(associatedId)).thenReturn(Single.just(new LoadBalancer(associatedId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "2.2.2.2", "3.3.3.3"))));
    when(client.getLoadBalancer(dissociatedId)).thenReturn(Single.just(new LoadBalancer(dissociatedId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("4.4.4.4", "5.5.5.5", "6.6.6.6"))));
    when(client.getLoadBalancer(removedId)).thenReturn(Single.just(new LoadBalancer(removedId, LoadBalancer.State.REMOVED, Collections.emptySet())));
    // current load balancers we are managing
    loadBalancerStore.addOrUpdateLoadBalancer(new JobLoadBalancer(jobId, associatedId), JobLoadBalancer.State.ASSOCIATED).await();
    loadBalancerStore.addOrUpdateLoadBalancer(new JobLoadBalancer(jobId, dissociatedId), JobLoadBalancer.State.DISSOCIATED).await();
    loadBalancerStore.addOrUpdateLoadBalancer(new JobLoadBalancer(jobId, removedId), JobLoadBalancer.State.ASSOCIATED).await();
    DefaultLoadBalancerService service = new DefaultLoadBalancerService(runtime, configuration, client, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
    service.backfillTargetsToStore();
    assertThat(loadBalancerStore.getLoadBalancerTargets(associatedId).collectList().block()).containsExactlyInAnyOrder(new LoadBalancerTargetState(new LoadBalancerTarget(associatedId, "BACKFILLED", "1.1.1.1"), REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(associatedId, "BACKFILLED", "2.2.2.2"), REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(associatedId, "BACKFILLED", "3.3.3.3"), REGISTERED));
    assertThat(loadBalancerStore.getLoadBalancerTargets(dissociatedId).collectList().block()).containsExactlyInAnyOrder(new LoadBalancerTargetState(new LoadBalancerTarget(dissociatedId, "BACKFILLED", "4.4.4.4"), REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(dissociatedId, "BACKFILLED", "5.5.5.5"), REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(dissociatedId, "BACKFILLED", "6.6.6.6"), REGISTERED));
    assertThat(loadBalancerStore.getLoadBalancerTargets(removedId).collectList().block()).isEmpty();
}
Also used : JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Aggregations

LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)11 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)8 Test (org.junit.Test)8 LoadBalancerTarget (com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget)7 LoadBalancerTargetState (com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState)7 LoadBalancerConnector (com.netflix.titus.api.connector.cloud.LoadBalancerConnector)5 JobLoadBalancerState (com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState)5 Task (com.netflix.titus.api.jobmanager.model.job.Task)4 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)4 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 Completable (rx.Completable)4 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 LoadBalancerStore (com.netflix.titus.api.loadbalancer.store.LoadBalancerStore)3 InMemoryLoadBalancerStore (com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore)3 List (java.util.List)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 Before (org.junit.Before)3