Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance tests deleting errors in AbstractApplicationErrorDaoTest #356

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kiwiproject.base.DefaultEnvironment;
import org.kiwiproject.dropwizard.error.model.ApplicationError;
import org.kiwiproject.dropwizard.error.model.ApplicationError.Resolved;
import org.kiwiproject.dropwizard.error.test.junit.jupiter.ApplicationErrorExtension;
Expand Down Expand Up @@ -248,29 +249,47 @@ void shouldChangeOnlyUnresolvedErrors() {
}

@Test
void shouldDeleteAllResolvedErrors() {
insertApplicationError(randomResolvedApplicationError());
insertApplicationError(randomUnresolvedApplicationError());
void shouldDeleteResolvedErrors_BeforeReferenceDate() {
var resolvedId1 = insertApplicationError(randomResolvedApplicationError());
var unresolvedId1 = insertApplicationError(randomUnresolvedApplicationError());

// Ensure the next createdAt is AFTER previous ones as long as
// the database timestamp precision is at least milliseconds
sleep5ms();

var timeInBetween = ZonedDateTime.now();
insertApplicationError(randomResolvedApplicationError());
var resolvedId2 = insertApplicationError(randomResolvedApplicationError());

var count = errorDao.deleteResolvedErrorsBefore(timeInBetween);

assertThat(count).isOne();
assertThat(errorDao.getById(resolvedId1)).isEmpty();
assertThat(errorDao.getById(unresolvedId1)).isPresent();
assertThat(errorDao.getById(resolvedId2)).isPresent();
}

@Test
void shouldDeleteUnresolvedErrors() {
insertApplicationError(randomResolvedApplicationError());
insertApplicationError(randomUnresolvedApplicationError());
void shouldDeleteUnresolvedErrors_BeforeReferenceDate() {
var resolvedId1 = insertApplicationError(randomResolvedApplicationError());
var unresolvedId1 = insertApplicationError(randomUnresolvedApplicationError());

// Ensure the createdAt is AFTER previous ones as long as
// the database timestamp precision is at least milliseconds
sleep5ms();

var timeInBetween = ZonedDateTime.now();
insertApplicationError(randomResolvedApplicationError());
var unresolvedId2 = insertApplicationError(randomUnresolvedApplicationError());

var count = errorDao.deleteUnresolvedErrorsBefore(timeInBetween);

assertThat(count).isOne();
assertThat(errorDao.getById(resolvedId1)).isPresent();
assertThat(errorDao.getById(unresolvedId1)).isEmpty();
assertThat(errorDao.getById(unresolvedId2)).isPresent();
}

private static void sleep5ms() {
new DefaultEnvironment().sleepQuietly(5);
}

@Test
Expand Down