Search in sources :

Example 6 with ExtTestSubscriber

use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.

the class DefaultReconciliationFrameworkTest method testMultiEngineChangeActionWithInvalidEngineId.

@Test
public void testMultiEngineChangeActionWithInvalidEngineId() {
    EntityHolder root1 = EntityHolder.newRoot("myRoot1", "myEntity1");
    framework.newEngine(root1).subscribe();
    testScheduler.triggerActions();
    Observable<Void> multiChangeObservable = framework.changeReferenceModel(// Keep anonymous class instead of lambda for readability
    new MultiEngineChangeAction() {

        @Override
        public Observable<Map<String, List<ModelActionHolder>>> apply() {
            return Observable.error(new IllegalStateException("invocation not expected"));
        }
    }, // Keep anonymous class instead of lambda for readability
    (id, modelUpdates) -> new ChangeAction() {

        @Override
        public Observable<List<ModelActionHolder>> apply() {
            return Observable.error(new IllegalStateException("invocation not expected"));
        }
    }, "myRoot1", "badRootId");
    ExtTestSubscriber<Void> multiChangeSubscriber = new ExtTestSubscriber<>();
    multiChangeObservable.subscribe(multiChangeSubscriber);
    assertThat(multiChangeSubscriber.isError()).isTrue();
    assertThat(multiChangeSubscriber.getError().getMessage()).contains("badRootId");
}
Also used : ChangeAction(com.netflix.titus.common.framework.reconciler.ChangeAction) MultiEngineChangeAction(com.netflix.titus.common.framework.reconciler.MultiEngineChangeAction) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) MultiEngineChangeAction(com.netflix.titus.common.framework.reconciler.MultiEngineChangeAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Observable(rx.Observable) List(java.util.List) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) Test(org.junit.Test)

Example 7 with ExtTestSubscriber

use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.

the class ZookeeperMasterMonitorTest method testMonitorWorksForMultipleLeaderUpdates.

@Test(timeout = 30_000)
public void testMonitorWorksForMultipleLeaderUpdates() throws Exception {
    // Note we intentionally didn't set the initial value of master description because we'd like to make sure
    // that the monitor will work property even if it fails occasionally (in this case, it will fail to deserialize
    // the master description in the very beginning
    ExtTestSubscriber<MasterDescription> leaderSubscriber = new ExtTestSubscriber<>();
    masterMonitor.getLeaderObservable().filter(Objects::nonNull).subscribe(leaderSubscriber);
    for (int i = 0; i < 5; i++) {
        curator.setData().forPath(zkPaths.getLeaderAnnouncementPath(), ObjectMappers.defaultMapper().writeValueAsBytes(newMasterDescription(i)));
        // Try a few times, as we can get update for the same entity more than once.
        for (int j = 0; j < 3; j++) {
            MasterDescription newLeader = leaderSubscriber.takeNext(5, TimeUnit.SECONDS);
            if (newLeader != null && newLeader.getApiPort() == i) {
                return;
            }
        }
        fail("Did not received TitusMaster update for iteration " + i);
    }
}
Also used : MasterDescription(com.netflix.titus.api.supervisor.service.MasterDescription) ZookeeperTestUtils.newMasterDescription(com.netflix.titus.ext.zookeeper.ZookeeperTestUtils.newMasterDescription) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 8 with ExtTestSubscriber

use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.

the class LocalCacheQueryProcessorTest method testObserveJobsWithFieldsFiltering.

