Search in sources :

Example 1 with ModelAction

use of com.netflix.titus.common.framework.reconciler.ModelAction in project titus-control-plane by Netflix.

the class RetryActionInterceptorTest method testRetry.

@Test
public void testRetry() throws Exception {
    TitusChangeAction changeAction = SampleTitusChangeActions.failingJob(2);
    // First two calls should fail
    ModelAction updateAction1 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RetryModelUpdateAction.class);
    EntityHolder modelWithTag1 = expectAboveExecutionLimits(updateAction1, EntityHolder.newRoot("rootId", "data"));
    expectBelowExecutionLimitsWhenTimeAdvanced(modelWithTag1, INITIAL_DELAY_MS);
    ModelAction updateAction2 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RetryModelUpdateAction.class);
    EntityHolder modelWithTag2 = expectAboveExecutionLimits(updateAction2, modelWithTag1);
    expectBelowExecutionLimitsWhenTimeAdvanced(modelWithTag2, INITIAL_DELAY_MS * 2);
    // Third call should succeed
    ModelAction updateAction3 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RemoveRetryRecord.class);
    expectNoRetryTag(updateAction3, modelWithTag2);
}
Also used : ModelAction(com.netflix.titus.common.framework.reconciler.ModelAction) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Test(org.junit.Test)

Example 2 with ModelAction

use of com.netflix.titus.common.framework.reconciler.ModelAction in project titus-control-plane by Netflix.

the class RateLimiterInterceptorTest method executeRateLimitedAction.

private ModelAction executeRateLimitedAction(TitusChangeAction changeAction) {
    ExtTestSubscriber<List<ModelActionHolder>> testSubscriber = new ExtTestSubscriber<>();
    rateLimiterInterceptor.apply(changeAction).apply().subscribe(testSubscriber);
    ModelAction updateAction = testSubscriber.takeNext().get(0).getAction();
    assertThat(updateAction).isInstanceOf(TitusModelAction.class);
    return updateAction;
}
Also used : ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ModelAction(com.netflix.titus.common.framework.reconciler.ModelAction) List(java.util.List)

Example 3 with ModelAction

use of com.netflix.titus.common.framework.reconciler.ModelAction in project titus-control-plane by Netflix.

the class RateLimiterInterceptorTest method testRateLimiting.

@Test
public void testRateLimiting() throws Exception {
    Job<BatchJobExt> job = batchJobs(JobDescriptorGenerator.oneTaskBatchJobDescriptor()).getValue();
    // Use all tokens
    EntityHolder nextRoot = EntityHolder.newRoot("root", job);
    for (int i = 0; i < BUCKET_SIZE; i++) {
        assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(BUCKET_SIZE - i);
        ModelAction updateAction = executeRateLimitedAction(SampleTitusChangeActions.successfulJob());
        nextRoot = updateAction.apply(nextRoot).get().getRight();
    }
    assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(0);
    // Refill
    testClock.advanceTime(REFILL_INTERVAL_MS, TimeUnit.MILLISECONDS);
    assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(1);
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ModelAction(com.netflix.titus.common.framework.reconciler.ModelAction) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Test(org.junit.Test)

Aggregations

ModelAction (com.netflix.titus.common.framework.reconciler.ModelAction)3 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)2 TitusModelAction (com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction)2 Test (org.junit.Test)2 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 TitusChangeAction (com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)1 ExtTestSubscriber (com.netflix.titus.testkit.rx.ExtTestSubscriber)1 List (java.util.List)1