don't create a channel if subscriptions are disabled. (#2733)

* don't create a channel if subscriptions are disabled.

* review feedback

* fix test

* fix intermittent

* fix intermittent
This commit is contained in:
Ken Stevens 2021-06-19 00:00:16 -04:00 committed by GitHub
parent 32ac16e2aa
commit 0b05c730fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 21 deletions

View File

@ -4,19 +4,29 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test;
import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionMatcherInterceptor;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.test.utilities.JettyUtil;
import com.google.common.collect.Lists;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.*;
import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Subscription;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,8 +39,6 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ca.uhn.fhir.test.utilities.JettyUtil;
public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourceProviderR4Test {
private static final Logger ourLog = LoggerFactory.getLogger(RestHookActivatesPreExistingSubscriptionsR4Test.class);
@ -38,20 +46,25 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc
private static RestfulServer ourListenerRestServer;
private static String ourListenerServerBase;
private static Server ourListenerServer;
private static List<Observation> ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList());
private static List<String> ourContentTypes = Collections.synchronizedList(new ArrayList<>());
private static List<String> ourHeaders = Collections.synchronizedList(new ArrayList<>());
private static final List<Observation> ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList());
private static final List<String> ourContentTypes = Collections.synchronizedList(new ArrayList<>());
private static final List<String> ourHeaders = Collections.synchronizedList(new ArrayList<>());
@Autowired
private SubscriptionTestUtil mySubscriptionTestUtil;
@Autowired
private SubscriptionMatcherInterceptor mySubscriptionMatcherInterceptor;
@AfterEach
public void afterUnregisterRestHookListener() {
mySubscriptionTestUtil.unregisterSubscriptionInterceptor();
myDaoConfig.clearSupportedSubscriptionTypesForUnitTest();
}
@BeforeEach
public void beforeSetSubscriptionActivatingInterceptor() {
myDaoConfig.addSupportedSubscriptionType(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.RESTHOOK);
mySubscriptionMatcherInterceptor.startIfNeeded();
mySubscriptionLoader.doSyncSubscriptionsForUnitTest();
}

View File

@ -244,18 +244,6 @@ public class InMemoryResourceMatcherR5Test {
assertTrue(result.matched());
}
@Test
public void testTodayTomorrow() {
Observation futureObservation = new Observation();
Instant nextWeek = Instant.now().plus(Duration.ofDays(1));
futureObservation.setEffective(new DateTimeType(Date.from(nextWeek)));
ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation);
InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams);
assertTrue(result.supported(), result.getUnsupportedReason());
assertTrue(result.matched());
}
@Test
public void testTodayYesterday() {
Observation futureObservation = new Observation();

View File

@ -13,8 +13,8 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedCons
import ca.uhn.fhir.jpa.subscription.match.matcher.subscriber.SubscriptionMatchingSubscriber;
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage;
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -51,7 +51,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
@Interceptor
public class SubscriptionMatcherInterceptor implements IResourceModifiedConsumer {
private Logger ourLog = LoggerFactory.getLogger(SubscriptionMatcherInterceptor.class);
private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionMatcherInterceptor.class);
@Autowired
private FhirContext myFhirContext;
@Autowired
@ -72,6 +72,10 @@ public class SubscriptionMatcherInterceptor implements IResourceModifiedConsumer
@EventListener(classes = {ContextRefreshedEvent.class})
public void startIfNeeded() {
if (myDaoConfig.getSupportedSubscriptionTypes().isEmpty()) {
ourLog.debug("Subscriptions are disabled on this server. Skipping {} channel creation.", SubscriptionMatchingSubscriber.SUBSCRIPTION_MATCHING_CHANNEL_NAME);
return;
}
if (myMatchingChannel == null) {
myMatchingChannel = mySubscriptionChannelFactory.newMatchingSendingChannel(SubscriptionMatchingSubscriber.SUBSCRIPTION_MATCHING_CHANNEL_NAME, null);
}