Search in sources :

Example 1 with SystemQuotaController

use of com.netflix.titus.master.eviction.service.quota.system.SystemQuotaController in project titus-control-plane by Netflix.

the class TitusQuotasManagerTest method tryConsumeSystemAndJobQuota.

@Test
public void tryConsumeSystemAndJobQuota() {
    String taskId = "job1Task1";
    String jobQuotaRejectionReason = "Job does not allow any more terminations";
    Job<BatchJobExt> job1 = JobGenerator.oneBatchJob().but(withApplicationName("app1Test"));
    EvictionConfiguration config1 = mock(EvictionConfiguration.class);
    when(config1.getAppsExemptFromSystemDisruptionWindow()).thenReturn("app1.*");
    SystemQuotaController systemQuotaController = mock(SystemQuotaController.class);
    when(systemQuotaController.consume(taskId)).thenReturn(ConsumptionResult.approved());
    JobQuotaController jobQuotaController = mock(JobQuotaController.class);
    when(jobQuotaController.consume(taskId)).thenReturn(ConsumptionResult.rejected(jobQuotaRejectionReason));
    TitusQuotasManager titusQuotasManager = new TitusQuotasManager(null, null, null, systemQuotaController, config1, null);
    ConsumptionResult consumptionResult = titusQuotasManager.tryConsumeSystemAndJobQuota(jobQuotaController, job1, taskId);
    assertThat(consumptionResult.isApproved()).isFalse();
    assertThat(consumptionResult.getRejectionReason()).isPresent();
    assertThat(consumptionResult.getRejectionReason().get()).isEqualTo(jobQuotaRejectionReason);
    JobQuotaController jobQuotaController2 = mock(JobQuotaController.class);
    when(jobQuotaController2.consume(taskId)).thenReturn(ConsumptionResult.approved());
    ConsumptionResult consumptionResult2 = titusQuotasManager.tryConsumeSystemAndJobQuota(jobQuotaController2, job1, taskId);
    assertThat(consumptionResult2.isApproved()).isTrue();
    String quotaLimitExceededReason = SystemQuotaConsumptionResults.QUOTA_LIMIT_EXCEEDED.getRejectionReason().get();
    when(systemQuotaController.consume(taskId)).thenReturn(ConsumptionResult.rejected(quotaLimitExceededReason));
    ConsumptionResult consumptionResult3 = titusQuotasManager.tryConsumeSystemAndJobQuota(jobQuotaController2, job1, taskId);
    assertThat(consumptionResult3.isApproved()).isFalse();
    assertThat(consumptionResult3.getRejectionReason()).isPresent();
    assertThat(consumptionResult3.getRejectionReason().get()).isEqualTo(quotaLimitExceededReason);
    String outsideSystemWindowReason = SystemQuotaConsumptionResults.OUTSIDE_SYSTEM_TIME_WINDOW.getRejectionReason().get();
    when(systemQuotaController.consume(taskId)).thenReturn(ConsumptionResult.rejected(outsideSystemWindowReason));
    ConsumptionResult consumptionResult4 = titusQuotasManager.tryConsumeSystemAndJobQuota(jobQuotaController2, job1, taskId);
    assertThat(consumptionResult4.isApproved()).isTrue();
}
Also used : BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) EvictionConfiguration(com.netflix.titus.runtime.connector.eviction.EvictionConfiguration) JobQuotaController(com.netflix.titus.master.eviction.service.quota.job.JobQuotaController) SystemQuotaController(com.netflix.titus.master.eviction.service.quota.system.SystemQuotaController) Test(org.junit.Test)

Aggregations

BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 JobQuotaController (com.netflix.titus.master.eviction.service.quota.job.JobQuotaController)1 SystemQuotaController (com.netflix.titus.master.eviction.service.quota.system.SystemQuotaController)1 EvictionConfiguration (com.netflix.titus.runtime.connector.eviction.EvictionConfiguration)1 Test (org.junit.Test)1