From ca95791d2e8a5243999ddeff72c95fffcd944275 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 1 Oct 2019 10:52:00 -0400 Subject: [PATCH] fix test --- .../SubscriptionInterceptorLoader.java | 7 ++++++- .../channel/SubscriptionChannelRegistry.java | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionInterceptorLoader.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionInterceptorLoader.java index d90c9b4818b..65984fdd389 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionInterceptorLoader.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionInterceptorLoader.java @@ -24,6 +24,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.interceptor.api.IInterceptorService; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionLoader; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; +import ca.uhn.fhir.jpa.subscription.module.channel.SubscriptionChannelRegistry; import com.google.common.annotations.VisibleForTesting; import org.hl7.fhir.dstu2.model.Subscription; import org.slf4j.Logger; @@ -47,6 +48,8 @@ public class SubscriptionInterceptorLoader { @Autowired private SubscriptionRegistry mySubscriptionRegistry; @Autowired + private SubscriptionChannelRegistry mySubscriptionChannelRegistry; + @Autowired private ApplicationContext myApplicationContext; @Autowired private IInterceptorService myInterceptorRegistry; @@ -69,8 +72,10 @@ public class SubscriptionInterceptorLoader { private void loadSubscriptions() { ourLog.info("Loading subscriptions into the SubscriptionRegistry..."); // Activate scheduled subscription loads into the SubscriptionRegistry - myApplicationContext.getBean(SubscriptionLoader.class); + SubscriptionLoader loader = myApplicationContext.getBean(SubscriptionLoader.class); + loader.syncSubscriptions(); ourLog.info("...{} subscriptions loaded", mySubscriptionRegistry.size()); + ourLog.info("...{} subscription channels started", mySubscriptionChannelRegistry.size()); } @VisibleForTesting diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistry.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistry.java index 8fbf0bfdbb5..84b66439bca 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistry.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistry.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.subscription.module.channel; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; import org.slf4j.Logger; @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.MessageHandler; import org.springframework.stereotype.Component; +import java.util.Collection; import java.util.Optional; @Component @@ -58,7 +59,7 @@ public class SubscriptionChannelRegistry { String channelName = theActiveSubscription.getChannelName(); boolean removed = myActiveSubscriptionByChannelName.remove(channelName, theActiveSubscription.getId()); if (!removed) { - ourLog.warn("Request to remove subscription {} that was not added", theActiveSubscription.getId()); + ourLog.warn("Failed to remove subscription {} from channel {}", theActiveSubscription.getId() ,channelName); } // This was the last one. Shut down the channel @@ -78,4 +79,15 @@ public class SubscriptionChannelRegistry { public int size() { return mySubscriptionChannelCache.size(); } + + @VisibleForTesting + public void logForUnitTest() { + ourLog.info("Channels: {}", size()); + for (String key : myActiveSubscriptionByChannelName.keySet()) { + Collection list = myActiveSubscriptionByChannelName.get(key); + for (String value : list) { + ourLog.info("{}: {}", key, value); + } + } + } }