@Test
public void testObserveJobsWithFieldsFiltering() throws InterruptedException {
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 1));
    Job<?> job1 = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    ObserveJobsQuery query = ObserveJobsQuery.newBuilder().addJobFields("status").addTaskFields("taskContext").build();
    processor.observeJobs(query).subscribe(subscriber);
    // Snapshot
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobManagerEvent.snapshotMarker()));
    expectJobUpdateEvent(subscriber, j -> {
        assertThat(j.getId()).isEqualTo(job1.getId());
        assertThat(j.getStatus().getReasonMessage()).isEqualTo("<not_given>");
        assertThat(j.getJobDescriptor()).isEqualTo(JobDescriptor.getDefaultInstance());
    });
    expectTaskUpdateEvent(subscriber, t -> {
        assertThat(t.getId()).isEqualTo(task1.getId());
        assertThat(t.getStatus()).isEqualTo(TaskStatus.getDefaultInstance());
        assertThat(t.getTaskContextMap()).containsAllEntriesOf(task1.getTaskContext());
    });
    expectSnapshot(subscriber);
    // Updates after snapshot marker
    Pair<Job<?>, List<Task>> jobAndTasks2 = addToJobDataReplicator(newJobAndTasks("job2", 1));
    Job<?> job2 = jobAndTasks2.getLeft();
    Task task2 = jobAndTasks2.getRight().get(0);
    JobUpdateEvent jobUpdateEvent = JobUpdateEvent.newJob(job2, JUNIT_CALL_METADATA);
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job2, task2, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), jobUpdateEvent));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectJobUpdateEvent(subscriber, j -> {
        assertThat(j.getId()).isEqualTo(job2.getId());
        assertThat(j.getStatus().getReasonMessage()).isEqualTo("<not_given>");
        assertThat(j.getJobDescriptor()).isEqualTo(JobDescriptor.getDefaultInstance());
    });
    expectTaskUpdateEvent(subscriber, t -> {
        assertThat(t.getId()).isEqualTo(task2.getId());
        assertThat(t.getStatus()).isEqualTo(TaskStatus.getDefaultInstance());
        assertThat(t.getTaskContextMap()).containsAllEntriesOf(task2.getTaskContext());
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Test(org.junit.Test)

Example 9 with ExtTestSubscriber

use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.

the class LocalCacheQueryProcessorTest method testObserveJob.

@Test
public void testObserveJob() throws InterruptedException {
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    processor.observeJob("job1").subscribe(subscriber);
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 2));
    Job<?> job2 = addToJobDataReplicator(newJobAndTasks("job2", 2)).getLeft();
    Job<?> job1 = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    Task task2 = jobAndTasks.getRight().get(1);
    // Job update event, which also triggers snapshot
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobUpdateEvent.newJob(job2, JUNIT_CALL_METADATA)));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobUpdateEvent.newJob(job1, JUNIT_CALL_METADATA)));
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job1.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectSnapshot(subscriber);
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job1.getId()));
    // Task update event
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job1, task1, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Check that is correctly terminated
    jobDataReplicatorSink.tryEmitError(new RuntimeException("simulated stream error"));
    await().until(() -> subscriber.getError() != null);
    assertThat(subscriber.getError()).isInstanceOf(RuntimeException.class);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) Test(org.junit.Test)

Example 10 with ExtTestSubscriber

use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.

the class LocalCacheQueryProcessorTest method testObserveJobs.

@Test
public void testObserveJobs() throws InterruptedException {
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    processor.observeJobs(ObserveJobsQuery.getDefaultInstance()).subscribe(subscriber);
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 2));
    Job<?> job = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    Task task2 = jobAndTasks.getRight().get(1);
    // Job update event, which also triggers snapshot
    JobUpdateEvent jobUpdateEvent = JobUpdateEvent.newJob(job, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), jobUpdateEvent));
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectSnapshot(subscriber);
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job.getId()));
    // Task update event
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job, task1, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Job replicator re-sends events if there is nothing new to keep the stream active. Make sure that
    // we filter the keep alive events.
    TaskUpdateEvent taskUpdateEvent2 = TaskUpdateEvent.newTask(job, task2, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobManagerEvent.keepAliveEvent(-1)));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent2));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task2.getId()));
    // Now repeat taskUpdateEvent which this time should go through.
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Check that is correctly terminated
    jobDataReplicatorSink.tryEmitError(new RuntimeException("simulated stream error"));
    await().until(() -> subscriber.getError() != null);
    assertThat(subscriber.getError()).isInstanceOf(RuntimeException.class);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Test(org.junit.Test)

Aggregations

ExtTestSubscriber (com.netflix.titus.testkit.rx.ExtTestSubscriber)14 Test (org.junit.Test)11 List (java.util.List)8 Task (com.netflix.titus.api.jobmanager.model.job.Task)4 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)4 Job (com.netflix.titus.api.jobmanager.model.job.Job)3 TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)3 ChangeAction (com.netflix.titus.common.framework.reconciler.ChangeAction)3 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)3 MultiEngineChangeAction (com.netflix.titus.common.framework.reconciler.MultiEngineChangeAction)3 Observable (rx.Observable)3 JobUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent)2 ModelActionHolder (com.netflix.titus.common.framework.reconciler.ModelActionHolder)2 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)2 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)1 CapacityAttributes (com.netflix.titus.api.jobmanager.model.job.CapacityAttributes)1 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)1 MasterInstance (com.netflix.titus.api.supervisor.model.MasterInstance)1 MasterDescription (com.netflix.titus.api.supervisor.service.MasterDescription)1 ModelAction (com.netflix.titus.common.framework.reconciler.ModelAction)1