Merge branch 'master' into windows-fixes

quickly update tests to new interceptor
This commit is contained in:
Ken Stevens 2019-01-20 09:39:34 -05:00
parent f7e05f6e58
commit b3bdbea19c
6 changed files with 31 additions and 24 deletions

View File

@ -67,9 +67,12 @@ public enum Pointcut {
* <li>ca.uhn.fhir.jpa.subscription.module.ResourceModifiedMessage</li>
* </ul>
*/
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<String> myParameterTypes;

View File

@ -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;
}

View File

@ -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();

View File

@ -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<Object> {
public class LatchedService implements IAnonymousLambdaHook {
private static final Logger ourLog = LoggerFactory.getLogger(LatchedService.class);
private final String name;
private CountDownLatch myCountdownLatch;
private AtomicReference<String> myFailure;
private AtomicReference<List<Object>> myCalledWith;
private AtomicReference<List<HookParams>> 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() {
@ -59,11 +64,10 @@ public class LatchedService implements Predicate<Object> {
}
@Override
public boolean test(Object object) {
public void invoke(HookParams theArgs) {
this.countdown();
if (myCalledWith.get() != null) {
myCalledWith.get().add(object);
}
return true;
myCalledWith.get().add(theArgs);
}
}
}

View File

@ -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<IIdType> 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 extends IBaseResource> T sendResource(T theResource) {

View File

@ -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;