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");
}
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);
}
}
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());
});
}
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);
}
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);
}
Aggregations