Search in sources :

Example 1 with LoadBalancerTargetState

use of com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState in project titus-control-plane by Netflix.

the class CassandraLoadBalancerStoreTest method testAddTargets.

@Test(timeout = TIMEOUT_MS)
public void testAddTargets() throws Exception {
    Map<LoadBalancerTarget, LoadBalancerTarget.State> testData = generateTestData(10, 20, 1).getTargets();
    Map<String, List<LoadBalancerTargetState>> expectedTargetsByLoadBalancer = testData.entrySet().stream().map(entry -> new LoadBalancerTargetState(entry.getKey(), entry.getValue())).collect(Collectors.groupingBy(t -> t.getLoadBalancerTarget().getLoadBalancerId()));
    CassandraLoadBalancerStore store = getInitdStore();
    store.addOrUpdateTargets(testData.entrySet().stream().map(LoadBalancerTargetState::from).collect(Collectors.toList())).block();
    expectedTargetsByLoadBalancer.forEach((loadBalancerId, expectedTargets) -> assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsExactlyInAnyOrder(IterableUtil.toArray(expectedTargets)));
    int totalCount = expectedTargetsByLoadBalancer.values().stream().mapToInt(List::size).sum();
    Session session = cassandraCQLUnit.getSession();
    ResultSet resultSet = session.execute("SELECT COUNT(*) FROM load_balancer_targets;");
    assertThat(resultSet.one().getLong(0)).isEqualTo(totalCount);
}
Also used : ASSOCIATED(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer.State.ASSOCIATED) EntitySanitizer(com.netflix.titus.common.model.sanitizer.EntitySanitizer) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) Row(com.datastax.driver.core.Row) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CassandraCQLUnit(org.cassandraunit.CassandraCQLUnit) DISSOCIATED(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer.State.DISSOCIATED) HashSet(java.util.HashSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement) Pair(com.netflix.titus.common.util.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) Session(com.datastax.driver.core.Session) ClassPathCQLDataSet(org.cassandraunit.dataset.cql.ClassPathCQLDataSet) ExecutorService(java.util.concurrent.ExecutorService) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Logger(org.slf4j.Logger) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) LoadBalancerSanitizerBuilder(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerSanitizerBuilder) IterableUtil(org.assertj.core.util.IterableUtil) List(java.util.List) Rule(org.junit.Rule) Collections(java.util.Collections) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest) Mockito.mock(org.mockito.Mockito.mock) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) ResultSet(com.datastax.driver.core.ResultSet) List(java.util.List) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 2 with LoadBalancerTargetState

