-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define
DbRetentionJob(Jdbi, DbRetentionConfig)
(#2549)
* Define `DbRetentionJob(Jdbi, DbRetentionConfig)` Signed-off-by: wslulciuc <willy@datakin.com> * Define `DbRetentionJob(Jdbi, DbRetentionConfig)` Signed-off-by: wslulciuc <willy@datakin.com> * continued: Define `DbRetentionJob(Jdbi, DbRetentionConfig)` Signed-off-by: wslulciuc <willy@datakin.com> * continued: Resolve merge conflicts Signed-off-by: wslulciuc <willy@datakin.com> * Add oss license header Signed-off-by: wslulciuc <willy@datakin.com> --------- Signed-off-by: wslulciuc <willy@datakin.com>
- Loading branch information
Showing
4 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
api/src/test/java/marquez/jobs/DbRetentionConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2018-2023 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.jobs; | ||
|
||
import static marquez.db.DbRetention.DEFAULT_NUMBER_OF_ROWS_PER_BATCH; | ||
import static marquez.db.DbRetention.DEFAULT_RETENTION_DAYS; | ||
import static marquez.jobs.DbRetentionConfig.DEFAULT_FREQUENCY_MINS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Set; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Validation; | ||
import javax.validation.Validator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** The test suite for {@link DbRetentionConfig}. */ | ||
public class DbRetentionConfigTest { | ||
private static final Validator VALIDATOR = | ||
Validation.buildDefaultValidatorFactory().getValidator(); | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_withDefaultsOnly() { | ||
final DbRetentionConfig configWithDefaults = new DbRetentionConfig(); | ||
|
||
assertThat(configWithDefaults.getFrequencyMins()).isEqualTo(DEFAULT_FREQUENCY_MINS); | ||
assertThat(configWithDefaults.getNumberOfRowsPerBatch()) | ||
.isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); | ||
assertThat(configWithDefaults.getRetentionDays()).isEqualTo(DEFAULT_RETENTION_DAYS); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_overrideFrequencyMins() { | ||
final int frequencyMinsOverride = 5; | ||
final DbRetentionConfig configWithFrequencyMinsOverride = | ||
DbRetentionConfig.builder().frequencyMins(frequencyMinsOverride).build(); | ||
|
||
// No constraint violations. | ||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithFrequencyMinsOverride); | ||
assertThat(violations).isEmpty(); | ||
|
||
assertThat(configWithFrequencyMinsOverride.getFrequencyMins()).isEqualTo(frequencyMinsOverride); | ||
assertThat(configWithFrequencyMinsOverride.getNumberOfRowsPerBatch()) | ||
.isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); | ||
assertThat(configWithFrequencyMinsOverride.getRetentionDays()) | ||
.isEqualTo(DEFAULT_RETENTION_DAYS); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_overrideNumberOfRowsPerBatch() { | ||
final int numberOfRowsPerBatchOverride = 25; | ||
final DbRetentionConfig configWithNumberOfRowsPerBatchOverride = | ||
DbRetentionConfig.builder().numberOfRowsPerBatch(numberOfRowsPerBatchOverride).build(); | ||
|
||
// No constraint violations. | ||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithNumberOfRowsPerBatchOverride); | ||
assertThat(violations).isEmpty(); | ||
|
||
assertThat(configWithNumberOfRowsPerBatchOverride.getFrequencyMins()) | ||
.isEqualTo(DEFAULT_FREQUENCY_MINS); | ||
assertThat(configWithNumberOfRowsPerBatchOverride.getNumberOfRowsPerBatch()) | ||
.isEqualTo(numberOfRowsPerBatchOverride); | ||
assertThat(configWithNumberOfRowsPerBatchOverride.getRetentionDays()) | ||
.isEqualTo(DEFAULT_RETENTION_DAYS); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_overrideRetentionDays() { | ||
final int retentionDaysOverride = 14; | ||
final DbRetentionConfig configWithNumberOfRowsPerBatchOverride = | ||
DbRetentionConfig.builder().retentionDays(retentionDaysOverride).build(); | ||
|
||
// No constraint violations. | ||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithNumberOfRowsPerBatchOverride); | ||
assertThat(violations).isEmpty(); | ||
|
||
assertThat(configWithNumberOfRowsPerBatchOverride.getFrequencyMins()) | ||
.isEqualTo(DEFAULT_FREQUENCY_MINS); | ||
assertThat(configWithNumberOfRowsPerBatchOverride.getNumberOfRowsPerBatch()) | ||
.isEqualTo(DEFAULT_NUMBER_OF_ROWS_PER_BATCH); | ||
assertThat(configWithNumberOfRowsPerBatchOverride.getRetentionDays()) | ||
.isEqualTo(retentionDaysOverride); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_negativeFrequencyMins() { | ||
final int negativeFrequencyMins = -5; | ||
|
||
final DbRetentionConfig configWithNegativeFrequencyMins = | ||
DbRetentionConfig.builder().frequencyMins(negativeFrequencyMins).build(); | ||
|
||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithNegativeFrequencyMins); | ||
assertThat(violations).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_negativeNumberOfRowsPerBatch() { | ||
final int negativeNumberOfRowsPerBatch = -25; | ||
|
||
final DbRetentionConfig configWithNegativeNumberOfRowsPerBatch = | ||
DbRetentionConfig.builder().numberOfRowsPerBatch(negativeNumberOfRowsPerBatch).build(); | ||
|
||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithNegativeNumberOfRowsPerBatch); | ||
assertThat(violations).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testNewDbRetentionConfig_negativeRetentionDays() { | ||
final int negativeRetentionDays = -14; | ||
|
||
final DbRetentionConfig configWithNegativeRetentionDays = | ||
DbRetentionConfig.builder().retentionDays(negativeRetentionDays).build(); | ||
|
||
final Set<ConstraintViolation<DbRetentionConfig>> violations = | ||
VALIDATOR.validate(configWithNegativeRetentionDays); | ||
assertThat(violations).hasSize(1); | ||
} | ||
} |