Skip to content

Commit

Permalink
Jpa race condition temporary workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Rwolfe-Nava committed Oct 19, 2023
1 parent 45a48bf commit bde19f1
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Set;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;

//plan on cleaning up when decoupling contract_id foreign keys in database
Expand Down Expand Up @@ -50,23 +51,30 @@ public void cleanup() {
// wipe the tables between tests and that the tables started as empty tables.
// Based on these assumptions it is safe to simply delete everything associated
// with those tables
coverageDeltaTestRepository.deleteAll();
coverageDeltaTestRepository.flush();
cleanupRepository(coverageDeltaTestRepository);

deleteCoverage();

coverageSearchEventRepo.deleteAll();
coverageSearchEventRepo.flush();
cleanupRepository(coverageSearchEventRepo);

coverageSearchRepo.deleteAll();
coverageSearchRepo.flush();
cleanupRepository(coverageSearchRepo);

coveragePeriodRepo.deleteAll();
coveragePeriodRepo.flush();
cleanupRepository(coveragePeriodRepo);

domainObjects.clear();
}

private void cleanupRepository(JpaRepository repository) {
repository.deleteAll();
repository.flush();

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.print("Exception: " + e);
}
}

public int countCoverage() {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) FROM COVERAGE")) {
Expand Down

0 comments on commit bde19f1

Please sign in to comment.