use of com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisterExtraTargetsPreviouslyRegisteredByUs.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisterExtraTargetsPreviouslyRegisteredByUs() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(3, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4", "5.5.5.5", "6.6.6.6"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// 3 running tasks were previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(1).getId(), "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(2).getId(), "3.3.3.3"), LoadBalancerTarget.State.REGISTERED), // Next two ips were previously registered by us, but their tasks do not exist anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "some-dead-task", "4.4.4.4"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "another-dead-task", "5.5.5.5"), LoadBalancerTarget.State.DEREGISTERED)).block();
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    subscriber.getOnNextEvents().forEach(update -> {
        assertThat(update.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
        assertThat(update.getPriority()).isEqualTo(Priority.LOW);
        assertThat(update.getLoadBalancerId()).isEqualTo(loadBalancerId);
        assertThat(update.getIdentifier().getTaskId()).isIn("some-dead-task", "another-dead-task");
        assertThat(update.getIdentifier().getIpAddress()).isIn("4.4.4.4", "5.5.5.5");
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) 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)

Example 3 with LoadBalancerTargetState

use of com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisteredTargetsAreCleanedUp.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisteredTargetsAreCleanedUp() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(1, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "10.10.10.10"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// running tasks was previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), // Next three ips were previously registered by us, but their tasks do not exist anymore and are not in the load balancer anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // no reconciliation ran yet
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(3);
    // first pass, the one stored as DEREGISTERED is cleaned up, the other in an inconsistent state is fixed
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(1);
    TargetStateBatchable inconsistencyFix = subscriber.getOnNextEvents().get(0);
    assertThat(inconsistencyFix.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(inconsistencyFix.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(inconsistencyFix.getIpAddress()).isEqualTo("2.2.2.2");
    List<LoadBalancerTargetState> storedTargets = store.getLoadBalancerTargets(loadBalancerId).collectList().block();
    assertThat(storedTargets).hasSize(2);
    assertThat(storedTargets).doesNotContain(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED));
    // update with fix not applied yet, keep trying
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    TargetStateBatchable update2 = subscriber.getOnNextEvents().get(0);
    assertThat(update2.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(update2.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(update2.getIpAddress()).isEqualTo("2.2.2.2");
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(2);
    // simulate the update with the fix above being applied
    store.addOrUpdateTargets(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // finally, corrected record is now cleaned up
    awaitReconciliationRuns(1);
    // no changes needed
    subscriber.assertNotCompleted().assertValueCount(2);
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsOnly(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED));
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) 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)

Example 4 with LoadBalancerTargetState

use of com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState in project titus-control-plane by Netflix.

the class DefaultLoadBalancerServiceTest method removeLoadBalancerDeregisterKnownTargets.

@Test
public void removeLoadBalancerDeregisterKnownTargets() {
    String jobId = UUID.randomUUID().toString();
    String loadBalancerId = "lb-" + UUID.randomUUID().toString();
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    defaultStubs();
    LoadBalancerTests.applyValidGetJobMock(v3JobOperations, jobId);
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(5, jobId);
    Collection<LoadBalancerTargetState> expectedTargets = tasks.stream().map(task -> new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, task.getId(), task.getTaskContext().get(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP)), // final state expected after updates are applied
    DEREGISTERED)).collect(Collectors.toList());
    when(v3JobOperations.getTasks(jobId)).thenReturn(CollectionsExt.merge(tasks, LoadBalancerTests.buildTasks(2, jobId, TaskState.StartInitiated), LoadBalancerTests.buildTasks(2, jobId, TaskState.KillInitiated), LoadBalancerTests.buildTasks(3, jobId, TaskState.Finished), LoadBalancerTests.buildTasks(1, jobId, TaskState.Disconnected)));
    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();
    assertTrue(loadBalancerStore.addOrUpdateLoadBalancer(jobLoadBalancer, JobLoadBalancer.State.ASSOCIATED).await(100, TimeUnit.MILLISECONDS));
    assertTrue(service.removeLoadBalancer(jobId, loadBalancerId).await(100, TimeUnit.MILLISECONDS));
    List<JobLoadBalancerState> jobLoadBalancers = loadBalancerStore.getAssociations().stream().filter(association -> jobId.equals(association.getJobId())).collect(Collectors.toList());
    assertThat(jobLoadBalancers).isNotEmpty();
    assertThat(jobLoadBalancers).hasSize(1);
    JobLoadBalancerState jobLoadBalancerState = jobLoadBalancers.iterator().next();
    assertEquals(loadBalancerId, jobLoadBalancerState.getLoadBalancerId());
    assertEquals(JobLoadBalancer.State.DISSOCIATED, jobLoadBalancerState.getState());
    assertFalse(service.getJobLoadBalancers(jobId).toBlocking().getIterator().hasNext());
    testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors().assertValueCount(1);
    assertThat(loadBalancerStore.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsExactlyInAnyOrderElementsOf(expectedTargets);
    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));
}
Also used : LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Single(rx.Single) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) DefaultLoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.DefaultLoadBalancerJobValidator) Schedulers(rx.schedulers.Schedulers) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) LoadBalancerStore(com.netflix.titus.api.loadbalancer.store.LoadBalancerStore) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerValidationConfiguration(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerValidationConfiguration) Collection(java.util.Collection) DEREGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.DEREGISTERED) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) Set(java.util.Set) UUID(java.util.UUID) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) Assert.assertFalse(org.junit.Assert.assertFalse) PublishSubject(rx.subjects.PublishSubject) Mockito.mock(org.mockito.Mockito.mock) Completable(rx.Completable) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) LoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerJobValidator) TestScheduler(rx.schedulers.TestScheduler) ArrayList(java.util.ArrayList) AssertableSubscriber(rx.observers.AssertableSubscriber) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) Batch(com.netflix.titus.common.util.rx.batch.Batch) Mockito.never(org.mockito.Mockito.never) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) REGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.REGISTERED) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Batch(com.netflix.titus.common.util.rx.batch.Batch) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) Test(org.junit.Test)

Example 5 with LoadBalancerTargetState

use of com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState in project titus-control-plane by Netflix.

the class DefaultLoadBalancerServiceTest method newTasksGetRegistered.

