Search in sources :

Example 1 with ExtTestSubscriber

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);
}
Also used : ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) List(java.util.List) SupervisorGrpcModelConverters.toCoreMasterInstance(com.netflix.titus.master.supervisor.endpoint.grpc.SupervisorGrpcModelConverters.toCoreMasterInstance) MasterInstance(com.netflix.titus.api.supervisor.model.MasterInstance) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 2 with ExtTestSubscriber

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");
}
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 3 with ExtTestSubscriber

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");
}
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) HashMap(java.util.HashMap) MultiEngineChangeAction(com.netflix.titus.common.framework.reconciler.MultiEngineChangeAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) List(java.util.List) Test(org.junit.Test)

Example 4 with ExtTestSubscriber

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);
}
Also used : ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Test(org.junit.Test)

Example 5 with ExtTestSubscriber

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();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Schedulers(rx.schedulers.Schedulers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) TestScheduler(rx.schedulers.TestScheduler) Observable(rx.Observable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) 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