From d18fcced99cae0a2289130e0bb2802bceebaa8fa Mon Sep 17 00:00:00 2001 From: Sivakumar Srinivasulu Date: Sat, 6 Jul 2024 00:17:15 -0500 Subject: [PATCH] added caching for apm entity json files --- converter/pom.xml | 6 ++++ .../test/java/gov/cms/qpp/CacheBuilder.java | 35 +++++++++++++++++++ .../ClinicalDocumentExtensionTest.java | 4 ++- .../acceptance/NegativePcfRoundTripTest.java | 4 ++- .../qpp/acceptance/Pcf2024AcceptanceTest.java | 4 ++- .../cms/qpp/acceptance/PcfRoundTripTest.java | 4 ++- .../QualityMeasureIdRoundTripTest.java | 4 ++- .../model/validation/ApmEntityIdsTest.java | 4 ++- .../PcfClinicalDocumentValidatorTest.java | 4 ++- .../java/gov/cms/qpp/model/CacheType.java | 7 ++++ pom.xml | 6 ++++ 11 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 converter/src/test/java/gov/cms/qpp/CacheBuilder.java create mode 100644 converter/src/test/java/gov/cms/qpp/model/CacheType.java diff --git a/converter/pom.xml b/converter/pom.xml index 25ee94525..8d85b3d13 100644 --- a/converter/pom.xml +++ b/converter/pom.xml @@ -88,6 +88,12 @@ test + + com.github.ben-manes.caffeine + caffeine + test + + gov.cms.qpp.conversion test-commons diff --git a/converter/src/test/java/gov/cms/qpp/CacheBuilder.java b/converter/src/test/java/gov/cms/qpp/CacheBuilder.java new file mode 100644 index 000000000..8cc45fbf0 --- /dev/null +++ b/converter/src/test/java/gov/cms/qpp/CacheBuilder.java @@ -0,0 +1,35 @@ +package gov.cms.qpp; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import gov.cms.qpp.conversion.model.validation.ApmEntityIds; +import gov.cms.qpp.model.CacheType; + +import java.util.concurrent.TimeUnit; + +public class CacheBuilder { + private static Cache entityIdsCache; + + CacheBuilder() {} + + public static void buildEntityIdsCache() { + entityIdsCache = Caffeine.newBuilder() + .expireAfterWrite(5, TimeUnit.MINUTES) + .maximumSize(100) + .build(); + } + + public static ApmEntityIds getEntityIds(CacheType value) { + if (entityIdsCache == null) buildEntityIdsCache(); + if (entityIdsCache.getIfPresent(value) == null) { + ApmEntityIds entityData = null; + switch(value) { + case ApmEntityId -> entityData = new ApmEntityIds("test_apm_entity_ids.json"); + case ApmEntityIds -> entityData = new ApmEntityIds("test_apm_entity_ids.json","test_apm_entity_ids.json"); + case ApmPcfEntityIds -> entityData = new ApmEntityIds("test_apm_entity_ids.json","test_pcf_apm_entity_ids.json"); + } + entityIdsCache.put(value, entityData); + } + return entityIdsCache.getIfPresent(value); + } +} diff --git a/converter/src/test/java/gov/cms/qpp/acceptance/ClinicalDocumentExtensionTest.java b/converter/src/test/java/gov/cms/qpp/acceptance/ClinicalDocumentExtensionTest.java index 59ab93b55..7a75a1c4b 100644 --- a/converter/src/test/java/gov/cms/qpp/acceptance/ClinicalDocumentExtensionTest.java +++ b/converter/src/test/java/gov/cms/qpp/acceptance/ClinicalDocumentExtensionTest.java @@ -1,5 +1,7 @@ package gov.cms.qpp.acceptance; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -64,7 +66,7 @@ void invalidMessage() throws IOException { } private JsonWrapper convert(Path location) throws IOException { - ApmEntityIds apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json", "test_apm_entity_ids.json"); + ApmEntityIds apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityIds); Converter converter = new Converter(new PathSource(location), new Context(apmEntityIds)); return converter.transform(); } diff --git a/converter/src/test/java/gov/cms/qpp/acceptance/NegativePcfRoundTripTest.java b/converter/src/test/java/gov/cms/qpp/acceptance/NegativePcfRoundTripTest.java index caac40363..4f0e70a1c 100644 --- a/converter/src/test/java/gov/cms/qpp/acceptance/NegativePcfRoundTripTest.java +++ b/converter/src/test/java/gov/cms/qpp/acceptance/NegativePcfRoundTripTest.java @@ -1,5 +1,7 @@ package gov.cms.qpp.acceptance; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,7 +45,7 @@ public class NegativePcfRoundTripTest { @BeforeEach void setup() { - apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json", "test_apm_entity_ids.json"); + apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityIds); } @AfterEach diff --git a/converter/src/test/java/gov/cms/qpp/acceptance/Pcf2024AcceptanceTest.java b/converter/src/test/java/gov/cms/qpp/acceptance/Pcf2024AcceptanceTest.java index 2074373fa..5a909a803 100644 --- a/converter/src/test/java/gov/cms/qpp/acceptance/Pcf2024AcceptanceTest.java +++ b/converter/src/test/java/gov/cms/qpp/acceptance/Pcf2024AcceptanceTest.java @@ -19,13 +19,15 @@ import static com.google.common.truth.Truth.assertThat; import static gov.cms.qpp.acceptance.Util.getXml; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; public class Pcf2024AcceptanceTest { private static final Path BASE = Paths.get("src/test/resources/pcf/acceptance2024"); private static final Path SUCCESS = BASE.resolve("success"); private static final Path SUCCESS_WARNING = BASE.resolve("warning"); private static final Path FAILURE = BASE.resolve("failure"); - private final ApmEntityIds apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json","test_apm_entity_ids.json"); + private static final ApmEntityIds apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityIds); static Stream successData() { return getXml(SUCCESS); diff --git a/converter/src/test/java/gov/cms/qpp/acceptance/PcfRoundTripTest.java b/converter/src/test/java/gov/cms/qpp/acceptance/PcfRoundTripTest.java index 9e612f53f..a2d9e6e09 100644 --- a/converter/src/test/java/gov/cms/qpp/acceptance/PcfRoundTripTest.java +++ b/converter/src/test/java/gov/cms/qpp/acceptance/PcfRoundTripTest.java @@ -1,6 +1,8 @@ package gov.cms.qpp.acceptance; import com.fasterxml.jackson.databind.ObjectMapper; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -36,7 +38,7 @@ public class PcfRoundTripTest { @SuppressWarnings("unchecked") @BeforeAll static void setup() throws URISyntaxException, IOException { - ApmEntityIds apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json", "test_pcf_apm_entity_ids.json"); + ApmEntityIds apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmPcfEntityIds); URL sample = PcfRoundTripTest.class.getClassLoader() .getResource("pcf/success/PCF_Sample_QRDA-III.xml"); Path path = Paths.get(sample.toURI()); diff --git a/converter/src/test/java/gov/cms/qpp/acceptance/QualityMeasureIdRoundTripTest.java b/converter/src/test/java/gov/cms/qpp/acceptance/QualityMeasureIdRoundTripTest.java index 5c8260aa7..26fd2f6a5 100644 --- a/converter/src/test/java/gov/cms/qpp/acceptance/QualityMeasureIdRoundTripTest.java +++ b/converter/src/test/java/gov/cms/qpp/acceptance/QualityMeasureIdRoundTripTest.java @@ -1,6 +1,8 @@ package gov.cms.qpp.acceptance; import com.jayway.jsonpath.TypeRef; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,7 +53,7 @@ class QualityMeasureIdRoundTripTest { @BeforeEach void setup() { - apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json", "test_apm_entity_ids.json"); + apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityIds); MeasureConfigs.initMeasureConfigs(MeasureConfigs.TEST_MEASURE_DATA); } diff --git a/converter/src/test/java/gov/cms/qpp/conversion/model/validation/ApmEntityIdsTest.java b/converter/src/test/java/gov/cms/qpp/conversion/model/validation/ApmEntityIdsTest.java index 425eed5a2..4de15d286 100644 --- a/converter/src/test/java/gov/cms/qpp/conversion/model/validation/ApmEntityIdsTest.java +++ b/converter/src/test/java/gov/cms/qpp/conversion/model/validation/ApmEntityIdsTest.java @@ -1,5 +1,7 @@ package gov.cms.qpp.conversion.model.validation; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,7 +17,7 @@ class ApmEntityIdsTest { @BeforeEach void setUp() { - apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json"); + apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityId); } @Test diff --git a/converter/src/test/java/gov/cms/qpp/conversion/validate/PcfClinicalDocumentValidatorTest.java b/converter/src/test/java/gov/cms/qpp/conversion/validate/PcfClinicalDocumentValidatorTest.java index 33d851720..3b228de03 100644 --- a/converter/src/test/java/gov/cms/qpp/conversion/validate/PcfClinicalDocumentValidatorTest.java +++ b/converter/src/test/java/gov/cms/qpp/conversion/validate/PcfClinicalDocumentValidatorTest.java @@ -1,5 +1,7 @@ package gov.cms.qpp.conversion.validate; +import gov.cms.qpp.CacheBuilder; +import gov.cms.qpp.model.CacheType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,7 +26,7 @@ public class PcfClinicalDocumentValidatorTest { @BeforeEach void setUp() { - apmEntityIds = new ApmEntityIds("test_apm_entity_ids.json", "test_apm_entity_ids.json"); + apmEntityIds = CacheBuilder.getEntityIds(CacheType.ApmEntityIds); validator = new PcfClinicalDocumentValidator(new Context(apmEntityIds)); } diff --git a/converter/src/test/java/gov/cms/qpp/model/CacheType.java b/converter/src/test/java/gov/cms/qpp/model/CacheType.java new file mode 100644 index 000000000..04fef99a7 --- /dev/null +++ b/converter/src/test/java/gov/cms/qpp/model/CacheType.java @@ -0,0 +1,7 @@ +package gov.cms.qpp.model; + +public enum CacheType { + ApmEntityId, + ApmEntityIds, + ApmPcfEntityIds; +} diff --git a/pom.xml b/pom.xml index 94efb2ea4..4585084dc 100644 --- a/pom.xml +++ b/pom.xml @@ -223,6 +223,12 @@ 32.1.1-jre + + com.github.ben-manes.caffeine + caffeine + 3.1.8 + + com.google.truth truth