|
| 1 | +/* |
| 2 | + * Copyright 2018-2023 contributors to the Marquez project |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package marquez.jobs; |
| 7 | + |
| 8 | +import static marquez.db.DbRetention.DEFAULT_NUMBER_OF_ROWS_PER_BATCH; |
| 9 | +import static marquez.db.DbRetention.DEFAULT_RETENTION_DAYS; |
| 10 | +import static marquez.jobs.DbRetentionConfig.DEFAULT_FREQUENCY_MINS; |
| 11 | +import static org.assertj.core.api.Assertions.assertThat; |
| 12 | + |
| 13 | +import java.util.Set; |
| 14 | +import javax.validation.ConstraintViolation; |
| 15 | +import javax.validation.Validation; |
| 16 | +import javax.validation.Validator; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +/** The test suite for {@link DbRetentionConfig}. */ |
| 20 | +public class DbRetentionConfigTest { |
| 21 | + private static final Validator VALIDATOR = |
| 22 | + Validation.buildDefaultValidatorFactory().getValidator(); |
| 23 | + |
| 24 | + @Test |
| 25 | + public void testNewDbRetentionConfig_withDefaultsOnly() { |
| 26 | + final DbRetentionConfig configWithDefaults = new DbRetentionConfig(); |
| 27 | + |
| 28 | + assertThat(configWithDefaults.getFrequencyMins()).isEqualTo(DEFAULT_FREQUENCY_MINS); |
| 29 | + assertThat(configWithDefaults.getNumberOfRowsPerBatch()) |
| 30 | + .isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); |
| 31 | + assertThat(configWithDefaults.getRetentionDays()).isEqualTo(DEFAULT_RETENTION_DAYS); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testNewDbRetentionConfig_overrideFrequencyMins() { |
| 36 | + final int frequencyMinsOverride = 5; |
| 37 | + final DbRetentionConfig configWithFrequencyMinsOverride = |
| 38 | + DbRetentionConfig.builder().frequencyMins(frequencyMinsOverride).build(); |
| 39 | + |
| 40 | + // No constraint violations. |
| 41 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 42 | + VALIDATOR.validate(configWithFrequencyMinsOverride); |
| 43 | + assertThat(violations).isEmpty(); |
| 44 | + |
| 45 | + assertThat(configWithFrequencyMinsOverride.getFrequencyMins()).isEqualTo(frequencyMinsOverride); |
| 46 | + assertThat(configWithFrequencyMinsOverride.getNumberOfRowsPerBatch()) |
| 47 | + .isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); |
| 48 | + assertThat(configWithFrequencyMinsOverride.getRetentionDays()) |
| 49 | + .isEqualTo(DEFAULT_RETENTION_DAYS); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testNewDbRetentionConfig_overrideNumberOfRowsPerBatch() { |
| 54 | + final int numberOfRowsPerBatchOverride = 25; |
| 55 | + final DbRetentionConfig configWithNumberOfRowsPerBatchOverride = |
| 56 | + DbRetentionConfig.builder().numberOfRowsPerBatch(numberOfRowsPerBatchOverride).build(); |
| 57 | + |
| 58 | + // No constraint violations. |
| 59 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 60 | + VALIDATOR.validate(configWithNumberOfRowsPerBatchOverride); |
| 61 | + assertThat(violations).isEmpty(); |
| 62 | + |
| 63 | + assertThat(configWithNumberOfRowsPerBatchOverride.getFrequencyMins()) |
| 64 | + .isEqualTo(DEFAULT_FREQUENCY_MINS); |
| 65 | + assertThat(configWithNumberOfRowsPerBatchOverride.getNumberOfRowsPerBatch()) |
| 66 | + .isEqualTo(numberOfRowsPerBatchOverride); |
| 67 | + assertThat(configWithNumberOfRowsPerBatchOverride.getRetentionDays()) |
| 68 | + .isEqualTo(DEFAULT_RETENTION_DAYS); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testNewDbRetentionConfig_overrideRetentionDays() { |
| 73 | + final int retentionDaysOverride = 14; |
| 74 | + final DbRetentionConfig configWithNumberOfRowsPerBatchOverride = |
| 75 | + DbRetentionConfig.builder().retentionDays(retentionDaysOverride).build(); |
| 76 | + |
| 77 | + // No constraint violations. |
| 78 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 79 | + VALIDATOR.validate(configWithNumberOfRowsPerBatchOverride); |
| 80 | + assertThat(violations).isEmpty(); |
| 81 | + |
| 82 | + assertThat(configWithNumberOfRowsPerBatchOverride.getFrequencyMins()) |
| 83 | + .isEqualTo(DEFAULT_FREQUENCY_MINS); |
| 84 | + assertThat(configWithNumberOfRowsPerBatchOverride.getNumberOfRowsPerBatch()) |
| 85 | + .isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); |
| 86 | + assertThat(configWithNumberOfRowsPerBatchOverride.getRetentionDays()) |
| 87 | + .isEqualTo(retentionDaysOverride); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testNewDbRetentionConfig_negativeFrequencyMins() { |
| 92 | + final int negativeFrequencyMins = -5; |
| 93 | + |
| 94 | + final DbRetentionConfig configWithNegativeFrequencyMins = |
| 95 | + DbRetentionConfig.builder().frequencyMins(negativeFrequencyMins).build(); |
| 96 | + |
| 97 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 98 | + VALIDATOR.validate(configWithNegativeFrequencyMins); |
| 99 | + assertThat(violations).hasSize(1); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void testNewDbRetentionConfig_negativeNumberOfRowsPerBatch() { |
| 104 | + final int negativeNumberOfRowsPerBatch = -25; |
| 105 | + |
| 106 | + final DbRetentionConfig configWithNegativeNumberOfRowsPerBatch = |
| 107 | + DbRetentionConfig.builder().numberOfRowsPerBatch(negativeNumberOfRowsPerBatch).build(); |
| 108 | + |
| 109 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 110 | + VALIDATOR.validate(configWithNegativeNumberOfRowsPerBatch); |
| 111 | + assertThat(violations).hasSize(1); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void testNewDbRetentionConfig_negativeRetentionDays() { |
| 116 | + final int negativeRetentionDays = -14; |
| 117 | + |
| 118 | + final DbRetentionConfig configWithNegativeRetentionDays = |
| 119 | + DbRetentionConfig.builder().retentionDays(negativeRetentionDays).build(); |
| 120 | + |
| 121 | + final Set<ConstraintViolation<DbRetentionConfig>> violations = |
| 122 | + VALIDATOR.validate(configWithNegativeRetentionDays); |
| 123 | + assertThat(violations).hasSize(1); |
| 124 | + } |
| 125 | +} |
0 commit comments