Search in sources :

Example 6 with ScheduleReference

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

the class DefaultLocalSchedulerPerf method newAction.

private ScheduleReference newAction(boolean failSometimes) {
    int intervalMs = 50;
    ScheduleReference reference = localScheduler.schedule(ScheduleDescriptor.newBuilder().withName("runnableAction").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;
        }
        if (failSometimes && context.getExecutionId().getTotal() % 2 == 0) {
            expectedFailures.incrementAndGet();
            throw new RuntimeException("Simulated error");
        }
        try {
            Thread.sleep(10);
            successes.incrementAndGet();
        } catch (InterruptedException ignore) {
        }
    }, true);
    observeEvents(reference);
    return reference;
}
Also used : ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference)

Example 7 with ScheduleReference

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

the class DefaultLocalSchedulerTest method testRetries.

@Test
public void testRetries() throws InterruptedException {
    AtomicInteger counter = new AtomicInteger();
    ScheduleReference reference = localScheduler.scheduleMono(scheduleDescriptor.toBuilder().withName("testRetries").build(), tick -> Mono.defer(() -> counter.incrementAndGet() % 2 == 0 ? Mono.empty() : Mono.error(new RuntimeException("Simulated error at iteration " + counter.get()))), Schedulers.parallel());
    expectScheduleAdded(reference);
    expectScheduleUpdateEvent(SchedulingState.Running);
    expectScheduleUpdateEvent(SchedulingState.Failed);
    expectScheduleUpdateEvent(SchedulingState.Waiting);
    expectScheduleUpdateEvent(SchedulingState.Running);
    expectScheduleUpdateEvent(SchedulingState.Succeeded);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) Test(org.junit.Test)

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