Search in sources :

Example 1 with ScheduleReference

use of com.netflix.titus.common.framework.scheduler.ScheduleReference in project titus-control-plane by Netflix.

the class DefaultLocalSchedulerTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    ScheduleReference reference = localScheduler.scheduleMono(scheduleDescriptor.toBuilder().withName("testTimeout").build(), tick -> Mono.never(), Schedulers.parallel());
    expectScheduleAdded(reference);
    expectScheduleUpdateEvent(SchedulingState.Running);
    expectScheduleUpdateEvent(SchedulingState.Failed);
    // Replacement
    expectScheduleUpdateEvent(SchedulingState.Waiting);
    assertThat(reference.getSchedule().getCompletedActions()).hasSize(1);
    ScheduledAction failedAction = reference.getSchedule().getCompletedActions().get(0);
    assertThat(failedAction.getStatus().getState()).isEqualTo(SchedulingState.Failed);
    assertThat(failedAction.getStatus().getError().get()).isInstanceOf(TimeoutException.class);
}
Also used : ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction) Test(org.junit.Test)

Example 2 with ScheduleReference

use of com.netflix.titus.common.framework.scheduler.ScheduleReference in project titus-control-plane by Netflix.

the class DefaultLocalSchedulerTest method testScheduleAction.

@Test(timeout = 60_000)
public void testScheduleAction() throws Exception {
    AtomicLong tickCounter = new AtomicLong();
    ScheduleReference reference = localScheduler.schedule(scheduleDescriptor.toBuilder().withName("testScheduleAction").build(), t -> tickCounter.incrementAndGet(), true);
    testExecutionLifecycle(reference, tickCounter);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) Test(org.junit.Test)

Example 3 with ScheduleReference

use of com.netflix.titus.common.framework.scheduler.ScheduleReference in project titus-control-plane by Netflix.

the class DefaultLocalSchedulerTest method testScheduleMono.

@Test(timeout = 60_000)
public void testScheduleMono() throws Exception {
    AtomicLong tickCounter = new AtomicLong();
    ScheduleReference reference = localScheduler.scheduleMono(scheduleDescriptor.toBuilder().withName("testScheduleMono").build(), tick -> Mono.delay(Duration.ofMillis(1)).flatMap(t -> {
        tickCounter.incrementAndGet();
        return Mono.empty();
    }), Schedulers.parallel());
    testExecutionLifecycle(reference, tickCounter);
}
Also used : LocalSchedulerEvent(com.netflix.titus.common.framework.scheduler.model.event.LocalSchedulerEvent) ScheduleAddedEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleAddedEvent) ScheduleRemovedEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleRemovedEvent) SchedulingState(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus.SchedulingState) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ScheduleUpdateEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleUpdateEvent) Schedulers(reactor.core.scheduler.Schedulers) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction) Before(org.junit.Before) Clocks(com.netflix.titus.common.util.time.Clocks) Schedule(com.netflix.titus.common.framework.scheduler.model.Schedule) Awaitility.await(com.jayway.awaitility.Awaitility.await) Retryers(com.netflix.titus.common.util.retry.Retryers) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) ScheduleDescriptor(com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor) LocalScheduler(com.netflix.titus.common.framework.scheduler.LocalScheduler) AtomicLong(java.util.concurrent.atomic.AtomicLong) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) Test(org.junit.Test)

Example 4 with ScheduleReference

use of com.netflix.titus.common.framework.scheduler.ScheduleReference in project titus-control-plane by Netflix.

the class DefaultLocalSchedulerPerf method newMonoAction.

private ScheduleReference newMonoAction(boolean failSometimes) {
    int intervalMs = 50;
    ScheduleReference reference = localScheduler.scheduleMono(ScheduleDescriptor.newBuilder().withName("monoAction").withDescription("Test...").withInterval(Duration.ofMillis(intervalMs)).withTimeout(Duration.ofSeconds(1)).build(), context -> {
        checkSchedulingLatency(intervalMs, context);
        if (context.getExecutionId().getTotal() > EXECUTIONS) {
            localScheduler.cancel(context.getId()).subscribe();
            return Mono.empty();
        }
        if (failSometimes && context.getExecutionId().getTotal() % 2 == 0) {
            expectedFailures.incrementAndGet();
            return Mono.error(new RuntimeException("Simulated error"));
        }
        return Mono.delay(Duration.ofMillis(10)).ignoreElement().cast(Void.class).doOnError(Throwable::printStackTrace).doOnSuccess(next -> successes.incrementAndGet());
    }, Schedulers.parallel());
    observeEvents(reference);
    return reference;
}
Also used : ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference)

Example 5 with ScheduleReference

use of com.netflix.titus.common.framework.scheduler.ScheduleReference in project titus-control-plane by Netflix.

the class DefaultLocalSchedulerPerf method observeEvents.

private void observeEvents(ScheduleReference reference) {
    localScheduler.events().filter(e -> e.getSchedule().getId().equals(reference.getSchedule().getId())).subscribe(event -> {
        if (event instanceof ScheduleUpdateEvent) {
            ScheduleUpdateEvent updateEvent = (ScheduleUpdateEvent) event;
            ScheduledAction action = updateEvent.getSchedule().getCurrentAction();
            if (action.getStatus().getState() == SchedulingStatus.SchedulingState.Failed) {
                eventFailures.incrementAndGet();
            }
        } else if (event instanceof ScheduleRemovedEvent) {
            removedEvents.incrementAndGet();
        }
    });
}
Also used : SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus) Clocks(com.netflix.titus.common.util.time.Clocks) ExecutionContext(com.netflix.titus.common.framework.scheduler.ExecutionContext) ScheduleRemovedEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleRemovedEvent) Set(java.util.Set) Mono(reactor.core.publisher.Mono) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) HashSet(java.util.HashSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) ScheduleDescriptor(com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor) Duration(java.time.Duration) ScheduleUpdateEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleUpdateEvent) Schedulers(reactor.core.scheduler.Schedulers) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction) LocalScheduler(com.netflix.titus.common.framework.scheduler.LocalScheduler) ScheduleRemovedEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleRemovedEvent) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction) ScheduleUpdateEvent(com.netflix.titus.common.framework.scheduler.model.event.ScheduleUpdateEvent)

Aggregations

ScheduleReference (com.netflix.titus.common.framework.scheduler.ScheduleReference)7 Test (org.junit.Test)4 ScheduledAction (com.netflix.titus.common.framework.scheduler.model.ScheduledAction)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 LocalScheduler (com.netflix.titus.common.framework.scheduler.LocalScheduler)2 ScheduleDescriptor (com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor)2 ScheduleRemovedEvent (com.netflix.titus.common.framework.scheduler.model.event.ScheduleRemovedEvent)2 ScheduleUpdateEvent (com.netflix.titus.common.framework.scheduler.model.event.ScheduleUpdateEvent)2 Clocks (com.netflix.titus.common.util.time.Clocks)2 Duration (java.time.Duration)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Mono (reactor.core.publisher.Mono)2 Schedulers (reactor.core.scheduler.Schedulers)2 Awaitility.await (com.jayway.awaitility.Awaitility.await)1 ExecutionContext (com.netflix.titus.common.framework.scheduler.ExecutionContext)1 Schedule (com.netflix.titus.common.framework.scheduler.model.Schedule)1 SchedulingStatus (com.netflix.titus.common.framework.scheduler.model.SchedulingStatus)1 SchedulingState (com.netflix.titus.common.framework.scheduler.model.SchedulingStatus.SchedulingState)1 LocalSchedulerEvent (com.netflix.titus.common.framework.scheduler.model.event.LocalSchedulerEvent)1