Search in sources :

Example 1 with TitusRxSubscriber

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

the class EurekaContainerHealthServiceTest method testBadSubscriberIsolation.

@Test
public void testBadSubscriberIsolation() {
    jobManagerStub.moveTaskToState(taskId1, TaskState.Started);
    eurekaServer.register(newInstanceInfo(taskId1, InstanceStatus.UP));
    // First event / one subscriber
    TitusRxSubscriber<ContainerHealthEvent> subscriber1 = new TitusRxSubscriber<>();
    healthService.events(false).subscribe(subscriber1);
    eurekaServer.triggerCacheRefreshUpdate();
    // Add bad subscriber
    Disposable subscription2 = healthService.events(false).subscribe(next -> {
        throw new RuntimeException("simulated error");
    }, e -> {
        throw new RuntimeException("simulated error");
    }, () -> {
        throw new RuntimeException("simulated error");
    });
    // Event 2
    registerAndRefresh(InstanceStatus.DOWN);
    assertThat(subscription2.isDisposed()).isTrue();
    // Event 3
    registerAndRefresh(InstanceStatus.UP);
    assertThat(subscriber1.isDisposed()).isFalse();
    assertThat(subscriber1.getAllItems()).hasSize(3);
}
Also used : Disposable(reactor.core.Disposable) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) ContainerHealthAsserts.assertContainerHealthEvent(com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent) ContainerHealthEvent(com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent) Test(org.junit.Test)

Example 2 with TitusRxSubscriber

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

the class DefaultOneOffReconcilerTest method testReconcilerCloseWithRunningReconciliationAction.

@Test(timeout = 30_000)
public void testReconcilerCloseWithRunningReconciliationAction() throws InterruptedException {
    // Start reconciliation action first
    CountDownLatch ready = new CountDownLatch(1);
    AtomicBoolean cancelled = new AtomicBoolean();
    Mono<Function<String, String>> action = Mono.<Function<String, String>>never().doOnSubscribe(s -> ready.countDown()).doOnCancel(() -> cancelled.set(true));
    newReconciler(current -> Collections.singletonList(action));
    ready.await();
    TitusRxSubscriber<String> subscriber = new TitusRxSubscriber<>();
    reconciler.apply(c -> Mono.never()).subscribe(subscriber);
    assertThat(subscriber.isOpen()).isTrue();
    reconciler.close().subscribe();
    await().until(() -> cancelled.get() && !subscriber.isOpen());
    assertThat(subscriber.getError().getMessage()).isEqualTo("cancelled");
    await().until(() -> !changesSubscriber.isOpen());
}
Also used : ReconcilerActionProviderPolicy(com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProviderPolicy) Arrays(java.util.Arrays) Disposable(reactor.core.Disposable) Awaitility.await(com.jayway.awaitility.Awaitility.await) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReconcilerActionProvider(com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProvider) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) Function(java.util.function.Function) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) Duration(java.time.Duration) After(org.junit.After) Schedulers(reactor.core.scheduler.Schedulers) ActionProviderSelectorFactory(com.netflix.titus.common.framework.simplereconciler.internal.provider.ActionProviderSelectorFactory) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Evaluators(com.netflix.titus.common.util.Evaluators) Collections(java.util.Collections) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with TitusRxSubscriber

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

the class AggregatingContainerHealthServiceTest method testBadSubscriberIsIsolated.

@Test
public void testBadSubscriberIsIsolated() {
    // First event / one subscriber
    TitusRxSubscriber<ContainerHealthEvent> goodSubscriber = new TitusRxSubscriber<>();
    healthService.events(false).subscribe(goodSubscriber);
    // Add bad subscriber
    Disposable badSubscriber = healthService.events(false).subscribe(next -> {
        throw new RuntimeException("simulated error");
    }, e -> {
        throw new RuntimeException("simulated error");
    }, () -> {
        throw new RuntimeException("simulated error");
    });
    downstream1.makeHealthy(taskId1);
    assertThat(goodSubscriber.isOpen()).isTrue();
    assertThat(badSubscriber.isDisposed()).isTrue();
}
Also used : Disposable(reactor.core.Disposable) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) ContainerHealthAsserts.assertContainerHealthEvent(com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent) ContainerHealthEvent(com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent) Test(org.junit.Test)

