From 014b804ac2c4b7a1ef083ac2c0790f18c0e125ff Mon Sep 17 00:00:00 2001 From: george321 Date: Mon, 7 Oct 2024 00:54:07 +0300 Subject: [PATCH] Fix unit tests --- .../parser/impl/CsvParserService.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/gmitaros/vesselmetrics/parser/impl/CsvParserService.java b/src/main/java/com/gmitaros/vesselmetrics/parser/impl/CsvParserService.java index 6d239d7..e4acc26 100644 --- a/src/main/java/com/gmitaros/vesselmetrics/parser/impl/CsvParserService.java +++ b/src/main/java/com/gmitaros/vesselmetrics/parser/impl/CsvParserService.java @@ -62,20 +62,22 @@ public class CsvParserService implements DataParser { @PostConstruct @Transactional public void init() { - long vesselData = vesselDataRepository.count(); - log.info("Found {} vessel data in vessel_data db ", vesselData); - boolean loadData = vesselData <= 0 || loadCsvIfAlreadyHaveData; - if (loadData) { - log.info("CsvParserService will load data from {} file", vesselDataPath); - try (InputStream inputStream = getClass().getResourceAsStream(vesselDataPath)) { - parseAndSave(inputStream); - checkForOutliers(); - } catch (Exception e) { - log.error("Error initializing data: ", e); - throw new RuntimeException("Failed to initialize data", e); + synchronized (this) { + long vesselData = vesselDataRepository.count(); + log.info("Found {} vessel data in vessel_data db ", vesselData); + boolean loadData = vesselData <= 0 || loadCsvIfAlreadyHaveData; + if (loadData) { + log.info("CsvParserService will load data from {} file", vesselDataPath); + try (InputStream inputStream = getClass().getResourceAsStream(vesselDataPath)) { + parseAndSave(inputStream); + checkForOutliers(); + } catch (Exception e) { + log.error("Error initializing data: ", e); + throw new RuntimeException("Failed to initialize data", e); + } + } else { + log.info("Skipping loading again vessel data from CSV file"); } - } else { - log.info("Skipping loading again vessel data from CSV file"); } }