diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecorator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecorator.java index 9b6697a96..ff2247f0c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecorator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecorator.java @@ -37,15 +37,6 @@ public class ExplicitExpirySessionCacheDecorator implements SessionCache { return key; } - @Override - public String cacheSession(Supplier validationEngineSupplier) { - maintainSessionIds(null); - ValidationEngine validationEngine = validationEngineSupplier.get(); - String key = sessionCache.cacheSession(validationEngine); - sessionIds.add(key); - return key; - } - private void maintainSessionIds(String keyToAdd) { if (keyToAdd != null || sessionCache.sessionExists(keyToAdd)) { return; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/PassiveExpiringSessionCache.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/PassiveExpiringSessionCache.java index d68a7ae3a..32c7d70da 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/PassiveExpiringSessionCache.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/PassiveExpiringSessionCache.java @@ -45,12 +45,6 @@ public class PassiveExpiringSessionCache implements SessionCache { return generatedId; } - @Override - public String cacheSession(Supplier validationEngineSupplier) { - ValidationEngine engine = validationEngineSupplier.get(); - return this.cacheSession(engine); - } - /** * Stores the initialized {@link ValidationEngine} in the cache with the passed in id as the key. If a null key is * passed in, a new key is generated and returned. diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/SessionCache.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/SessionCache.java index 73be98c49..f39b614c9 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/SessionCache.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/SessionCache.java @@ -15,14 +15,6 @@ public interface SessionCache { */ String cacheSession(ValidationEngine validationEngine); - /** - * Uses the passed {@link Supplier} to generate a {@link ValidationEngine} and add it to the cache. Returns the - * session id that will be associated with the generated instance. - * @param validationEngineSupplier {@link Supplier} of {@link ValidationEngine} - * @return The {@link String} id associated with the stored instance. - */ - String cacheSession(Supplier validationEngineSupplier); - /** * Stores the initialized {@link ValidationEngine} in the cache with the passed in id as the key. If a null key is * passed in, a new key is generated and returned. diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index f85a01122..6f412397d 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -490,19 +490,10 @@ public class ValidationService { System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator."); } - // Send a supplier instead of instantiating. This will permit the sessionCache to manage existing sessions (drop - // or expire old sessions as needed) - sessionId = sessionCache.cacheSession(() -> { + ValidationEngine validationEngine = getValidationEngineFromCliContext(cliContext, definitions, tt); + sessionId = sessionCache.cacheSession(validationEngine); + System.out.println("Cached new session. Cache size = " + sessionCache.getSessionIds().size()); - try { - return buildValidationEngine(cliContext, definitions, tt); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - - }); } else { System.out.println("Cached session exists for session id " + sessionId + ", returning stored validator session id. Cache size = " + sessionCache.getSessionIds().size()); } diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecoratorTest.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecoratorTest.java index 63db66546..096bf1741 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecoratorTest.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/services/ExplicitExpirySessionCacheDecoratorTest.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import static org.mockito.Mockito.mock; -public class MaxSizeSessionCacheDecoratorTest { +public class ExplicitExpirySessionCacheDecoratorTest { private List getMockedEngines(int count) { List engines = new ArrayList<>(); @@ -71,17 +71,6 @@ public class MaxSizeSessionCacheDecoratorTest { Assertions.assertFalse(sessionCache.expireOldestSession()); } - @Test - public void producerAddTest() { - ExplicitExpirySessionCacheDecorator maxSizeSessionCacheDecorator = new ExplicitExpirySessionCacheDecorator(new PassiveExpiringSessionCache()); - ValidationEngine producedEngine = mock(ValidationEngine.class); - String sessionId = maxSizeSessionCacheDecorator.cacheSession(() -> { - return producedEngine; - }); - Assertions.assertEquals(1, maxSizeSessionCacheDecorator.getSessionIds().size()); - Assertions.assertSame(producedEngine, maxSizeSessionCacheDecorator.fetchSessionValidatorEngine(sessionId)); - } - private String getKeyByIndex(LinkedHashMap engineMap, int index) { return (String) engineMap.keySet().toArray()[index]; }