Search in sources :

Example 1 with AdmissionValidator

use of com.netflix.titus.common.model.admission.AdmissionValidator in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateHardSoftTimeout.

// Hard/Soft validation tests
@Test
public void validateHardSoftTimeout() {
    AdmissionValidator<JobDescriptor> never0 = new NeverJobValidator(ValidationError.Type.HARD);
    AdmissionValidator never1 = new NeverJobValidator(ValidationError.Type.SOFT);
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(never0, never1));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 2).verifyComplete();
    Collection<ValidationError> errors = mono.block();
    validateTimeoutErrors(errors);
    Collection<ValidationError> hardErrors = errors.stream().filter(error -> error.getType().equals(ValidationError.Type.HARD)).collect(Collectors.toList());
    assertThat(hardErrors).hasSize(1);
    Collection<ValidationError> softErrors = errors.stream().filter(error -> error.getType().equals(ValidationError.Type.SOFT)).collect(Collectors.toList());
    assertThat(softErrors).hasSize(1);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 2 with AdmissionValidator

use of com.netflix.titus.common.model.admission.AdmissionValidator in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateSoftTimeout.

// Soft validation tests
@Test
public void validateSoftTimeout() {
    AdmissionValidator never = new NeverJobValidator(ValidationError.Type.SOFT);
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(never));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 1).verifyComplete();
    Collection<ValidationError> errors = mono.block();
    validateTimeoutErrors(errors);
    validateErrorType(errors, ValidationError.Type.SOFT);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 3 with AdmissionValidator

use of com.netflix.titus.common.model.admission.AdmissionValidator in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateSoftPass.

@Test
public void validateSoftPass() {
    AdmissionValidator pass = new PassJobValidator();
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(pass));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 0).verifyComplete();
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Test(org.junit.Test)

Example 4 with AdmissionValidator

use of com.netflix.titus.common.model.admission.AdmissionValidator in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateHardPassFailTimeout.

@Test
public void validateHardPassFailTimeout() {
    AdmissionValidator pass = new PassJobValidator();
    AdmissionValidator fail = new FailJobValidator();
    AdmissionValidator never = new NeverJobValidator();
    AdmissionValidator parallelValidator = new AggregatingValidator(configuration, registry, Arrays.asList(pass, fail, never));
    Mono<Set<ValidationError>> mono = parallelValidator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 2).verifyComplete();
    Set<ValidationError> errors = mono.block();
    validateErrorType(errors, ValidationError.Type.HARD);
    Collection<ValidationError> failErrors = errors.stream().filter(error -> error.getField().equals(FailJobValidator.ERR_FIELD)).collect(Collectors.toList());
    assertThat(failErrors).hasSize(1);
    validateFailErrors(failErrors);
    Collection<ValidationError> timeoutErrors = errors.stream().filter(error -> error.getField().equals(NeverJobValidator.class.getSimpleName())).collect(Collectors.toList());
    assertThat(timeoutErrors).hasSize(1);
    validateTimeoutErrors(timeoutErrors);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 5 with AdmissionValidator

use of com.netflix.titus.common.model.admission.AdmissionValidator in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateHardFailFail.

@Test
public void validateHardFailFail() {
    AdmissionValidator fail0 = new FailJobValidator(ValidationError.Type.HARD);
    AdmissionValidator fail1 = new FailJobValidator(ValidationError.Type.HARD);
    AggregatingValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(fail0, fail1));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 2).verifyComplete();
    Set<ValidationError> errors = mono.block();
    validateFailErrors(errors);
    validateErrorType(errors, ValidationError.Type.HARD);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Aggregations

AdmissionValidator (com.netflix.titus.common.model.admission.AdmissionValidator)11 Set (java.util.Set)11 Test (org.junit.Test)11 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)10 Registry (com.netflix.spectator.api.Registry)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 TitusValidatorConfiguration (com.netflix.titus.common.model.admission.TitusValidatorConfiguration)10 ValidationError (com.netflix.titus.common.model.sanitizer.ValidationError)10 Duration (java.time.Duration)10 Arrays (java.util.Arrays)10 Collection (java.util.Collection)10 Collections (java.util.Collections)10 Collectors (java.util.stream.Collectors)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 Before (org.junit.Before)10 Mockito.mock (org.mockito.Mockito.mock)10 Mockito.when (org.mockito.Mockito.when)10 Mono (reactor.core.publisher.Mono)10 StepVerifier (reactor.test.StepVerifier)10