use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.
the class ZookeeperMasterMonitorTest method testLocalMasterInstanceUpdates.
@Test(timeout = 30_000)
public void testLocalMasterInstanceUpdates() throws Exception {
// Should get dummy version first.
assertThat(masterMonitor.getCurrentMasterInstance()).isEqualTo(ZookeeperMasterMonitor.UNKNOWN_MASTER_INSTANCE);
ExtTestSubscriber<List<MasterInstance>> mastersSubscriber = new ExtTestSubscriber<>();
masterMonitor.observeMasters().subscribe(mastersSubscriber);
assertThat(mastersSubscriber.takeNext()).isEmpty();
// Update information about itself
MasterInstance initial = ZookeeperTestUtils.newMasterInstance("selfId", MasterState.Inactive);
assertThat(masterMonitor.updateOwnMasterInstance(initial).get()).isNull();
expectMasters(mastersSubscriber, initial);
// Change state
MasterInstance updated = MasterInstanceFunctions.moveTo(initial, MasterStatus.newBuilder().withState(MasterState.NonLeader).withMessage("testing").build());
assertThat(masterMonitor.updateOwnMasterInstance(updated).get()).isNull();
expectMasters(mastersSubscriber, updated);
// Now add second master
MasterInstance second = ZookeeperTestUtils.newMasterInstance("secondId", MasterState.Inactive);
addMasterInstanceToZookeeper(second);
expectMasters(mastersSubscriber, updated, second);
// And remove it
removeMasterInstanceFromZookeeper(second.getInstanceId());
expectMasters(mastersSubscriber, updated);
}
use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.
the class DefaultReconciliationFrameworkTest method testFailingMultiEngineChangeAction.
@Test
public void testFailingMultiEngineChangeAction() {
EntityHolder root1 = EntityHolder.newRoot("myRoot1", "myEntity1");
EntityHolder root2 = EntityHolder.newRoot("myRoot2", "myEntity2");
framework.newEngine(root1).subscribe();
framework.newEngine(root2).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 RuntimeException("simulated error"));
}
}, // Keep anonymous class instead of lambda for readability
(id, modelUpdates) -> new ChangeAction() {
@Override
public Observable<List<ModelActionHolder>> apply() {
return modelUpdates;
}
}, "myRoot1", "myRoot2");
ExtTestSubscriber<Void> multiChangeSubscriber = new ExtTestSubscriber<>();
multiChangeObservable.subscribe(multiChangeSubscriber);
assertThat(multiChangeSubscriber.isError()).isTrue();
String errorMessage = ExceptionExt.toMessageChain(multiChangeSubscriber.getError());
assertThat(errorMessage).contains("simulated error");
}
use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.
the class DefaultReconciliationFrameworkTest method testMultiEngineChangeAction.
@Test
public void testMultiEngineChangeAction() {
EntityHolder root1 = EntityHolder.newRoot("myRoot1", "myEntity1");
EntityHolder root2 = EntityHolder.newRoot("myRoot2", "myEntity2");
framework.newEngine(root1).subscribe();
framework.newEngine(root2).subscribe();
testScheduler.triggerActions();
MultiEngineChangeAction multiEngineChangeAction = () -> Observable.just(ImmutableMap.of("myRoot1", ModelActionHolder.allModels(new SimpleModelUpdateAction(EntityHolder.newRoot("myRoot1", "myEntity1#v2"), true)), "myRoot2", ModelActionHolder.allModels(new SimpleModelUpdateAction(EntityHolder.newRoot("myRoot2", "myEntity2#v2"), true))));
Map<String, List<ModelActionHolder>> holders = new HashMap<>();
Observable<Void> multiChangeObservable = framework.changeReferenceModel(multiEngineChangeAction, (id, modelUpdates) -> {
ChangeAction changeAction = () -> modelUpdates.doOnNext(next -> holders.put(id, next));
return changeAction;
}, "myRoot1", "myRoot2");
verify(engine1, times(0)).changeReferenceModel(any());
verify(engine2, times(0)).changeReferenceModel(any());
ExtTestSubscriber<Void> multiChangeSubscriber = new ExtTestSubscriber<>();
multiChangeObservable.subscribe(multiChangeSubscriber);
assertThat(multiChangeSubscriber.isUnsubscribed()).isTrue();
verify(engine1, times(1)).changeReferenceModel(any());
verify(engine2, times(1)).changeReferenceModel(any());
// one action per view (Running, Store, Reference)
assertThat(holders.get("myRoot1")).hasSize(3);
SimpleModelUpdateAction modelAction1 = (SimpleModelUpdateAction) holders.get("myRoot1").get(0).getAction();
assertThat((String) modelAction1.getEntityHolder().getEntity()).isEqualTo("myEntity1#v2");
// one action per view (Running, Store, Reference)
assertThat(holders.get("myRoot2")).hasSize(3);
SimpleModelUpdateAction modelAction2 = (SimpleModelUpdateAction) holders.get("myRoot2").get(0).getAction();
assertThat((String) modelAction2.getEntityHolder().getEntity()).isEqualTo("myEntity2#v2");
}
use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.
the class LocalCacheQueryProcessorTest method testObserveJobsEmitsEmptySnapshotIfNoJobsAreRunning.
@Test
public void testObserveJobsEmitsEmptySnapshotIfNoJobsAreRunning() throws InterruptedException {
ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
processor.observeJobs(ObserveJobsQuery.getDefaultInstance()).subscribe(subscriber);
emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobManagerEvent.snapshotMarker()));
JobChangeNotification receivedEvent = subscriber.takeNext(30, TimeUnit.SECONDS);
assertThat(receivedEvent.getNotificationCase()).isEqualTo(JobChangeNotification.NotificationCase.SNAPSHOTEND);
}
use of com.netflix.titus.testkit.rx.ExtTestSubscriber in project titus-control-plane by Netflix.
the class ComputationTaskInvokerTest method testFailingComputations.
@Test
public void testFailingComputations() throws Exception {
AtomicBoolean flag = new AtomicBoolean();
ComputationTaskInvoker<String> slowInvoker = new ComputationTaskInvoker<>(Observable.create(subscriber -> {
if (flag.getAndSet(true)) {
subscriber.onNext("OK!");
subscriber.onCompleted();
} else {
Observable.<String>timer(1, TimeUnit.SECONDS, testScheduler).flatMap(tick -> Observable.<String>error(new RuntimeException("simulated computation error"))).subscribe(subscriber);
}
}), testScheduler);
ExtTestSubscriber<String> failingSubscriber = new ExtTestSubscriber<>();
slowInvoker.recompute().subscribe(failingSubscriber);
testScheduler.triggerActions();
ExtTestSubscriber<String> okSubscriber = new ExtTestSubscriber<>();
slowInvoker.recompute().subscribe(okSubscriber);
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
failingSubscriber.assertOnError();
assertThat(okSubscriber.takeNext()).isEqualTo("OK!");
okSubscriber.assertOnCompleted();
}
Aggregations