Skip to content

Commit

Permalink
Bug fix in subscription processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Aug 10, 2018
1 parent 93bd018 commit 98d794e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Expand Up @@ -177,10 +177,13 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
}

private void registerSubscriptionUnlessAlreadyRegistered(IBaseResource theSubscription) {
if (!mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
if (mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
ourLog.info("Updating already-registered active subscription {}", theSubscription.getIdElement().toUnqualified().getValue());
mySubscriptionInterceptor.unregisterSubscription(theSubscription.getIdElement());
} else {
ourLog.info("Registering active subscription {}", theSubscription.getIdElement().toUnqualified().getValue());
mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(), theSubscription);
}
mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(), theSubscription);
}

@VisibleForTesting
Expand Down
Expand Up @@ -105,7 +105,7 @@ private void logGetConnectionStackTrace() {

DataSource dataSource = ProxyDataSourceBuilder
.create(retVal)
.logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL")
// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL")
.logSlowQueryBySlf4j(10, TimeUnit.SECONDS)
.countQuery(new ThreadQueryCountHolder())
.build();
Expand Down
Expand Up @@ -355,6 +355,53 @@ public void testRestHookSubscriptionApplicationXml() throws Exception {
Assert.assertFalse(observation2.getId().isEmpty());
}


@Test
public void testUpdateSubscriptionToMatchLater() throws Exception {
String payload = "application/xml";

String code = "1000000050";
String criteriaBad = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";

ourLog.info("** About to create non-matching subscription");

Subscription subscription2 = createSubscription(criteriaBad, payload, ourListenerServerBase);

ourLog.info("** About to send observation that wont match");

Observation observation1 = sendObservation(code, "SNOMED-CT");

// Criteria didn't match, shouldn't see any updates
waitForQueueToDrain();
Thread.sleep(1000);
assertEquals(0, ourUpdatedObservations.size());

Subscription subscriptionTemp = myClient.read().resource(Subscription.class).withId(subscription2.getId()).execute();
Assert.assertNotNull(subscriptionTemp);
String criteriaGood = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
subscriptionTemp.setCriteria(criteriaGood);
ourLog.info("** About to update subscription");
myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
waitForQueueToDrain();

ourLog.info("** About to send Observation 2");
Observation observation2 = sendObservation(code, "SNOMED-CT");
waitForQueueToDrain();

// Should see a subscription notification this time
waitForSize(0, ourCreatedObservations);
waitForSize(1, ourUpdatedObservations);

myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute();

Observation observationTemp3 = sendObservation(code, "SNOMED-CT");

// No more matches
Thread.sleep(1000);
assertEquals(1, ourUpdatedObservations.size());
}


@Test
public void testRestHookSubscriptionApplicationXmlJson() throws Exception {
String payload = "application/fhir+xml";
Expand Down

0 comments on commit 98d794e

Please sign in to comment.