From 7ffbe9505b83de548675ad79757bfecda44a525d Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 16 Jan 2019 23:35:14 -0500 Subject: [PATCH 01/11] Prototype. Not working yet. --- .../interceptor/InterceptorRegistry.java | 34 +++++++++ .../module/cache/SubscriptionRegistry.java | 5 ++ .../SubscriptionMatchingSubscriber.java | 13 +++- .../subscription/module/LatchedService.java | 69 +++++++++++++++++++ ...kingQueueSubscribableChannelDstu3Test.java | 39 +++++++++-- .../SubscriptionCheckingSubscriberTest.java | 15 ++-- .../SubscriptionMatchingSubscriberTest.java | 17 +++-- 7 files changed, 172 insertions(+), 20 deletions(-) create mode 100644 hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/interceptor/InterceptorRegistry.java create mode 100644 hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/interceptor/InterceptorRegistry.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/interceptor/InterceptorRegistry.java new file mode 100644 index 00000000000..99651e462ba --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/interceptor/InterceptorRegistry.java @@ -0,0 +1,34 @@ +package ca.uhn.fhir.jpa.searchparam.interceptor; + +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.function.Predicate; + +import static javolution.testing.TestContext.assertTrue; + +@Component +public class InterceptorRegistry { + private final Map>> interceptorMap = new HashMap<>(); + + public void addInterceptor(String key, Predicate interceptor) { + interceptorMap.computeIfAbsent(key, entry -> new ArrayList<>()).add(interceptor); + } + + public void removeInterceptor(String key, Predicate interceptor) { + assertTrue(interceptorMap.get(key).remove(interceptor)); + } + + // TODO KHS this feels like it should be a one-line lambda + public Boolean trigger(String key, Object object) { + List> predicates = interceptorMap.get(key); + if (predicates != null) { + for (Predicate predicate : predicates) { + if (!predicate.test(object)) { + return false; + } + } + } + return true; + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java index 363a7bcea9b..f746995bd8f 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.module.cache; */ import ca.uhn.fhir.jpa.model.entity.ModelConfig; +import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -47,6 +48,7 @@ import java.util.Optional; @Component public class SubscriptionRegistry { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionRegistry.class); + public static final String INTERCEPTOR_POST_ACTIVATED = "SubscriptionRegistry.postActivated"; @Autowired SubscriptionCanonicalizer mySubscriptionCanonicalizer; @@ -56,6 +58,8 @@ public class SubscriptionRegistry { SubscriptionChannelFactory mySubscriptionDeliveryChannelFactory; @Autowired ModelConfig myModelConfig; + @Autowired + InterceptorRegistry myInterceptorRegistry; private final ActiveSubscriptionCache myActiveSubscriptionCache = new ActiveSubscriptionCache(); @@ -97,6 +101,7 @@ public class SubscriptionRegistry { deliveryHandler.ifPresent(activeSubscription::register); myActiveSubscriptionCache.put(subscriptionId, activeSubscription); + myInterceptorRegistry.trigger(INTERCEPTOR_POST_ACTIVATED, theSubscription); return canonicalized; } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriber.java index 1acf9bbe662..c540936a98f 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriber.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; @@ -30,9 +31,9 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,6 +45,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; @Service public class SubscriptionMatchingSubscriber implements MessageHandler { private Logger ourLog = LoggerFactory.getLogger(SubscriptionMatchingSubscriber.class); + public static final String INTERCEPTOR_PRE_PROCESSED = "SubscriptionMatchingSubscriber.preProcessed"; + public static final String INTERCEPTOR_POST_PROCESSED = "SubscriptionMatchingSubscriber.postProcessed"; @Autowired private ISubscriptionMatcher mySubscriptionMatcher; @@ -51,6 +54,8 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { private FhirContext myFhirContext; @Autowired private SubscriptionRegistry mySubscriptionRegistry; + @Autowired + private InterceptorRegistry myInterceptorRegistry; @Override public void handleMessage(Message theMessage) throws MessagingException { @@ -66,6 +71,9 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { } public void matchActiveSubscriptionsAndDeliver(ResourceModifiedMessage theMsg) { + if (!myInterceptorRegistry.trigger(INTERCEPTOR_PRE_PROCESSED, theMsg)) { + return; + } switch (theMsg.getOperationType()) { case CREATE: case UPDATE: @@ -135,5 +143,6 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { ourLog.warn("Do not have delivery channel for subscription {}", nextActiveSubscription.getIdElement(myFhirContext)); } } + myInterceptorRegistry.trigger(INTERCEPTOR_POST_PROCESSED, theMsg); } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java new file mode 100644 index 00000000000..359621338c9 --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java @@ -0,0 +1,69 @@ +package ca.uhn.fhir.jpa.subscription.module; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class LatchedService implements Predicate { + private static final Logger ourLog = LoggerFactory.getLogger(LatchedService.class); + private final String name; + + private CountDownLatch myCountdownLatch; + private AtomicReference myFailure; + private AtomicReference> myCalledWith; + + public LatchedService(String name) { + this.name = name; + } + + public void countdown() { + if (myCountdownLatch == null) { + myFailure.set(name + " latch countdown() called before expectedCount set."); + } else if (myCountdownLatch.getCount() <= 0) { + myFailure.set(name + " latch countdown() called "+ (1 - myCountdownLatch.getCount()) + " more times than expected."); + } + ourLog.info("{} counting down {}", name, myCountdownLatch); + myCountdownLatch.countDown(); + } + + public void setExpectedCount(int count) { + myFailure = new AtomicReference<>(); + myCalledWith = new AtomicReference<>(new ArrayList<>()); + myCountdownLatch = new CountDownLatch(count); + } + + public void awaitExpected() throws InterruptedException { + awaitExpectedWithTimeout(10); + } + + public void awaitExpectedWithTimeout(int timeoutSecond) throws InterruptedException { + assertTrue(name+" latch timed out waiting "+timeoutSecond+" seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); + + if (myFailure.get() != null) { + String error = myFailure.get(); + error += "\nLatch called with values: "+myCalledWith.get().stream().map(Object::toString).collect(Collectors.joining(", ")); + throw new AssertionError(error); + } + } + + @Override + public boolean test(Object object) { + this.countdown(); + if (myCalledWith.get() != null) { + myCalledWith.get().add(object); + } + return true; + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index 8b3186ea951..b061ece857e 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -1,10 +1,14 @@ package ca.uhn.fhir.jpa.subscription.module.standalone; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; +import ca.uhn.fhir.jpa.subscription.module.LatchedService; import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionChannelFactory; +import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriber; import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriberTest; import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.ResourceParam; @@ -21,6 +25,7 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -36,6 +41,7 @@ import java.util.List; public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends BaseSubscriptionDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionMatchingSubscriberTest.class); + protected static ObservationListener ourObservationListener; @Autowired FhirContext myFhirContext; @@ -43,6 +49,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base StandaloneSubscriptionMessageHandler myStandaloneSubscriptionMessageHandler; @Autowired SubscriptionChannelFactory mySubscriptionChannelFactory; + @Autowired + InterceptorRegistry myInterceptorRegistry; protected String myCode = "1000000050"; @@ -56,6 +64,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base private static SubscribableChannel ourSubscribableChannel; private List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); private long idCounter = 0; + protected LatchedService mySubscriptionMatchingPost = new LatchedService(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED); + protected LatchedService mySubscriptionActivatedPost = new LatchedService(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED); @Before public void beforeReset() { @@ -66,6 +76,14 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base ourSubscribableChannel = mySubscriptionChannelFactory.newDeliveryChannel("test", Subscription.SubscriptionChannelType.RESTHOOK.toCode().toLowerCase()); ourSubscribableChannel.subscribe(myStandaloneSubscriptionMessageHandler); } + myInterceptorRegistry.addInterceptor(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED, mySubscriptionMatchingPost); + myInterceptorRegistry.addInterceptor(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED, mySubscriptionActivatedPost); + } + + @After + public void cleanup() { + myInterceptorRegistry.removeInterceptor(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED, mySubscriptionActivatedPost); + myInterceptorRegistry.removeInterceptor(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED, mySubscriptionMatchingPost); } public T sendResource(T theResource) { @@ -77,8 +95,10 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base protected Subscription sendSubscription(String theCriteria, String thePayload, String theEndpoint) throws InterruptedException { Subscription subscription = returnedActiveSubscription(theCriteria, thePayload, theEndpoint); - - return sendResource(subscription); + mySubscriptionActivatedPost.setExpectedCount(1); + Subscription retval = sendResource(subscription); + mySubscriptionActivatedPost.awaitExpected(); + return retval; } protected Subscription returnedActiveSubscription(String theCriteria, String thePayload, String theEndpoint) { @@ -122,8 +142,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base ourListenerRestServer = new RestfulServer(FhirContext.forDstu3()); ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; - ObservationListener obsListener = new ObservationListener(); - ourListenerRestServer.setResourceProviders(obsListener); + ourObservationListener = new ObservationListener(); + ourListenerRestServer.setResourceProviders(ourObservationListener); ourListenerServer = new Server(ourListenerPort); @@ -145,6 +165,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base public static class ObservationListener implements IResourceProvider { + private LatchedService updateLatch = new LatchedService("Observation Update"); + @Create public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { ourLog.info("Received Listener Create"); @@ -162,8 +184,17 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base public MethodOutcome update(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { ourContentTypes.add(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE).replaceAll(";.*", "")); ourUpdatedObservations.add(theObservation); + updateLatch.countdown(); ourLog.info("Received Listener Update (now have {} updates)", ourUpdatedObservations.size()); return new MethodOutcome(new IdType("Observation/1"), false); } + + public void setExpectedCount(int count) { + updateLatch.setExpectedCount(count); + } + + public void awaitExpected() throws InterruptedException { + updateLatch.awaitExpected(); + } } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java index 2b656d1f79d..58e5f696f38 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java @@ -25,10 +25,10 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); + ourObservationListener.awaitExpected(); - waitForSize(0, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); } @@ -43,10 +43,10 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); + ourObservationListener.awaitExpected(); - waitForSize(0, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); } @@ -61,9 +61,10 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(0); + mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - - waitForSize(0, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + mySubscriptionMatchingPost.awaitExpected(); + ourObservationListener.awaitExpected(); } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java index 2a8e605a577..5eb8e73db12 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java @@ -1,10 +1,12 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; +import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.standalone.BaseBlockingQueueSubscribableChannelDstu3Test; import ca.uhn.fhir.rest.api.Constants; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import static org.junit.Assert.assertEquals; @@ -25,10 +27,10 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); + ourObservationListener.awaitExpected(); - waitForSize(0, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); } @@ -43,10 +45,10 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); + ourObservationListener.awaitExpected(); - waitForSize(0, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); } @@ -61,9 +63,10 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + ourObservationListener.setExpectedCount(0); + mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - - waitForSize(0, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + mySubscriptionMatchingPost.awaitExpected(); + ourObservationListener.awaitExpected(); } } From b3bdbea19c61fc068be356cb529c4352f6f5b726 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Sun, 20 Jan 2019 09:39:34 -0500 Subject: [PATCH 02/11] Merge branch 'master' into windows-fixes quickly update tests to new interceptor --- .../jpa/model/interceptor/api/Pointcut.java | 7 ++++-- .../module/cache/SubscriptionRegistry.java | 6 +++-- .../module/config/BaseSubscriptionConfig.java | 2 +- .../subscription/module/LatchedService.java | 24 +++++++++++-------- ...kingQueueSubscribableChannelDstu3Test.java | 14 +++++------ .../SubscriptionMatchingSubscriberTest.java | 2 -- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java index 462d864c454..1a251114b51 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java @@ -67,9 +67,12 @@ public enum Pointcut { *
  • ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage
  • * */ - SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED("ResourceModifiedMessage") + SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED("ResourceModifiedMessage"), - ; + // FIXME KHS + SUBSCRIPTION_AFTER_SUBSCRIPTION_MATCHING("ResourceModifiedMessage"), + // FIXME KHS + SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED("CanonicalSubscription"); private final List myParameterTypes; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java index f746995bd8f..72d9249b4ce 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java @@ -21,7 +21,8 @@ package ca.uhn.fhir.jpa.subscription.module.cache; */ import ca.uhn.fhir.jpa.model.entity.ModelConfig; -import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; +import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -101,7 +102,8 @@ public class SubscriptionRegistry { deliveryHandler.ifPresent(activeSubscription::register); myActiveSubscriptionCache.put(subscriptionId, activeSubscription); - myInterceptorRegistry.trigger(INTERCEPTOR_POST_ACTIVATED, theSubscription); + + myInterceptorRegistry.callHooks(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED, canonicalized); return canonicalized; } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java index b484886ab18..a89870c7b0e 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java @@ -30,7 +30,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @Configuration @EnableScheduling -@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.searchparam", "ca.uhn.fhir.jpa.subscription.module"}) +@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.searchparam", "ca.uhn.fhir.jpa.subscription.module", "ca.uhn.fhir.jpa.model.interceptor.executor"}) public abstract class BaseSubscriptionConfig { public abstract FhirContext fhirContext(); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java index 359621338c9..cca0c509d4b 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java @@ -1,5 +1,8 @@ package ca.uhn.fhir.jpa.subscription.module; +import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; +import ca.uhn.fhir.jpa.model.interceptor.api.IAnonymousLambdaHook; +import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,24 +11,26 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class LatchedService implements Predicate { +public class LatchedService implements IAnonymousLambdaHook { private static final Logger ourLog = LoggerFactory.getLogger(LatchedService.class); private final String name; private CountDownLatch myCountdownLatch; private AtomicReference myFailure; - private AtomicReference> myCalledWith; + private AtomicReference> myCalledWith; - public LatchedService(String name) { - this.name = name; + public LatchedService(Pointcut thePointcut) { + this.name = thePointcut.name(); + } + + public LatchedService(String theName) { + this.name = theName; } public void countdown() { @@ -49,7 +54,7 @@ public class LatchedService implements Predicate { } public void awaitExpectedWithTimeout(int timeoutSecond) throws InterruptedException { - assertTrue(name+" latch timed out waiting "+timeoutSecond+" seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); + assertTrue(name +" latch timed out waiting "+timeoutSecond+" seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); if (myFailure.get() != null) { String error = myFailure.get(); @@ -59,11 +64,10 @@ public class LatchedService implements Predicate { } @Override - public boolean test(Object object) { + public void invoke(HookParams theArgs) { this.countdown(); if (myCalledWith.get() != null) { - myCalledWith.get().add(object); + myCalledWith.get().add(theArgs); } - return true; } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index b061ece857e..88a16c83ee6 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -1,7 +1,8 @@ package ca.uhn.fhir.jpa.subscription.module.standalone; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; +import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.jpa.subscription.module.LatchedService; import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage; @@ -64,8 +65,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base private static SubscribableChannel ourSubscribableChannel; private List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); private long idCounter = 0; - protected LatchedService mySubscriptionMatchingPost = new LatchedService(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED); - protected LatchedService mySubscriptionActivatedPost = new LatchedService(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED); + protected LatchedService mySubscriptionMatchingPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_MATCHING); + protected LatchedService mySubscriptionActivatedPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED); @Before public void beforeReset() { @@ -76,14 +77,13 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base ourSubscribableChannel = mySubscriptionChannelFactory.newDeliveryChannel("test", Subscription.SubscriptionChannelType.RESTHOOK.toCode().toLowerCase()); ourSubscribableChannel.subscribe(myStandaloneSubscriptionMessageHandler); } - myInterceptorRegistry.addInterceptor(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED, mySubscriptionMatchingPost); - myInterceptorRegistry.addInterceptor(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED, mySubscriptionActivatedPost); + myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_MATCHING, mySubscriptionMatchingPost); + myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED, mySubscriptionActivatedPost); } @After public void cleanup() { - myInterceptorRegistry.removeInterceptor(SubscriptionRegistry.INTERCEPTOR_POST_ACTIVATED, mySubscriptionActivatedPost); - myInterceptorRegistry.removeInterceptor(SubscriptionMatchingSubscriber.INTERCEPTOR_POST_PROCESSED, mySubscriptionMatchingPost); + myInterceptorRegistry.clearAnonymousHookForUnitTest(); } public T sendResource(T theResource) { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java index 5eb8e73db12..0bd4ac035c1 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java @@ -1,12 +1,10 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; -import ca.uhn.fhir.jpa.searchparam.interceptor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.standalone.BaseBlockingQueueSubscribableChannelDstu3Test; import ca.uhn.fhir.rest.api.Constants; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import static org.junit.Assert.assertEquals; From b4350bbdae408658573ff8c1fa2e39cd75a2caa7 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 21 Jan 2019 11:05:53 -0500 Subject: [PATCH 03/11] Working through failed tests. Consolidating sleep calls --- .../java/ca/uhn/fhir/jpa/util/TestUtil.java | 17 ++++++- .../FhirResourceDaoDstu3SearchNoFtTest.java | 17 ++++--- ...rResourceDaoDstu3SearchPageExpiryTest.java | 9 ++-- .../dao/dstu3/FhirResourceDaoDstu3Test.java | 6 +-- .../dstu3/FhirResourceDaoDstu3UpdateTest.java | 2 +- .../FhirResourceDaoDstu3ValidateTest.java | 6 +-- .../r4/FhirResourceDaoR4SearchNoFtTest.java | 32 ++++++++----- .../FhirResourceDaoR4SearchNoHashesTest.java | 47 ++++++++++--------- ...FhirResourceDaoR4SearchPageExpiryTest.java | 10 ++-- .../dao/r4/FhirResourceDaoR4UpdateTest.java | 13 +++-- .../r4/ResourceProviderR4CacheTest.java | 3 +- .../provider/r4/ResourceProviderR4Test.java | 4 +- .../module/config/BaseSubscriptionConfig.java | 2 +- .../subscription/module/LatchedService.java | 2 - ...kingQueueSubscribableChannelDstu3Test.java | 8 ++-- 15 files changed, 103 insertions(+), 75 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java index 0f41138cc20..1cd6d7098cf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java @@ -25,11 +25,15 @@ import com.google.common.collect.ImmutableSet; import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath.ClassInfo; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.InstantType; +import org.hl7.fhir.r4.model.Patient; import javax.persistence.*; import java.io.IOException; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -165,10 +169,21 @@ public class TestUtil { ourLog.info("Sleeping for {}ms", timeToSleep); Thread.sleep(timeToSleep); } catch (InterruptedException theE) { - theE.printStackTrace(); + ourLog.error("Interrupted", theE); } } } + public static void clearAllStaticFieldsForUnitTest() { + ca.uhn.fhir.util.TestUtil.clearAllStaticFieldsForUnitTest(); + } + + public static InstantType getTimestamp(IBaseResource resource) { + return new InstantType(new Date(resource.getMeta().getLastUpdated().getTime())); + } + + public static void sleepOneClick() { + sleepAtLeast(1); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 5ebda85d4df..2e7d2c50ff0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.jpa.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.dstu3.model.*; @@ -40,7 +41,6 @@ import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @@ -667,6 +667,9 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } long betweenTime = System.currentTimeMillis(); + + TestUtil.sleepOneClick(); + IIdType id2; { Patient patient = new Patient(); @@ -1199,7 +1202,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { int sleep = 100; long start = System.currentTimeMillis(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(sleep); + TestUtil.sleepAtLeast(sleep); IIdType id1a; { @@ -1218,7 +1221,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { ourLog.info("Res 2: {}", myPatientDao.read(id1a, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); ourLog.info("Res 3: {}", myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(sleep); + TestUtil.sleepAtLeast(sleep); long end = System.currentTimeMillis(); SearchParameterMap map; @@ -1615,18 +1618,18 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { obs01.setSubject(new Reference(patientId01)); IIdType obsId01 = myObservationDao.create(obs01, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date between = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(locId01)); IIdType obsId02 = myObservationDao.create(obs02, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date after = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 }); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchPageExpiryTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchPageExpiryTest.java index 90b19eaaa53..779e8175506 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchPageExpiryTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchPageExpiryTest.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.jpa.dao.data.ISearchDao; import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoR4SearchPageExpiryTest; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.StringParam; @@ -29,7 +30,6 @@ import org.springframework.transaction.support.TransactionTemplate; import java.util.Date; import java.util.concurrent.atomic.AtomicLong; -import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.*; @@ -105,8 +105,7 @@ public class FhirResourceDaoDstu3SearchPageExpiryTest extends BaseJpaDstu3Test { } assertEquals(searchUuid1, searchUuid2); - sleepAtLeast(501); - + TestUtil.sleepAtLeast(501); // We're now past 500ms so we shouldn't reuse the search final String searchUuid3; @@ -277,7 +276,7 @@ public class FhirResourceDaoDstu3SearchPageExpiryTest extends BaseJpaDstu3Test { } assertEquals(searchUuid1, searchUuid2); - sleepAtLeast(501); + TestUtil.sleepAtLeast(501); // We're now past 500ms so we shouldn't reuse the search @@ -363,7 +362,7 @@ public class FhirResourceDaoDstu3SearchPageExpiryTest extends BaseJpaDstu3Test { } }); if (search == null) { - sleepAtLeast(100); + TestUtil.sleepAtLeast(100); } } assertNotNull("Search " + bundleProvider.getUuid() + " not found on disk after 10 seconds", search); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java index d8b94a50f9f..0d41ad30e2c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java @@ -2867,21 +2867,21 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.addName().setFamily(methodName); IIdType id1 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName); p.addName().setFamily(methodName); IIdType id2 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); p = new Patient(); p.addIdentifier().setSystem("urn:system3").setValue(methodName); p.addName().setFamily(methodName); IIdType id3 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); p = new Patient(); p.addIdentifier().setSystem("urn:system4").setValue(methodName); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java index 51089f210d4..ae9c5f521c9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java @@ -306,7 +306,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { assertEquals("1", outcome.getId().getVersionIdPart()); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date now = new Date(); Patient retrieved = myPatientDao.read(outcome.getId(), mySrd); InstantType updated = retrieved.getMeta().getLastUpdatedElement().copy(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java index 9c60aea71f1..9e297d4d916 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; @@ -11,7 +12,6 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; @@ -25,8 +25,6 @@ import org.junit.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; -import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; - public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class); @@ -64,7 +62,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { MethodOutcome results = myQuestionnaireResponseDao.validate(qr, null, null, null, null, null, null); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(results.getOperationOutcome())); - sleepAtLeast(2500); + TestUtil.sleepAtLeast(2500); try { myQuestionnaireResponseDao.validate(qr, null, null, null, null, null, null); fail(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java index f49b54e57bf..bfcbdc6a22c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java @@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.jpa.model.entity.*; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.parser.StrictErrorHandler; @@ -12,7 +13,6 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; @@ -151,16 +151,16 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { List ids; Date beforeAll = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Organization org = new Organization(); org.setName("O1"); org.setId("O1"); myOrganizationDao.update(org); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date beforePatient = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Patient p = new Patient(); p.setId("P1"); @@ -168,7 +168,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { p.setManagingOrganization(new Reference("Organization/O1")); myPatientDao.update(p); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date afterAll = new Date(); // Search with between date (should still return Organization even though @@ -216,7 +216,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { myOrganizationDao.update(org); Date beforeAll = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Patient p = new Patient(); p.setId("P1"); @@ -224,17 +224,17 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { p.setManagingOrganization(new Reference("Organization/O1")); myPatientDao.update(p); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date beforeOrg = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); org = new Organization(); org.setActive(true); org.setId("O1"); myOrganizationDao.update(org); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date afterAll = new Date(); // Everything should come back @@ -890,6 +890,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } long betweenTime = System.currentTimeMillis(); + + TestUtil.sleepOneClick(); + IIdType id2; { Patient patient = new Patient(); @@ -1266,6 +1269,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { Date betweenTime = new Date(); + TestUtil.sleepOneClick(); + IIdType id2; { Patient patient = new Patient(); @@ -1439,10 +1444,10 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - int sleep = 100; long start = System.currentTimeMillis(); - Thread.sleep(sleep); + + TestUtil.sleepOneClick(); IIdType id1a; { @@ -1461,7 +1466,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { ourLog.info("Res 2: {}", myPatientDao.read(id1a, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); ourLog.info("Res 3: {}", myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); - Thread.sleep(sleep); + TestUtil.sleepOneClick(); + long end = System.currentTimeMillis(); SearchParameterMap map; @@ -1487,7 +1493,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { map = new SearchParameterMap(); map.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN, startDateTime.getValue()), - new DateParam(ParamPrefixEnum.LESSTHAN, myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValue()))); + new DateParam(ParamPrefixEnum.LESSTHAN, TestUtil.getTimestamp(myPatientDao.read(id1b, mySrd))))); ourLog.info("Searching: {}", map.getLastUpdated()); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a)); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java index ff2144142d3..7810878bc0e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java @@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.jpa.model.entity.*; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.parser.StrictErrorHandler; @@ -12,7 +13,6 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; @@ -153,16 +153,16 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { List ids; Date beforeAll = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Organization org = new Organization(); org.setName("O1"); org.setId("O1"); myOrganizationDao.update(org); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date beforePatient = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Patient p = new Patient(); p.setId("P1"); @@ -170,7 +170,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { p.setManagingOrganization(new Reference("Organization/O1")); myPatientDao.update(p); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date afterAll = new Date(); // Search with between date (should still return Organization even though @@ -218,7 +218,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { myOrganizationDao.update(org); Date beforeAll = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Patient p = new Patient(); p.setId("P1"); @@ -226,17 +226,17 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { p.setManagingOrganization(new Reference("Organization/O1")); myPatientDao.update(p); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date beforeOrg = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); org = new Organization(); org.setActive(true); org.setId("O1"); myOrganizationDao.update(org); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100); + ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick(); Date afterAll = new Date(); // Everything should come back @@ -891,6 +891,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); long betweenTime = System.currentTimeMillis(); IIdType id2; { @@ -1266,6 +1267,8 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + Date betweenTime = new Date(); IIdType id2; @@ -1349,8 +1352,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { public void testSearchLastUpdatedParam() throws InterruptedException { String methodName = "testSearchLastUpdatedParam"; - int sleep = 100; - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(sleep); + TestUtil.sleepOneClick(); DateTimeType beforeAny = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI); IIdType id1a; @@ -1368,9 +1370,9 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { id1b = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1100); + TestUtil.sleepAtLeast(1100); DateTimeType beforeR2 = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(1100); + TestUtil.sleepAtLeast(1100); IIdType id2; { @@ -1441,10 +1443,8 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - int sleep = 100; - long start = System.currentTimeMillis(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(sleep); + TestUtil.sleepOneClick(); IIdType id1a; { @@ -1463,7 +1463,8 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { ourLog.info("Res 2: {}", myPatientDao.read(id1a, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); ourLog.info("Res 3: {}", myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(sleep); + TestUtil.sleepOneClick(); + long end = System.currentTimeMillis(); SearchParameterMap map; @@ -1489,7 +1490,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { map = new SearchParameterMap(); map.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN, startDateTime.getValue()), - new DateParam(ParamPrefixEnum.LESSTHAN, myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValue()))); + new DateParam(ParamPrefixEnum.LESSTHAN, TestUtil.getTimestamp(myPatientDao.read(id1b, mySrd))))); ourLog.info("Searching: {}", map.getLastUpdated()); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a)); } @@ -1860,14 +1861,14 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { IIdType obsId01 = myObservationDao.create(obs01, mySrd).getId().toUnqualifiedVersionless(); Date between = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(10); + TestUtil.sleepOneClick(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(locId01)); IIdType obsId02 = myObservationDao.create(obs02, mySrd).getId().toUnqualifiedVersionless(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(10); + TestUtil.sleepOneClick(); Date after = new Date(); ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", patientId01, locId01, obsId01, obsId02); @@ -1991,14 +1992,14 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } Date between = new Date(); - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(10); + TestUtil.sleepOneClick(); { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily("Tester_testSearchStringParam").addGiven("John"); pid2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(10); + TestUtil.sleepOneClick(); Date after = new Date(); SearchParameterMap params; @@ -2945,6 +2946,8 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { tag1id = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + Date betweenDate = new Date(); IIdType tag2id; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java index aa99e4dbb4b..1dd6c8a479d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.jpa.dao.data.ISearchDao; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.SearchStatusEnum; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.StringParam; @@ -29,7 +30,6 @@ import javax.annotation.Nullable; import java.util.Date; import java.util.concurrent.atomic.AtomicLong; -import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.*; @@ -100,7 +100,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { } assertEquals(searchUuid1, searchUuid2); - sleepAtLeast(501); + TestUtil.sleepAtLeast(501); // We're now past 500ms so we shouldn't reuse the search @@ -274,7 +274,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { } assertEquals(searchUuid1, searchUuid2); - sleepAtLeast(501); + TestUtil.sleepAtLeast(501); // We're now past 500ms so we shouldn't reuse the search @@ -360,7 +360,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { } }); if (search == null) { - sleepAtLeast(100); + TestUtil.sleepAtLeast(100); } } assertNotNull("Search " + bundleProvider.getUuid() + " not found on disk after 10 seconds", search); @@ -407,7 +407,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { for (int i = 0; i < 20 && search == null; i++) { search = theSearchEntityDao.findByUuid(theUuid); if (search == null || search.getStatus() == SearchStatusEnum.LOADING) { - sleepAtLeast(100); + TestUtil.sleepAtLeast(100); } } assertNotNull(search); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java index aa6008ccc73..06e3dc75327 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -12,7 +13,6 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; @@ -314,11 +314,14 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { assertEquals("1", outcome.getId().getVersionIdPart()); Date now = new Date(); + + TestUtil.sleepOneClick(); + Patient retrieved = myPatientDao.read(outcome.getId(), mySrd); - InstantType updated = retrieved.getMeta().getLastUpdatedElement().copy(); + InstantType updated = TestUtil.getTimestamp(retrieved); assertTrue(updated.before(now)); - Thread.sleep(1000); + TestUtil.sleepOneClick(); reset(myInterceptor); retrieved.getIdentifier().get(0).setValue("002"); @@ -341,11 +344,11 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { assertEquals("2", retrieved2.getIdElement().getVersionIdPart()); assertEquals("002", retrieved2.getIdentifier().get(0).getValue()); - InstantType updated2 = retrieved2.getMeta().getLastUpdatedElement(); + InstantType updated2 = TestUtil.getTimestamp(retrieved2); assertTrue(updated2.after(now)); assertTrue(updated2.before(now2)); - Thread.sleep(2000); + TestUtil.sleepOneClick(); /* * Get history diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java index 1792f9fe300..40c0b4012e9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java @@ -2,12 +2,12 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.rest.api.CacheControlDirective; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Patient; import org.junit.After; @@ -159,6 +159,7 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { ourClient.create().resource(pt1).execute(); Date beforeFirst = new Date(); + TestUtil.sleepOneClick(); Bundle results1 = ourClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); assertEquals(1, results1.getEntry().size()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index 72f422b8a8b..2faa1d58a5e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -37,6 +37,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.api.PreferReturnEnum; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -116,7 +117,6 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; @SuppressWarnings("Duplicates") @@ -3659,6 +3659,8 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Search search1 = newTxTemplate().execute(theStatus -> mySearchEntityDao.findByUuid(uuid1)); Date lastReturned1 = search1.getSearchLastReturned(); + TestUtil.sleepOneClick(); + Bundle result2 = ourClient .search() .forResource("Organization") diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java index a89870c7b0e..b484886ab18 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java @@ -30,7 +30,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @Configuration @EnableScheduling -@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.searchparam", "ca.uhn.fhir.jpa.subscription.module", "ca.uhn.fhir.jpa.model.interceptor.executor"}) +@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.searchparam", "ca.uhn.fhir.jpa.subscription.module"}) public abstract class BaseSubscriptionConfig { public abstract FhirContext fhirContext(); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java index cca0c509d4b..6e638bdfd36 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java @@ -13,8 +13,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class LatchedService implements IAnonymousLambdaHook { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index 88a16c83ee6..4cb096dba32 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -65,8 +65,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base private static SubscribableChannel ourSubscribableChannel; private List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); private long idCounter = 0; - protected LatchedService mySubscriptionMatchingPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_MATCHING); - protected LatchedService mySubscriptionActivatedPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED); + protected LatchedService mySubscriptionMatchingPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED); + protected LatchedService mySubscriptionActivatedPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED); @Before public void beforeReset() { @@ -77,8 +77,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base ourSubscribableChannel = mySubscriptionChannelFactory.newDeliveryChannel("test", Subscription.SubscriptionChannelType.RESTHOOK.toCode().toLowerCase()); ourSubscribableChannel.subscribe(myStandaloneSubscriptionMessageHandler); } - myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_MATCHING, mySubscriptionMatchingPost); - myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_SUBSCRIPTION_ACTIVATED, mySubscriptionActivatedPost); + myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED, mySubscriptionMatchingPost); + myInterceptorRegistry.registerAnonymousHookForUnitTest(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED, mySubscriptionActivatedPost); } @After From a6d1cc56c7ee7962c8cfdfb1a79d90ec15a47344 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 21 Jan 2019 16:58:14 -0500 Subject: [PATCH 04/11] added maxRetriex extension to canonical subscription --- .../module/CanonicalSubscription.java | 29 ++++++++++++++----- .../cache/SubscriptionCanonicalizer.java | 17 +++++++++-- .../module/cache/SubscriptionConstants.java | 6 ++++ ...scriptionDeliveringRestHookSubscriber.java | 3 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java index f240b810453..707a75aabc4 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java @@ -295,6 +295,8 @@ public class CanonicalSubscription implements Serializable, Cloneable { private boolean myStripVersionId; @JsonProperty("deliverLatestVersion") private boolean myDeliverLatestVersion; + @JsonProperty("maxRetries") + private int myMaxRetries; /** * Constructor @@ -311,6 +313,23 @@ public class CanonicalSubscription implements Serializable, Cloneable { myDeliverLatestVersion = theDeliverLatestVersion; } + + public boolean isStripVersionId() { + return myStripVersionId; + } + + public void setStripVersionId(boolean theStripVersionId) { + myStripVersionId = theStripVersionId; + } + + public int getMaxRetries() { + return myMaxRetries; + } + + public void setMaxRetries(int theMaxRetries) { + myMaxRetries = theMaxRetries; + } + @Override public boolean equals(Object theO) { if (this == theO) return true; @@ -322,6 +341,7 @@ public class CanonicalSubscription implements Serializable, Cloneable { return new EqualsBuilder() .append(myStripVersionId, that.myStripVersionId) .append(myDeliverLatestVersion, that.myDeliverLatestVersion) + .append(myMaxRetries, that.myMaxRetries) .isEquals(); } @@ -330,17 +350,10 @@ public class CanonicalSubscription implements Serializable, Cloneable { return new HashCodeBuilder(17, 37) .append(myStripVersionId) .append(myDeliverLatestVersion) + .append(myMaxRetries) .toHashCode(); } - public boolean isStripVersionId() { - return myStripVersionId; - } - - public void setStripVersionId(boolean theStripVersionId) { - myStripVersionId = theStripVersionId; - } - } @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java index b7a3f09ce7c..ed25780a416 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java @@ -28,6 +28,7 @@ import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IPrimitiveDatatype; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -96,10 +97,10 @@ public class SubscriptionCanonicalizer { retVal.setIdElement(subscription.getIdElement()); retVal.setPayloadString(subscription.getChannel().getPayload()); - if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) { + if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) { String from; String subjectTemplate; - String bodyTemplate; + try { from = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_EMAIL_FROM); subjectTemplate = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE); @@ -111,16 +112,22 @@ public class SubscriptionCanonicalizer { } if (retVal.getChannelType() == CanonicalSubscriptionChannelType.RESTHOOK) { + String stripVersionIds; String deliverLatestVersion; + String maxRetries; try { stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS); deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION); + maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES); } catch (FHIRException theE) { throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE); } retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds)); retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion)); + if (isNotBlank(maxRetries)) { + retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries)); + } } } catch (FHIRException theE) { @@ -239,14 +246,20 @@ public class SubscriptionCanonicalizer { if (retVal.getChannelType() == CanonicalSubscriptionChannelType.RESTHOOK) { String stripVersionIds; String deliverLatestVersion; + String maxRetries; try { stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS); deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION); + maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES); + } catch (FHIRException theE) { throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE); } retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds)); retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion)); + if (isNotBlank(maxRetries)) { + retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries)); + } } List topicExts = subscription.getExtensionsByUrl("http://hl7.org/fhir/subscription/topics"); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java index 5d9f3f1ef20..e785464508d 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java @@ -67,6 +67,12 @@ public class SubscriptionConstants { */ public static final String EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION = "http://hapifhir.io/fhir/StructureDefinition/subscription-resthook-deliver-latest-version"; + /** + * This extension URL indicates the maximum number of delivery retries that will be attempted before the subscription delivery is considered to have failed. + */ + + public static final String EXT_SUBSCRIPTION_MAX_RETRIES = "http://hapifhir.io/fhir/StructureDefinition/subscription-max-retries"; + /** * The number of threads used in subscription channel processing */ diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java index 3358e8ab0cd..cefaf35eb79 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java @@ -101,8 +101,7 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe try { operation.execute(); } catch (ResourceNotFoundException e) { - ourLog.error("Cannot reach " + theMsg.getSubscription().getEndpointUrl()); - e.printStackTrace(); + ourLog.error("Cannot reach " + theMsg.getSubscription().getEndpointUrl(), e); throw e; } } From 6b22977d7c464259f392f267d03ae6c94e37c62c Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 21 Jan 2019 22:28:48 -0500 Subject: [PATCH 05/11] fixing more tests for Windows --- .../jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java | 3 ++- .../fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java | 1 + .../ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java | 1 + .../uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java | 4 ++-- .../ca/uhn/fhir/jpa/subscription/module/LatchedService.java | 3 ++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 7bfd40cfb5c..9662d068099 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.dao.data.ISearchParamPresentDao; import ca.uhn.fhir.jpa.model.entity.*; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.base.composite.BaseCodingDt; import ca.uhn.fhir.model.dstu2.composite.*; @@ -19,7 +20,6 @@ import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -858,6 +858,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { SearchParameterMap params; Date startDate = new Date(start); + TestUtil.sleepOneClick(); Date endDate = new Date(end); DateTimeDt startDateTime = new DateTimeDt(startDate, TemporalPrecisionEnum.MILLI); DateTimeDt endDateTime = new DateTimeDt(endDate, TemporalPrecisionEnum.MILLI); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java index 7810878bc0e..8300f487fd7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java @@ -1469,6 +1469,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { SearchParameterMap map; Date startDate = new Date(start); + TestUtil.sleepOneClick(); Date endDate = new Date(end); DateTimeType startDateTime = new DateTimeType(startDate, TemporalPrecisionEnum.MILLI); DateTimeType endDateTime = new DateTimeType(endDate, TemporalPrecisionEnum.MILLI); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java index 06e3dc75327..b1f7d1b2c4c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java @@ -338,6 +338,7 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { assertEquals("Patient", details.getResourceType()); assertEquals(Patient.class, details.getResource().getClass()); + TestUtil.sleepOneClick(); Date now2 = new Date(); Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless(), mySrd); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java index 40c0b4012e9..16ed5ca99cb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java @@ -165,8 +165,8 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { assertEquals(1, results1.getEntry().size()); assertEquals(1, mySearchEntityDao.count()); assertThat(myCapturingInterceptor.getLastResponse().getHeaders(Constants.HEADER_X_CACHE), empty()); - assertThat(results1.getMeta().getLastUpdated(), greaterThan(beforeFirst)); - assertThat(results1.getMeta().getLastUpdated(), lessThan(new Date())); + assertThat(TestUtil.getTimestamp(results1).getValue(), greaterThan(beforeFirst)); + assertThat(TestUtil.getTimestamp(results1).getValue(), lessThan(new Date())); assertThat(results1.getId(), not(blankOrNullString())); Patient pt2 = new Patient(); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java index 6e638bdfd36..0bb32a97fe5 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue; public class LatchedService implements IAnonymousLambdaHook { private static final Logger ourLog = LoggerFactory.getLogger(LatchedService.class); + private static final int DEFAULT_TIMEOUT_SECONDS = 20; private final String name; private CountDownLatch myCountdownLatch; @@ -48,7 +49,7 @@ public class LatchedService implements IAnonymousLambdaHook { } public void awaitExpected() throws InterruptedException { - awaitExpectedWithTimeout(10); + awaitExpectedWithTimeout(DEFAULT_TIMEOUT_SECONDS); } public void awaitExpectedWithTimeout(int timeoutSecond) throws InterruptedException { From 2c7eb39b29510220e296417d4696de5f33ad3519 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 22 Jan 2019 18:53:54 -0500 Subject: [PATCH 06/11] final batch of windows fixes (to deal with jumpy windows clock) also added semaphore to PointcutLatch --- .../FhirResourceDaoDstu2SearchNoFtTest.java | 13 ++- .../FhirResourceDaoDstu3SearchNoFtTest.java | 21 ++-- .../r4/FhirResourceDaoR4SearchNoFtTest.java | 20 +++- .../FhirResourceDaoR4SearchNoHashesTest.java | 7 ++ .../jpa/dao/r4/FhirResourceDaoR4Test.java | 8 +- .../dao/r4/FhirResourceDaoR4UpdateTest.java | 4 +- .../r4/ResourceProviderR4CacheTest.java | 9 +- .../subscription/module/LatchedService.java | 72 -------------- .../subscription/module/PointcutLatch.java | 95 +++++++++++++++++++ ...kingQueueSubscribableChannelDstu3Test.java | 23 +++-- .../SubscriptionCheckingSubscriberTest.java | 8 +- .../SubscriptionMatchingSubscriberTest.java | 8 +- 12 files changed, 173 insertions(+), 115 deletions(-) delete mode 100644 hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java create mode 100644 hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 9662d068099..bfa828616d7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -374,6 +374,9 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + + TestUtil.sleepOneClick(); + long betweenTime = System.currentTimeMillis(); IIdType id2; { @@ -820,8 +823,6 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Test public void testSearchLastUpdatedParamWithComparator() throws InterruptedException { - String methodName = "testSearchLastUpdatedParamWithComparator"; - IIdType id0; { Patient patient = new Patient(); @@ -829,18 +830,16 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - int sleep = 100; - long start = System.currentTimeMillis(); - Thread.sleep(sleep); + TestUtil.sleepOneClick(); - DateTimeDt beforeAny = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI); IIdType id1a; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); id1a = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); IIdType id1b; { Patient patient = new Patient(); @@ -853,7 +852,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b, mySrd)); ourLog.info("Res 3: {}", id1bpublished.getValueAsString()); - Thread.sleep(sleep); + TestUtil.sleepOneClick(); long end = System.currentTimeMillis(); SearchParameterMap params; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 2e7d2c50ff0..77bdfa62ed1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -1023,7 +1023,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addName().setFamily("testSearchLanguageParam").addGiven("Joe"); id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - + TestUtil.sleepOneClick(); Date betweenTime = new Date(); IIdType id2; @@ -1199,10 +1199,9 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - int sleep = 100; - + TestUtil.sleepOneClick(); long start = System.currentTimeMillis(); - TestUtil.sleepAtLeast(sleep); + TestUtil.sleepOneClick(); IIdType id1a; { @@ -1221,7 +1220,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { ourLog.info("Res 2: {}", myPatientDao.read(id1a, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); ourLog.info("Res 3: {}", myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValueAsString()); - TestUtil.sleepAtLeast(sleep); + TestUtil.sleepOneClick(); long end = System.currentTimeMillis(); SearchParameterMap map; @@ -1856,15 +1855,15 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addName().setFamily("Tester_testSearchStringParam").addGiven("Joe"); pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); Date between = new Date(); - Thread.sleep(10); { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily("Tester_testSearchStringParam").addGiven("John"); pid2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - Thread.sleep(10); + TestUtil.sleepOneClick(); Date after = new Date(); SearchParameterMap params; @@ -2874,6 +2873,8 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { tag1id = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + Date betweenDate = new Date(); IIdType tag2id; @@ -3196,7 +3197,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { p01.addName().setFamily("B").addGiven("A"); String id1 = myPatientDao.create(p01).getId().toUnqualifiedVersionless().getValue(); - Thread.sleep(10); + TestUtil.sleepOneClick(); // Numeric ID Patient p02 = new Patient(); @@ -3206,7 +3207,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { p02.addName().setFamily("Z").addGiven("Z"); String id2 = myPatientDao.create(p02).getId().toUnqualifiedVersionless().getValue(); - Thread.sleep(10); + TestUtil.sleepOneClick(); // Forced ID Patient pAB = new Patient(); @@ -3216,7 +3217,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { pAB.addName().setFamily("A").addGiven("B"); myPatientDao.update(pAB); - Thread.sleep(10); + TestUtil.sleepOneClick(); // Forced ID Patient pAA = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java index bfcbdc6a22c..221fbeaec8c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java @@ -889,10 +889,11 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - long betweenTime = System.currentTimeMillis(); TestUtil.sleepOneClick(); + long betweenTime = System.currentTimeMillis(); + IIdType id2; { Patient patient = new Patient(); @@ -1267,6 +1268,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { id1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + Date betweenTime = new Date(); TestUtil.sleepOneClick(); @@ -1444,6 +1447,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); long start = System.currentTimeMillis(); @@ -1455,6 +1459,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); id1a = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + + TestUtil.sleepOneClick(); + IIdType id1b; { Patient patient = new Patient(); @@ -1863,15 +1870,15 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { obs01.setSubject(new Reference(patientId01)); IIdType obsId01 = myObservationDao.create(obs01, mySrd).getId().toUnqualifiedVersionless(); + TestUtil.sleepOneClick(); Date between = new Date(); - Thread.sleep(10); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(locId01)); IIdType obsId02 = myObservationDao.create(obs02, mySrd).getId().toUnqualifiedVersionless(); - Thread.sleep(10); + TestUtil.sleepOneClick(); Date after = new Date(); ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", patientId01, locId01, obsId01, obsId02); @@ -1994,15 +2001,16 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { patient.addName().setFamily("Tester_testSearchStringParam").addGiven("Joe"); pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); Date between = new Date(); - Thread.sleep(10); + { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily("Tester_testSearchStringParam").addGiven("John"); pid2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } - Thread.sleep(10); + TestUtil.sleepOneClick(); Date after = new Date(); SearchParameterMap params; @@ -2972,6 +2980,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { tag1id = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + Date betweenDate = new Date(); IIdType tag2id; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java index 8300f487fd7..9d2c7036f75 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java @@ -1443,7 +1443,10 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { id0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); + long start = System.currentTimeMillis(); + TestUtil.sleepOneClick(); IIdType id1a; @@ -1452,6 +1455,9 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); id1a = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + + TestUtil.sleepOneClick(); + IIdType id1b; { Patient patient = new Patient(); @@ -1992,6 +1998,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { patient.addName().setFamily("Tester_testSearchStringParam").addGiven("Joe"); pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); } + TestUtil.sleepOneClick(); Date between = new Date(); TestUtil.sleepOneClick(); { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java index f75d4a5fbba..ea6c924d38b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java @@ -10,6 +10,7 @@ import ca.uhn.fhir.jpa.model.entity.*; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; @@ -20,7 +21,6 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.*; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; @@ -3159,16 +3159,22 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { p.addName().setFamily(methodName); IIdType id1 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); + TestUtil.sleepOneClick(); + p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName); p.addName().setFamily(methodName); IIdType id2 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); + TestUtil.sleepOneClick(); + p = new Patient(); p.addIdentifier().setSystem("urn:system3").setValue(methodName); p.addName().setFamily(methodName); IIdType id3 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); + TestUtil.sleepOneClick(); + p = new Patient(); p.addIdentifier().setSystem("urn:system4").setValue(methodName); p.addName().setFamily(methodName); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java index b1f7d1b2c4c..9301cbd1c59 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java @@ -313,10 +313,10 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { assertEquals("1", outcome.getId().getVersionIdPart()); - Date now = new Date(); - TestUtil.sleepOneClick(); + Date now = new Date(); + Patient retrieved = myPatientDao.read(outcome.getId(), mySrd); InstantType updated = TestUtil.getTimestamp(retrieved); assertTrue(updated.before(now)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java index 16ed5ca99cb..dd4eb173b2f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java @@ -159,14 +159,19 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { ourClient.create().resource(pt1).execute(); Date beforeFirst = new Date(); + TestUtil.sleepOneClick(); Bundle results1 = ourClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); + + TestUtil.sleepOneClick(); + assertEquals(1, results1.getEntry().size()); assertEquals(1, mySearchEntityDao.count()); assertThat(myCapturingInterceptor.getLastResponse().getHeaders(Constants.HEADER_X_CACHE), empty()); - assertThat(TestUtil.getTimestamp(results1).getValue(), greaterThan(beforeFirst)); - assertThat(TestUtil.getTimestamp(results1).getValue(), lessThan(new Date())); + Date results1Date = TestUtil.getTimestamp(results1).getValue(); + assertThat(results1Date, greaterThan(beforeFirst)); + assertThat(results1Date, lessThan(new Date())); assertThat(results1.getId(), not(blankOrNullString())); Patient pt2 = new Patient(); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java deleted file mode 100644 index 0bb32a97fe5..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/LatchedService.java +++ /dev/null @@ -1,72 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.module; - -import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; -import ca.uhn.fhir.jpa.model.interceptor.api.IAnonymousLambdaHook; -import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; - -import static org.junit.Assert.assertTrue; - -public class LatchedService implements IAnonymousLambdaHook { - private static final Logger ourLog = LoggerFactory.getLogger(LatchedService.class); - private static final int DEFAULT_TIMEOUT_SECONDS = 20; - private final String name; - - private CountDownLatch myCountdownLatch; - private AtomicReference myFailure; - private AtomicReference> myCalledWith; - - public LatchedService(Pointcut thePointcut) { - this.name = thePointcut.name(); - } - - public LatchedService(String theName) { - this.name = theName; - } - - public void countdown() { - if (myCountdownLatch == null) { - myFailure.set(name + " latch countdown() called before expectedCount set."); - } else if (myCountdownLatch.getCount() <= 0) { - myFailure.set(name + " latch countdown() called "+ (1 - myCountdownLatch.getCount()) + " more times than expected."); - } - ourLog.info("{} counting down {}", name, myCountdownLatch); - myCountdownLatch.countDown(); - } - - public void setExpectedCount(int count) { - myFailure = new AtomicReference<>(); - myCalledWith = new AtomicReference<>(new ArrayList<>()); - myCountdownLatch = new CountDownLatch(count); - } - - public void awaitExpected() throws InterruptedException { - awaitExpectedWithTimeout(DEFAULT_TIMEOUT_SECONDS); - } - - public void awaitExpectedWithTimeout(int timeoutSecond) throws InterruptedException { - assertTrue(name +" latch timed out waiting "+timeoutSecond+" seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); - - if (myFailure.get() != null) { - String error = myFailure.get(); - error += "\nLatch called with values: "+myCalledWith.get().stream().map(Object::toString).collect(Collectors.joining(", ")); - throw new AssertionError(error); - } - } - - @Override - public void invoke(HookParams theArgs) { - this.countdown(); - if (myCalledWith.get() != null) { - myCalledWith.get().add(theArgs); - } - } -} diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java new file mode 100644 index 00000000000..a8d6f91468e --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java @@ -0,0 +1,95 @@ +package ca.uhn.fhir.jpa.subscription.module; + +import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; +import ca.uhn.fhir.jpa.model.interceptor.api.IAnonymousLambdaHook; +import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class PointcutLatch implements IAnonymousLambdaHook { + private static final Logger ourLog = LoggerFactory.getLogger(PointcutLatch.class); + private static final int DEFAULT_TIMEOUT_SECONDS = 10; + private final String name; + + private Semaphore mySemaphore = new Semaphore(1); + private CountDownLatch myCountdownLatch; + private AtomicReference myFailure; + private AtomicReference> myCalledWith; + + public PointcutLatch(Pointcut thePointcut) { + this.name = thePointcut.name(); + } + + public PointcutLatch(String theName) { + this.name = theName; + } + + private void countdown() { + if (myCountdownLatch == null) { + myFailure.set(name + " latch countdown() called before expectedCount set."); + } else if (myCountdownLatch.getCount() <= 0) { + myFailure.set(name + " latch countdown() called "+ (1 - myCountdownLatch.getCount()) + " more times than expected."); + } + ourLog.info("{} counting down {}", name, myCountdownLatch); + myCountdownLatch.countDown(); + } + + public void setExpectedCount(int count) throws InterruptedException { + mySemaphore.acquire(); + if (myCountdownLatch != null) { + myFailure.set(name + " latch setExpectedCount() called before previous awaitExpected() completed."); + } + myFailure = new AtomicReference<>(); + myCalledWith = new AtomicReference<>(new ArrayList<>()); + myCountdownLatch = new CountDownLatch(count); + } + + public void awaitExpected() throws InterruptedException { + awaitExpected(true); + } + + public void awaitExpected(boolean release) throws InterruptedException { + awaitExpectedWithTimeout(DEFAULT_TIMEOUT_SECONDS, release); + } + + public void awaitExpectedWithTimeout(int timeoutSecond, boolean release) throws InterruptedException { + try { + assertNotNull(name + " latch awaitExpected() called before previous setExpected() called.", myCountdownLatch); + assertTrue(name + " latch timed out waiting " + timeoutSecond + " seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); + + if (myFailure.get() != null) { + String error = myFailure.get(); + error += "\nLatch called with values: " + myCalledWith.get().stream().map(Object::toString).collect(Collectors.joining(", ")); + throw new AssertionError(error); + } + } finally { + if (release) { + release(); + } + } + } + + public void release() { + myCountdownLatch = null; + mySemaphore.release(); + } + + @Override + public void invoke(HookParams theArgs) { + this.countdown(); + if (myCalledWith.get() != null) { + myCalledWith.get().add(theArgs); + } + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index 4cb096dba32..4269641541a 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -1,15 +1,14 @@ package ca.uhn.fhir.jpa.subscription.module.standalone; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorRegistry; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; -import ca.uhn.fhir.jpa.subscription.module.LatchedService; +import ca.uhn.fhir.jpa.subscription.module.PointcutLatch; import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionChannelFactory; -import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriber; import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriberTest; import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.ResourceParam; @@ -65,8 +64,8 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base private static SubscribableChannel ourSubscribableChannel; private List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); private long idCounter = 0; - protected LatchedService mySubscriptionMatchingPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED); - protected LatchedService mySubscriptionActivatedPost = new LatchedService(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED); + protected PointcutLatch mySubscriptionMatchingPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED); + protected PointcutLatch mySubscriptionActivatedPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED); @Before public void beforeReset() { @@ -165,7 +164,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base public static class ObservationListener implements IResourceProvider { - private LatchedService updateLatch = new LatchedService("Observation Update"); + private PointcutLatch updateLatch = new PointcutLatch("Observation Update"); @Create public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { @@ -184,17 +183,21 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base public MethodOutcome update(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { ourContentTypes.add(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE).replaceAll(";.*", "")); ourUpdatedObservations.add(theObservation); - updateLatch.countdown(); + updateLatch.invoke(new HookParams().add(Observation.class, theObservation)); ourLog.info("Received Listener Update (now have {} updates)", ourUpdatedObservations.size()); return new MethodOutcome(new IdType("Observation/1"), false); } - public void setExpectedCount(int count) { + public void setExpectedCount(int count) throws InterruptedException { updateLatch.setExpectedCount(count); } - public void awaitExpected() throws InterruptedException { - updateLatch.awaitExpected(); + public void awaitExpected(boolean release) throws InterruptedException { + updateLatch.awaitExpected(release); + } + + public void release() { + updateLatch.release(); } } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java index 58e5f696f38..5af2d728dff 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java @@ -27,9 +27,10 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(false); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); + ourObservationListener.release(); } @Test @@ -45,9 +46,10 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(false); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); + ourObservationListener.release(); } @Test @@ -65,6 +67,6 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); mySubscriptionMatchingPost.awaitExpected(); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(true); } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java index 0bd4ac035c1..8fd2e436e4e 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java @@ -27,9 +27,10 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(false); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); + ourObservationListener.release(); } @Test @@ -45,9 +46,10 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(false); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); + ourObservationListener.release(); } @Test @@ -65,6 +67,6 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); mySubscriptionMatchingPost.awaitExpected(); - ourObservationListener.awaitExpected(); + ourObservationListener.awaitExpected(true); } } From 707bf0709936f88105a49b4599d234f2e04cbaf8 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 23 Jan 2019 11:57:59 -0500 Subject: [PATCH 07/11] optimistic the windows tests will now finally pass! --- .../jpa/model/interceptor/api/HookParams.java | 5 + .../module/cache/ActiveSubscriptionCache.java | 6 + .../module/cache/SubscriptionRegistry.java | 6 + .../subscription/module/PointcutLatch.java | 132 +++++++++++++----- ...kingQueueSubscribableChannelDstu3Test.java | 29 ++-- .../SubscriptionCheckingSubscriberTest.java | 22 ++- .../SubscriptionMatchingSubscriberTest.java | 20 ++- 7 files changed, 156 insertions(+), 64 deletions(-) diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/HookParams.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/HookParams.java index 5c97f1ae081..5156e67c66a 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/HookParams.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/HookParams.java @@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.model.interceptor.api; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -73,4 +75,7 @@ public class HookParams { return myParams.values().stream().map(t -> t.getClass().getSimpleName()).collect(Collectors.toList()); } + public Collection values() { + return Collections.unmodifiableCollection(myParams.values()); + } } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/ActiveSubscriptionCache.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/ActiveSubscriptionCache.java index 0aa92298c04..6afcd485850 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/ActiveSubscriptionCache.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/ActiveSubscriptionCache.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.subscription.module.cache; * #L% */ +import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.Validate; import java.util.ArrayList; @@ -69,4 +70,9 @@ public class ActiveSubscriptionCache { } } } + + @VisibleForTesting + public void clearForUnitTests() { + myCache.clear(); + } } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java index 29c6e939d2c..7c9b9b5da50 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistry.java @@ -24,6 +24,7 @@ import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.interceptor.api.IInterceptorRegistry; import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription; +import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -155,4 +156,9 @@ public class SubscriptionRegistry { public int size() { return myActiveSubscriptionCache.size(); } + + @VisibleForTesting + public void clearForUnitTests() { + myActiveSubscriptionCache.clearForUnitTests(); + } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java index a8d6f91468e..6c0a5108203 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/PointcutLatch.java @@ -1,17 +1,19 @@ package ca.uhn.fhir.jpa.subscription.module; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; import ca.uhn.fhir.jpa.model.interceptor.api.IAnonymousLambdaHook; import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import java.util.stream.Collectors; import static org.junit.Assert.assertNotNull; @@ -22,7 +24,6 @@ public class PointcutLatch implements IAnonymousLambdaHook { private static final int DEFAULT_TIMEOUT_SECONDS = 10; private final String name; - private Semaphore mySemaphore = new Semaphore(1); private CountDownLatch myCountdownLatch; private AtomicReference myFailure; private AtomicReference> myCalledWith; @@ -35,61 +36,116 @@ public class PointcutLatch implements IAnonymousLambdaHook { this.name = theName; } - private void countdown() { - if (myCountdownLatch == null) { - myFailure.set(name + " latch countdown() called before expectedCount set."); - } else if (myCountdownLatch.getCount() <= 0) { - myFailure.set(name + " latch countdown() called "+ (1 - myCountdownLatch.getCount()) + " more times than expected."); + public void setExpectedCount(int count) throws InterruptedException { + if (myCountdownLatch != null) { + throw new PointcutLatchException("setExpectedCount() called before previous awaitExpected() completed."); } - ourLog.info("{} counting down {}", name, myCountdownLatch); - myCountdownLatch.countDown(); + createLatch(count); } - public void setExpectedCount(int count) throws InterruptedException { - mySemaphore.acquire(); - if (myCountdownLatch != null) { - myFailure.set(name + " latch setExpectedCount() called before previous awaitExpected() completed."); - } + private void createLatch(int count) { myFailure = new AtomicReference<>(); myCalledWith = new AtomicReference<>(new ArrayList<>()); myCountdownLatch = new CountDownLatch(count); } - public void awaitExpected() throws InterruptedException { - awaitExpected(true); - } - - public void awaitExpected(boolean release) throws InterruptedException { - awaitExpectedWithTimeout(DEFAULT_TIMEOUT_SECONDS, release); - } - - public void awaitExpectedWithTimeout(int timeoutSecond, boolean release) throws InterruptedException { - try { - assertNotNull(name + " latch awaitExpected() called before previous setExpected() called.", myCountdownLatch); - assertTrue(name + " latch timed out waiting " + timeoutSecond + " seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); - - if (myFailure.get() != null) { - String error = myFailure.get(); - error += "\nLatch called with values: " + myCalledWith.get().stream().map(Object::toString).collect(Collectors.joining(", ")); - throw new AssertionError(error); - } - } finally { - if (release) { - release(); - } + private void setFailure(String failure) { + if (myFailure != null) { + myFailure.set(failure); + } else { + throw new PointcutLatchException("trying to set failure on latch that hasn't been created: " + failure); } } - public void release() { + private String getName() { + return name + " " + this.getClass().getSimpleName(); + } + + public void awaitExpected() throws InterruptedException { + awaitExpectedWithTimeout(DEFAULT_TIMEOUT_SECONDS); + } + + public void awaitExpectedWithTimeout(int timeoutSecond) throws InterruptedException { + try { + assertNotNull(getName() + " awaitExpected() called before setExpected() called.", myCountdownLatch); + assertTrue(getName() + " timed out waiting " + timeoutSecond + " seconds for latch to be triggered.", myCountdownLatch.await(timeoutSecond, TimeUnit.SECONDS)); + + if (myFailure.get() != null) { + String error = getName() + ": " + myFailure.get(); + error += "\nLatch called with values: " + myCalledWithString(); + throw new AssertionError(error); + } + } finally { + destroyLatch(); + } + } + + public void expectNothing() { + destroyLatch(); + } + + private void destroyLatch() { myCountdownLatch = null; - mySemaphore.release(); + } + + private String myCalledWithString() { + if (myCalledWith == null) { + return "[]"; + } + List calledWith = myCalledWith.get(); + if (calledWith.isEmpty()) { + return "[]"; + } + String retVal = "[ "; + retVal += calledWith.stream().flatMap(hookParams -> hookParams.values().stream()).map(itemToString()).collect(Collectors.joining(", ")); + return retVal + " ]"; + } + + private static Function itemToString() { + return object -> { + if (object instanceof IBaseResource) { + IBaseResource resource = (IBaseResource) object; + return "Resource " + resource.getIdElement().getValue(); + } else if (object instanceof ResourceModifiedMessage) { + ResourceModifiedMessage resourceModifiedMessage = (ResourceModifiedMessage)object; + // FIXME KHS can we get the context from the payload? + return "ResourceModified Message { " + resourceModifiedMessage.getOperationType() + ", " + resourceModifiedMessage.getNewPayload(FhirContext.forDstu3()).getIdElement().getValue() + "}"; + } else { + return object.toString(); + } + }; } @Override public void invoke(HookParams theArgs) { + if (myCountdownLatch == null) { + throw new PointcutLatchException("countdown() called before setExpectedCount() called.", theArgs); + } else if (myCountdownLatch.getCount() <= 0) { + setFailure("countdown() called " + (1 - myCountdownLatch.getCount()) + " more times than expected."); + } + this.countdown(); if (myCalledWith.get() != null) { myCalledWith.get().add(theArgs); } } + + private void countdown() { + ourLog.info("{} counting down {}", name, myCountdownLatch); + myCountdownLatch.countDown(); + } + + private class PointcutLatchException extends IllegalStateException { + public PointcutLatchException(String message, HookParams theArgs) { + super(getName() + ": " + message + " called with values: " + hookParamsToString(theArgs)); + } + + public PointcutLatchException(String message) { + super(getName() + ": " + message); + } + } + + private static String hookParamsToString(HookParams hookParams) { + return hookParams.values().stream().map(itemToString()).collect(Collectors.joining(", ")); + } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index 4269641541a..f2608b12f95 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -8,6 +8,7 @@ import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.jpa.subscription.module.PointcutLatch; import ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionChannelFactory; +import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceModifiedJsonMessage; import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriberTest; import ca.uhn.fhir.rest.annotation.Create; @@ -38,6 +39,7 @@ import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicLong; public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends BaseSubscriptionDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionMatchingSubscriberTest.class); @@ -51,6 +53,9 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base SubscriptionChannelFactory mySubscriptionChannelFactory; @Autowired InterceptorRegistry myInterceptorRegistry; + @Autowired + protected SubscriptionRegistry mySubscriptionRegistry; + protected String myCode = "1000000050"; @@ -63,7 +68,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base protected static List ourContentTypes = Collections.synchronizedList(new ArrayList<>()); private static SubscribableChannel ourSubscribableChannel; private List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); - private long idCounter = 0; + private static AtomicLong idCounter = new AtomicLong(); protected PointcutLatch mySubscriptionMatchingPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED); protected PointcutLatch mySubscriptionActivatedPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED); @@ -72,6 +77,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base ourCreatedObservations.clear(); ourUpdatedObservations.clear(); ourContentTypes.clear(); + mySubscriptionRegistry.clearForUnitTests(); if (ourSubscribableChannel == null) { ourSubscribableChannel = mySubscriptionChannelFactory.newDeliveryChannel("test", Subscription.SubscriptionChannelType.RESTHOOK.toCode().toLowerCase()); ourSubscribableChannel.subscribe(myStandaloneSubscriptionMessageHandler); @@ -85,10 +91,12 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base myInterceptorRegistry.clearAnonymousHookForUnitTest(); } - public T sendResource(T theResource) { + public T sendResource(T theResource) throws InterruptedException { ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, theResource, ResourceModifiedMessage.OperationTypeEnum.CREATE); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(msg); + mySubscriptionMatchingPost.setExpectedCount(1); ourSubscribableChannel.send(message); + mySubscriptionMatchingPost.awaitExpected(); return theResource; } @@ -105,8 +113,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)"); subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE); subscription.setCriteria(theCriteria); - ++idCounter; - IdType id = new IdType("Subscription", idCounter); + IdType id = new IdType("Subscription", idCounter.incrementAndGet()); subscription.setId(id); Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent(); @@ -117,10 +124,9 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base return subscription; } - protected Observation sendObservation(String code, String system) { + protected Observation sendObservation(String code, String system) throws InterruptedException { Observation observation = new Observation(); - ++idCounter; - IdType id = new IdType("Observation", idCounter); + IdType id = new IdType("Observation", idCounter.incrementAndGet()); observation.setId(id); CodeableConcept codeableConcept = new CodeableConcept(); @@ -134,7 +140,6 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base return sendResource(observation); } - @BeforeClass public static void startListenerServer() throws Exception { ourListenerPort = PortUtil.findFreePort(); @@ -192,12 +197,12 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base updateLatch.setExpectedCount(count); } - public void awaitExpected(boolean release) throws InterruptedException { - updateLatch.awaitExpected(release); + public void awaitExpected() throws InterruptedException { + updateLatch.awaitExpected(); } - public void release() { - updateLatch.release(); + public void expectNothing() { + updateLatch.expectNothing(); } } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java index 5af2d728dff..d3fe0ba2a38 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java @@ -1,10 +1,12 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; +import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.module.standalone.BaseBlockingQueueSubscribableChannelDstu3Test; import ca.uhn.fhir.rest.api.Constants; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import static org.junit.Assert.assertEquals; @@ -25,12 +27,14 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(false); + ourObservationListener.awaitExpected(); + assertEquals(1, ourContentTypes.size()); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); - ourObservationListener.release(); } @Test @@ -44,12 +48,14 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(false); + ourObservationListener.awaitExpected(); + assertEquals(1, ourContentTypes.size()); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); - ourObservationListener.release(); } @Test @@ -63,10 +69,12 @@ public class SubscriptionCheckingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(0); - mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - mySubscriptionMatchingPost.awaitExpected(); - ourObservationListener.awaitExpected(true); + ourObservationListener.expectNothing(); + + assertEquals(0, ourContentTypes.size()); } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java index 8fd2e436e4e..446b903e4a3 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java @@ -25,12 +25,14 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(false); + ourObservationListener.awaitExpected(); + assertEquals(1, ourContentTypes.size()); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); - ourObservationListener.release(); } @Test @@ -44,12 +46,14 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - ourObservationListener.awaitExpected(false); + ourObservationListener.awaitExpected(); + assertEquals(1, ourContentTypes.size()); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); - ourObservationListener.release(); } @Test @@ -63,10 +67,12 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri sendSubscription(criteria1, payload, ourListenerServerBase); sendSubscription(criteria2, payload, ourListenerServerBase); + assertEquals(2, mySubscriptionRegistry.size()); + ourObservationListener.setExpectedCount(0); - mySubscriptionMatchingPost.setExpectedCount(1); sendObservation(code, "SNOMED-CT"); - mySubscriptionMatchingPost.awaitExpected(); - ourObservationListener.awaitExpected(true); + ourObservationListener.expectNothing(); + + assertEquals(0, ourContentTypes.size()); } } From 7d1d5a102ce5f75afda6556ec78d123dd0175f82 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 23 Jan 2019 16:14:53 -0500 Subject: [PATCH 08/11] Attempt to fix a weird lucene indexing issue --- .../jpa/provider/SystemProviderDstu2Test.java | 20 +++++++++++++++---- .../jpa/provider/r4/SystemProviderR4Test.java | 15 ++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java index ae52fbdfcd3..48325472741 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java @@ -211,9 +211,11 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); myObservationDao.update(obs, mySrd); + // Try to wait for the indexing to complete + waitToParamsToIndex(ptId); + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); - CloseableHttpResponse http = ourHttpClient.execute(get); - try { + try (CloseableHttpResponse http = ourHttpClient.execute(get)) { assertEquals(200, http.getStatusLine().getStatusCode()); String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(output); @@ -225,11 +227,21 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { assertEquals("score", parameters.getParameter().get(0).getPart().get(1).getName()); assertEquals(new DecimalDt("1.0"), parameters.getParameter().get(0).getPart().get(1).getValue()); - } finally { - http.close(); } } + private void waitToParamsToIndex(IIdType thePtId) throws Exception { + waitForSize(2, ()->{ + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); + try (CloseableHttpResponse http = ourHttpClient.execute(get)) { + assertEquals(200, http.getStatusLine().getStatusCode()); + String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); + Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); + return parameters.getParameter().size(); + } + }); + } + @Test public void testSuggestKeywordsInvalid() throws Exception { Patient patient = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java index 137d05f9492..4389dc159cb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java @@ -279,6 +279,9 @@ public class SystemProviderR4Test extends BaseJpaR4Test { obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); myObservationDao.update(obs, mySrd); + // Try to wait for the indexing to complete + waitForParamsToIndex(ptId); + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); CloseableHttpResponse http = ourHttpClient.execute(get); try { @@ -298,6 +301,18 @@ public class SystemProviderR4Test extends BaseJpaR4Test { } } + private void waitForParamsToIndex(IIdType thePtId) throws Exception { + waitForSize(2, ()->{ + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); + try (CloseableHttpResponse http = ourHttpClient.execute(get)) { + assertEquals(200, http.getStatusLine().getStatusCode()); + String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); + Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); + return parameters.getParameter().size(); + } + }); + } + @Test public void testSuggestKeywordsInvalid() throws Exception { Patient patient = new Patient(); From 5c7907dfeae332a05f06d63dab7734e527455df4 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 23 Jan 2019 16:17:41 -0500 Subject: [PATCH 09/11] magic number --- .../uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index aeb14f9a454..aee27813903 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -123,6 +123,7 @@ import ca.uhn.fhir.util.UrlUtil; public class ResourceProviderR4Test extends BaseResourceProviderR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4Test.class); + public static final int LARGE_NUMBER = 77; private SearchCoordinatorSvcImpl mySearchCoordinatorSvcRaw; private CapturingInterceptor myCapturingInterceptor = new CapturingInterceptor(); @@ -1755,7 +1756,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p.setActive(true); IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - for (int i = 1; i < 77; i++) { + for (int i = 1; i < LARGE_NUMBER; i++) { Observation obs = new Observation(); obs.setId("A" + StringUtils.leftPad(Integer.toString(i), 2, '0')); obs.setSubject(new Reference(id)); @@ -1793,8 +1794,8 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } assertThat(ids, hasItem(id.getIdPart())); - assertEquals(77, ids.size()); - for (int i = 1; i < 77; i++) { + assertEquals(LARGE_NUMBER, ids.size()); + for (int i = 1; i < LARGE_NUMBER; i++) { assertThat(ids.size() + " ids: " + ids, ids, hasItem("A" + StringUtils.leftPad(Integer.toString(i), 2, '0'))); } } From e819b83a94d6c064550edd6d7dfde376243f83f7 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 23 Jan 2019 16:21:13 -0500 Subject: [PATCH 10/11] Make busywait more clear --- .../jpa/provider/SystemProviderDstu2Test.java | 20 +++++++++---------- .../jpa/provider/r4/SystemProviderR4Test.java | 20 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java index 48325472741..af487089ba1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java @@ -212,7 +212,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { myObservationDao.update(obs, mySrd); // Try to wait for the indexing to complete - waitToParamsToIndex(ptId); + waitForSize(2, ()-> fetchSuggestionCount(ptId)); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); try (CloseableHttpResponse http = ourHttpClient.execute(get)) { @@ -230,16 +230,14 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { } } - private void waitToParamsToIndex(IIdType thePtId) throws Exception { - waitForSize(2, ()->{ - HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); - try (CloseableHttpResponse http = ourHttpClient.execute(get)) { - assertEquals(200, http.getStatusLine().getStatusCode()); - String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); - Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); - return parameters.getParameter().size(); - } - }); + private Number fetchSuggestionCount(IIdType thePtId) throws IOException { + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); + try (CloseableHttpResponse http = ourHttpClient.execute(get)) { + assertEquals(200, http.getStatusLine().getStatusCode()); + String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); + Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); + return parameters.getParameter().size(); + } } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java index 4389dc159cb..3c4300011c7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java @@ -280,7 +280,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { myObservationDao.update(obs, mySrd); // Try to wait for the indexing to complete - waitForParamsToIndex(ptId); + waitForSize(2, ()-> fetchSuggestionCount(ptId)); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -301,16 +301,14 @@ public class SystemProviderR4Test extends BaseJpaR4Test { } } - private void waitForParamsToIndex(IIdType thePtId) throws Exception { - waitForSize(2, ()->{ - HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); - try (CloseableHttpResponse http = ourHttpClient.execute(get)) { - assertEquals(200, http.getStatusLine().getStatusCode()); - String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); - Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); - return parameters.getParameter().size(); - } - }); + private Number fetchSuggestionCount(IIdType thePtId) throws IOException { + HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + thePtId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); + try (CloseableHttpResponse http = ourHttpClient.execute(get)) { + assertEquals(200, http.getStatusLine().getStatusCode()); + String output = IOUtils.toString(http.getEntity().getContent(), StandardCharsets.UTF_8); + Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output); + return parameters.getParameter().size(); + } } @Test From 0eb70b81fe3a7559cc9ef2dfb8859c08d53220cd Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 23 Jan 2019 18:13:29 -0500 Subject: [PATCH 11/11] Oops. This was supposed to be automatically backed out. But SQUASH MERGE prevented that from happening. Hmmmmm...... --- .../subscription/module/CanonicalSubscription.java | 12 ------------ .../module/cache/SubscriptionCanonicalizer.java | 11 ----------- .../module/cache/SubscriptionConstants.java | 6 ------ 3 files changed, 29 deletions(-) diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java index 707a75aabc4..b055a20d5c4 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java @@ -295,8 +295,6 @@ public class CanonicalSubscription implements Serializable, Cloneable { private boolean myStripVersionId; @JsonProperty("deliverLatestVersion") private boolean myDeliverLatestVersion; - @JsonProperty("maxRetries") - private int myMaxRetries; /** * Constructor @@ -322,14 +320,6 @@ public class CanonicalSubscription implements Serializable, Cloneable { myStripVersionId = theStripVersionId; } - public int getMaxRetries() { - return myMaxRetries; - } - - public void setMaxRetries(int theMaxRetries) { - myMaxRetries = theMaxRetries; - } - @Override public boolean equals(Object theO) { if (this == theO) return true; @@ -341,7 +331,6 @@ public class CanonicalSubscription implements Serializable, Cloneable { return new EqualsBuilder() .append(myStripVersionId, that.myStripVersionId) .append(myDeliverLatestVersion, that.myDeliverLatestVersion) - .append(myMaxRetries, that.myMaxRetries) .isEquals(); } @@ -350,7 +339,6 @@ public class CanonicalSubscription implements Serializable, Cloneable { return new HashCodeBuilder(17, 37) .append(myStripVersionId) .append(myDeliverLatestVersion) - .append(myMaxRetries) .toHashCode(); } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java index 24a559b6a8f..0c87b0d0076 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionCanonicalizer.java @@ -115,19 +115,14 @@ public class SubscriptionCanonicalizer { String stripVersionIds; String deliverLatestVersion; - String maxRetries; try { stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS); deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION); - maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES); } catch (FHIRException theE) { throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE); } retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds)); retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion)); - if (isNotBlank(maxRetries)) { - retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries)); - } } } catch (FHIRException theE) { @@ -246,20 +241,14 @@ public class SubscriptionCanonicalizer { if (retVal.getChannelType() == CanonicalSubscriptionChannelType.RESTHOOK) { String stripVersionIds; String deliverLatestVersion; - String maxRetries; try { stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS); deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION); - maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES); - } catch (FHIRException theE) { throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE); } retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds)); retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion)); - if (isNotBlank(maxRetries)) { - retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries)); - } } List topicExts = subscription.getExtensionsByUrl("http://hl7.org/fhir/subscription/topics"); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java index e785464508d..5d9f3f1ef20 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionConstants.java @@ -67,12 +67,6 @@ public class SubscriptionConstants { */ public static final String EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION = "http://hapifhir.io/fhir/StructureDefinition/subscription-resthook-deliver-latest-version"; - /** - * This extension URL indicates the maximum number of delivery retries that will be attempted before the subscription delivery is considered to have failed. - */ - - public static final String EXT_SUBSCRIPTION_MAX_RETRIES = "http://hapifhir.io/fhir/StructureDefinition/subscription-max-retries"; - /** * The number of threads used in subscription channel processing */