use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent 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());
});
}
use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent 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);
}
use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent 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);
}
use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.
the class JobScenarioBuilder method expectArchivedTaskEvent.
public JobScenarioBuilder expectArchivedTaskEvent(int taskIdx, int resubmit) {
JobManagerEvent<?> event = autoAdvance(() -> jobEventsSubscriber.takeNextTaskEvent(taskIdx, resubmit));
assertThat(event).isNotNull();
assertThat(event).isInstanceOf(TaskUpdateEvent.class);
TaskUpdateEvent taskUpdateEvent = (TaskUpdateEvent) event;
assertThat(taskUpdateEvent.isArchived()).isTrue();
return this;
}
use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.
the class JobScenarioBuilder method expectTaskStateChangeEvent.
public JobScenarioBuilder expectTaskStateChangeEvent(int taskIdx, int resubmit, TaskState taskState, String reasonCode) {
TaskUpdateEvent event = expectTaskEvent(taskIdx, resubmit);
TaskStatus status = event.getCurrent().getStatus();
assertThat(status.getState()).isEqualTo(taskState);
assertThat(status.getReasonCode()).isEqualTo(reasonCode);
return this;
}
Aggregations