From 1a90c7e9cebcfacbb487698b0abdc63b9a3429c7 Mon Sep 17 00:00:00 2001 From: longma1 <32119004+longma1@users.noreply.github.com> Date: Fri, 3 Jun 2022 12:54:54 -0600 Subject: [PATCH] =?UTF-8?q?added=20fix=20for=20subscription=20in=20default?= =?UTF-8?q?=20partition=20when=20default=20partitio=E2=80=A6=20(#3670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added fix for subscription in default partition when default partition's id is null * added changelog Co-authored-by: Long Ma --- ...nt-subscription-default-partition-fix.yaml | 6 ++++ .../SubscriptionMatchingSubscriber.java | 2 +- .../SubscriptionMatchingSubscriberTest.java | 36 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_1_0/3669-multitenant-subscription-default-partition-fix.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_1_0/3669-multitenant-subscription-default-partition-fix.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_1_0/3669-multitenant-subscription-default-partition-fix.yaml new file mode 100644 index 00000000000..8f7e07a09ab --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_1_0/3669-multitenant-subscription-default-partition-fix.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 2669 +title: "Previously subscriptions in a partition with the id null will be matched against incoming resources from all partitions. +Changed to subscriptions will only match against incoming resources in the partition the subscription exists in unless +cross partition subscription is enabled and the subscription has the appropriate extension." diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java index e74b12a2b04..40043edcab5 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java @@ -127,7 +127,7 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { for (ActiveSubscription nextActiveSubscription : subscriptions) { // skip if the partitions don't match CanonicalSubscription subscription = nextActiveSubscription.getSubscription(); - if (subscription != null && subscription.getRequestPartitionId() != null && theMsg.getPartitionId() != null && + if (subscription != null && theMsg.getPartitionId() != null && theMsg.getPartitionId().hasPartitionIds() && !subscription.getCrossPartitionEnabled() && !theMsg.getPartitionId().hasPartitionId(subscription.getRequestPartitionId())) { continue; 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 6da61d7b999..6e8cbcfd452 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 @@ -245,6 +245,42 @@ public class SubscriptionMatchingSubscriberTest extends BaseBlockingQueueSubscri mySubscriptionResourceNotMatched.awaitExpected(); } + @Test + public void testSubscriptionOnDefaultPartitionAndResourceOnDiffPartitionNotMatch() throws InterruptedException { + myPartitionSettings.setPartitioningEnabled(true); + String payload = "application/fhir+json"; + + String code = "1000000050"; + String criteria = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; + + RequestPartitionId requestPartitionId = RequestPartitionId.defaultPartition(); + Subscription subscription = makeActiveSubscription(criteria, payload, ourListenerServerBase); + mockSubscriptionRead(requestPartitionId, subscription); + sendSubscription(subscription, requestPartitionId, true); + + mySubscriptionResourceNotMatched.setExpectedCount(1); + sendObservation(code, "SNOMED-CT", RequestPartitionId.fromPartitionId(1)); + mySubscriptionResourceNotMatched.awaitExpected(); + } + + @Test + public void testSubscriptionOnAPartitionAndResourceOnDefaultPartitionNotMatch() throws InterruptedException { + myPartitionSettings.setPartitioningEnabled(true); + String payload = "application/fhir+json"; + + String code = "1000000050"; + String criteria = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; + + RequestPartitionId requestPartitionId = RequestPartitionId.fromPartitionId(1); + Subscription subscription = makeActiveSubscription(criteria, payload, ourListenerServerBase); + mockSubscriptionRead(requestPartitionId, subscription); + sendSubscription(subscription, requestPartitionId, true); + + mySubscriptionResourceNotMatched.setExpectedCount(1); + sendObservation(code, "SNOMED-CT", RequestPartitionId.defaultPartition()); + mySubscriptionResourceNotMatched.awaitExpected(); + } + @Test public void testSubscriptionOnOnePartitionMatchResourceOnMultiplePartitions() throws InterruptedException { myPartitionSettings.setPartitioningEnabled(true);