Example 4 with TitusRxSubscriber

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

the class DefaultManyReconcilerTest method testReconcilerCloseWithRunningReconciliationAction.

@Test
public void testReconcilerCloseWithRunningReconciliationAction() throws InterruptedException {
    // Start reconciliation action first
    CountDownLatch ready = new CountDownLatch(1);
    AtomicBoolean cancelled = new AtomicBoolean();
    Mono<Function<String, String>> action = Mono.<Function<String, String>>never().doOnSubscribe(s -> ready.countDown()).doOnCancel(() -> cancelled.set(true));
    newReconcilerWithRegistrations(current -> Collections.singletonList(action), "r1", "a");
    ready.await();
    TitusRxSubscriber<String> subscriber = new TitusRxSubscriber<>();
    reconciler.apply("r1", c -> Mono.never()).subscribe(subscriber);
    assertThat(subscriber.isOpen()).isTrue();
    reconciler.close().subscribe();
    await().until(() -> cancelled.get() && !subscriber.isOpen());
    assertThat(subscriber.getError().getMessage()).isEqualTo("cancelled");
    await().until(() -> !changesSubscriber.isOpen());
}
Also used : ReconcilerActionProviderPolicy(com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProviderPolicy) Arrays(java.util.Arrays) Disposable(reactor.core.Disposable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReconcilerActionProvider(com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProvider) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) CloseableReference(com.netflix.titus.common.util.closeable.CloseableReference) Duration(java.time.Duration) After(org.junit.After) IndexSetHolderBasic(com.netflix.titus.common.util.collections.index.IndexSetHolderBasic) Schedulers(reactor.core.scheduler.Schedulers) ActionProviderSelectorFactory(com.netflix.titus.common.framework.simplereconciler.internal.provider.ActionProviderSelectorFactory) Awaitility.await(com.jayway.awaitility.Awaitility.await) Indexes(com.netflix.titus.common.util.collections.index.Indexes) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) SimpleReconcilerEvent(com.netflix.titus.common.framework.simplereconciler.SimpleReconcilerEvent) SampleActionProviderCatalog(com.netflix.titus.common.framework.simplereconciler.internal.provider.SampleActionProviderCatalog) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) SampleProviderActionFunction(com.netflix.titus.common.framework.simplereconciler.internal.provider.SampleActionProviderCatalog.SampleProviderActionFunction) IndexSpec(com.netflix.titus.common.util.collections.index.IndexSpec) Preconditions(com.google.common.base.Preconditions) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Evaluators(com.netflix.titus.common.util.Evaluators) Collections(java.util.Collections) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) SampleProviderActionFunction(com.netflix.titus.common.framework.simplereconciler.internal.provider.SampleActionProviderCatalog.SampleProviderActionFunction) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

TitusRxSubscriber (com.netflix.titus.testkit.rx.TitusRxSubscriber)4 Test (org.junit.Test)4 Disposable (reactor.core.Disposable)4 Awaitility.await (com.jayway.awaitility.Awaitility.await)2 ContainerHealthEvent (com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent)2 ReconcilerActionProvider (com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProvider)2 ReconcilerActionProviderPolicy (com.netflix.titus.common.framework.simplereconciler.ReconcilerActionProviderPolicy)2 ActionProviderSelectorFactory (com.netflix.titus.common.framework.simplereconciler.internal.provider.ActionProviderSelectorFactory)2 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)2 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)2 Evaluators (com.netflix.titus.common.util.Evaluators)2 ReactorExt (com.netflix.titus.common.util.rx.ReactorExt)2 ContainerHealthAsserts.assertContainerHealthEvent (com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent)2 Duration (java.time.Duration)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2