@Test
public void newTasksGetRegistered() {
    String jobId = UUID.randomUUID().toString();
    String taskId = UUID.randomUUID().toString();
    String loadBalancerId = "lb-" + UUID.randomUUID().toString();
    PublishSubject<JobManagerEvent<?>> taskEvents = PublishSubject.create();
    when(client.registerAll(any(), any())).thenReturn(Completable.complete());
    when(client.deregisterAll(any(), any())).thenReturn(Completable.complete());
    when(v3JobOperations.observeJobs()).thenReturn(taskEvents);
    when(v3JobOperations.getTasks(jobId)).thenReturn(Collections.emptyList());
    LoadBalancerTests.applyValidGetJobMock(v3JobOperations, jobId);
    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();
    assertTrue(service.addLoadBalancer(jobId, loadBalancerId).await(100, TimeUnit.MILLISECONDS));
    assertThat(service.getJobLoadBalancers(jobId).toBlocking().first()).isEqualTo(loadBalancerId);
    testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors().assertValueCount(0);
    verify(client, never()).registerAll(any(), any());
    verify(client, never()).deregisterAll(any(), any());
    verifyNoReconcilerIgnore();
    Task launched = ServiceJobTask.newBuilder().withJobId(jobId).withId(taskId).withStatus(TaskStatus.newBuilder().withState(TaskState.Launched).build()).build();
    Task startingWithIp = launched.toBuilder().withStatus(TaskStatus.newBuilder().withState(TaskState.StartInitiated).build()).withTaskContext(CollectionsExt.asMap(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4")).build();
    Task started = startingWithIp.toBuilder().withStatus(TaskStatus.newBuilder().withState(TaskState.Started).build()).build();
    LoadBalancerTargetState expectedTarget = new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, started.getId(), "1.2.3.4"), REGISTERED);
    // events with no state transition gets ignored
    taskEvents.onNext(TaskUpdateEvent.newTask(null, launched, callMetadata));
    testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors().assertValueCount(0);
    verify(client, never()).registerAll(any(), any());
    verify(client, never()).deregisterAll(any(), any());
    verifyNoReconcilerIgnore();
    // events to !Started states get ignored
    taskEvents.onNext(TaskUpdateEvent.taskChange(null, startingWithIp, launched, callMetadata));
    testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors().assertValueCount(0);
    verify(client, never()).registerAll(any(), any());
    verify(client, never()).deregisterAll(any(), any());
    verifyNoReconcilerIgnore();
    // finally detect the task is UP and gets registered
    taskEvents.onNext(TaskUpdateEvent.taskChange(null, started, startingWithIp, callMetadata));
    testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors().assertValueCount(1);
    assertThat(loadBalancerStore.getLoadBalancerTargets(loadBalancerId).collectList().block()).contains(expectedTarget);
    verify(client).registerAll(eq(loadBalancerId), argThat(set -> set.contains("1.2.3.4")));
    verify(client, never()).deregisterAll(eq(loadBalancerId), any());
    verifyReconcilerIgnore(loadBalancerId, "1.2.3.4");
}
Also used : LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Single(rx.Single) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) DefaultLoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.DefaultLoadBalancerJobValidator) Schedulers(rx.schedulers.Schedulers) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) LoadBalancerStore(com.netflix.titus.api.loadbalancer.store.LoadBalancerStore) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerValidationConfiguration(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerValidationConfiguration) Collection(java.util.Collection) DEREGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.DEREGISTERED) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) Set(java.util.Set) UUID(java.util.UUID) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) Assert.assertFalse(org.junit.Assert.assertFalse) PublishSubject(rx.subjects.PublishSubject) Mockito.mock(org.mockito.Mockito.mock) Completable(rx.Completable) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) LoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerJobValidator) TestScheduler(rx.schedulers.TestScheduler) ArrayList(java.util.ArrayList) AssertableSubscriber(rx.observers.AssertableSubscriber) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) Batch(com.netflix.titus.common.util.rx.batch.Batch) Mockito.never(org.mockito.Mockito.never) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) REGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.REGISTERED) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Batch(com.netflix.titus.common.util.rx.batch.Batch) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Aggregations

LoadBalancerTarget (com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget)13 LoadBalancerTargetState (com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState)13 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)12 Test (org.junit.Test)12 LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)11 JobLoadBalancerState (com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState)11 Task (com.netflix.titus.api.jobmanager.model.job.Task)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 Collectors (java.util.stream.Collectors)8 LoadBalancerConnector (com.netflix.titus.api.connector.cloud.LoadBalancerConnector)7 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)7 LoadBalancerStore (com.netflix.titus.api.loadbalancer.store.LoadBalancerStore)7 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)7 Set (java.util.Set)7 UUID (java.util.UUID)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.when (org.mockito.Mockito.when)7