Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Fix/700 retention policy #711

Merged
merged 4 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface DiagnosisKeyRepository extends PagingAndSortingRepository<Diagn
* @param submissionTimestamp The submission timestamp up to which entries will be expired.
* @return The number of expired keys.
*/
@Query("SELECT COUNT(*) FROM diagnosis_key WHERE submission_timestamp<=:threshold")
@Query("SELECT COUNT(*) FROM diagnosis_key WHERE submission_timestamp<:threshold")
int countOlderThanOrEqual(@Param("threshold") long submissionTimestamp);
fredrb marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand All @@ -45,7 +45,7 @@ public interface DiagnosisKeyRepository extends PagingAndSortingRepository<Diagn
* @param submissionTimestamp The submission timestamp up to which entries will be deleted.
*/
@Modifying
@Query("DELETE FROM diagnosis_key WHERE submission_timestamp<=:threshold")
@Query("DELETE FROM diagnosis_key WHERE submission_timestamp<:threshold")
void deleteOlderThanOrEqual(@Param("threshold") long submissionTimestamp);
fredrb marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void testApplyRetentionPolicyForEmptyDb() {

@Test
void testApplyRetentionPolicyForOneNotApplicableEntry() {
var expKeys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusHours(23)));
var expKeys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusDays(1L)));

diagnosisKeyService.saveDiagnosisKeys(expKeys);
diagnosisKeyService.applyRetentionPolicy(1);
Expand All @@ -125,7 +125,7 @@ void testApplyRetentionPolicyForOneNotApplicableEntry() {

@Test
void testApplyRetentionPolicyForOneApplicableEntry() {
var keys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusDays(1L)));
var keys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusDays(1L).minusHours(1)));

diagnosisKeyService.saveDiagnosisKeys(keys);
diagnosisKeyService.applyRetentionPolicy(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void writeTestData() {

// Timestamps in hours since epoch. Test data generation starts one hour after the latest diagnosis key in the
// database and ends one hour before the current one.
long startTimestamp = getGeneratorStartTimestamp(existingDiagnosisKeys) + 1; // Inclusive
long startTimestamp = getGeneratorStartTimestamp(existingDiagnosisKeys); // Inclusive
long endTimestamp = getGeneratorEndTimestamp(); // Inclusive

// Add the startTimestamp to the seed. Otherwise we would generate the same data every hour.
Expand Down Expand Up @@ -134,7 +134,7 @@ private long getGeneratorStartTimestamp(List<DiagnosisKey> diagnosisKeys) {
return getRetentionStartTimestamp();
} else {
DiagnosisKey latestDiagnosisKey = diagnosisKeys.get(diagnosisKeys.size() - 1);
return latestDiagnosisKey.getSubmissionTimestamp();
return latestDiagnosisKey.getSubmissionTimestamp() + 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void files_once_published_to_objectstore_should_not_be_overriden_because_of_rete

triggerRetentionPolicy(testStartDate);

// Trigger second distrubution after data retention policies were applied
// Trigger second distribution after data retention policies were applied
assembleAndDistribute(testOutputFolder.newFolder("output-after-retention"));
List<S3Object> filesAfterRetention = getPublishedFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import app.coronawarn.server.services.distribution.assembly.structure.util.TimeUtils;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig.TestData;
import org.junit.After;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -76,6 +78,11 @@ void setup() {
distributionServiceConfig.setTestData(testData);
}

@AfterEach
void tearDown() {
TimeUtils.setNow(null);
}

@Test
void shouldCreateKeysAllKeys() {
var now = LocalDateTime.of(2020, 7, 15, 12, 0, 0).toInstant(ZoneOffset.UTC);
Expand Down