Skip to content

Commit

Permalink
merge release branch to master (#4811)
Browse files Browse the repository at this point in the history
* Force Verify tests

* fix ITs (#4809)

* fix RestHookTestR5IT

* fix intermittent

---------

Co-authored-by: Ken Stevens <[email protected]>

---------

Co-authored-by: Tadgh <[email protected]>
Co-authored-by: Ken Stevens <[email protected]>
  • Loading branch information
3 people committed May 3, 2023
1 parent a3c33d2 commit 350d1a4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testRestHookSubscriptionApplicationFhirJson() throws Exception {
Observation sentObservation = sendObservationExpectDelivery();

// Should see 1 subscription notification
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

Observation obs = assertBundleAndGetObservation(subscription, sentObservation);
assertEquals(Enumerations.ObservationStatus.FINAL, obs.getStatus());
Expand All @@ -112,7 +112,7 @@ public void testUpdatesHaveCorrectMetadata() throws Exception {
sentObservation = myObservationDao.read(sentObservation.getIdElement().toUnqualifiedVersionless());

// Should see 1 subscription notification
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

Observation receivedObs = assertBundleAndGetObservation(subscription, sentObservation);

Expand All @@ -132,7 +132,7 @@ public void testUpdatesHaveCorrectMetadata() throws Exception {
sentObservation = myObservationDao.read(sentObservation.getIdElement().toUnqualifiedVersionless());

// Should see a second subscription notification
assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);

receivedObs = assertBundleAndGetObservation(subscription, sentObservation);

Expand Down Expand Up @@ -200,7 +200,7 @@ public void testUpdatesHaveCorrectMetadataUsingTransactions() throws Exception {
bundle.addEntry().setResource(sentObservation).getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl("Observation");
// Send the transaction
Bundle responseBundle = sendTransaction(bundle, true);
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

Observation receivedObs = assertBundleAndGetObservation(subscription, sentObservation);

Expand All @@ -226,7 +226,7 @@ public void testUpdatesHaveCorrectMetadataUsingTransactions() throws Exception {
bundle.addEntry().setResource(sentObservation).getRequest().setMethod(Bundle.HTTPVerb.PUT).setUrl(obs.getIdElement().toUnqualifiedVersionless().getValue());
// Send the transaction
sendTransaction(bundle, true);
assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);

receivedObs = assertBundleAndGetObservation(subscription, sentObservation);
obs = myObservationDao.read(obs.getIdElement().toUnqualifiedVersionless());
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testRestHookSubscriptionNoopUpdateDoesntTriggerNewDelivery() throws

Observation sentObservation = sendObservationExpectDelivery();

assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

Observation obs = assertBundleAndGetObservation(subscription, sentObservation);

Expand All @@ -311,7 +311,7 @@ public void testRestHookSubscriptionNoopUpdateDoesntTriggerNewDelivery() throws
Thread.sleep(1000);

// Should be no further deliveries
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
}

@Test
Expand All @@ -325,7 +325,7 @@ public void testRestHookSubscriptionApplicationJsonDisableVersionIdInDelivery()
ourLog.info("** About to send observation");
Observation sentObservation1 = sendObservationExpectDelivery();

assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

Observation obs = assertBundleAndGetObservation(subscription, sentObservation1);

Expand All @@ -346,13 +346,13 @@ public void testRestHookSubscriptionApplicationJsonDisableVersionIdInDelivery()
ourLog.info("** About to send observation");
Observation sentObservation2 = sendObservationExpectDelivery();

assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);

Observation obs2 = assertBundleAndGetObservation(subscription, sentObservation2);

Assertions.assertEquals(Constants.CT_FHIR_JSON_NEW, getLastSystemProviderContentType());

idElement =obs2.getIdElement();
idElement = obs2.getIdElement();
assertEquals(sentObservation2.getIdElement().getIdPart(), idElement.getIdPart());
// Now VersionId is stripped
assertEquals(null, idElement.getVersionIdPart());
Expand Down Expand Up @@ -387,7 +387,7 @@ public void testRestHookSubscriptionDoesntGetLatestVersionByDefault() throws Exc
myStoppableSubscriptionDeliveringRestHookSubscriber.unPause();
mySubscriptionDeliveredLatch.awaitExpected();

assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);

Observation observation1 = getReceivedObservations().stream()
.filter(t -> "1".equals(t.getIdElement().getVersionIdPart()))
Expand Down Expand Up @@ -453,7 +453,7 @@ public void testRestHookSubscriptionApplicationJson() throws Exception {
waitForActivatedSubscriptionCount(2);

Observation sentObservation1 = sendObservationExpectDelivery();
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
Observation receivedObs = assertBundleAndGetObservation(subscription1, sentObservation1);
assertEquals(Constants.CT_FHIR_JSON_NEW, getLastSystemProviderContentType());

Expand All @@ -466,25 +466,26 @@ public void testRestHookSubscriptionApplicationJson() throws Exception {

Observation observation2 = sendObservationExpectDelivery();

assertReceivedTransactionCount(3);
awaitUntilReceivedTransactionCount(3);

deleteSubscription(subscription2);

Observation observationTemp3 = sendObservationExpectDelivery();

// Should see only one subscription notification
assertReceivedTransactionCount(4);
awaitUntilReceivedTransactionCount(4);

Observation observation3 = myClient.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept = new CodeableConcept();
observation3.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(OBS_CODE + "111");
coding.setSystem("SNOMED-CT");
updateResource(observation3, false);
updateResource(observation3, true);

// Should see no subscription notification
assertReceivedTransactionCount(4);
// Should see one subscription notification even though the new version doesn't match, the old version still does and our subscription topic
// is configured to match if either the old version matches or the new version matches
awaitUntilReceivedTransactionCount(5);

Observation observation3a = myClient.read(Observation.class, observationTemp3.getId());

Expand All @@ -496,7 +497,7 @@ public void testRestHookSubscriptionApplicationJson() throws Exception {
updateResource(observation3a, true);

// Should see only one subscription notification
assertReceivedTransactionCount(5);
awaitUntilReceivedTransactionCount(6);

assertFalse(subscription1.getId().equals(subscription2.getId()));
assertFalse(sentObservation1.getId().isEmpty());
Expand All @@ -509,13 +510,12 @@ private void deleteSubscription(Subscription subscription2) throws InterruptedEx
mySubscriptionTopicsCheckedLatch.awaitExpected();
}

private void assertReceivedTransactionCount(int theExpected) {
if (getSystemProviderCount() != theExpected) {
String list = getReceivedObservations().stream()
.map(t -> t.getIdElement().toUnqualifiedVersionless().getValue() + " " + t.getCode().getCodingFirstRep().getCode())
.collect(Collectors.joining(", "));
throw new AssertionError("Expected " + theExpected + " transactions, have " + getSystemProviderCount() + ": " + list);
}
private void awaitUntilReceivedTransactionCount(int theExpected) {
String list = getReceivedObservations().stream()
.map(t -> t.getIdElement().toUnqualifiedVersionless().getValue() + " " + t.getCode().getCodingFirstRep().getCode())
.collect(Collectors.joining(", "));
String errorMessage = "Expected " + theExpected + " transactions, have " + getSystemProviderCount() + ": " + list;
await(errorMessage).until(() -> getSystemProviderCount() == theExpected);
}

@Test
Expand Down Expand Up @@ -577,7 +577,7 @@ public void testSubscriptionTriggerViaSubscription() throws Exception {
sendTransaction(requestBundle, true);

// Should see 1 subscription notification
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
Observation receivedObs = assertBundleAndGetObservation(subscription, sentObservation);
assertEquals(Constants.CT_FHIR_XML_NEW, getLastSystemProviderContentType());

Expand All @@ -600,7 +600,7 @@ public void testUpdateSubscriptionToMatchLater() throws Exception {
ourLog.info("** About to send observation that wont match");

Observation observation1 = sendObservation(OBS_CODE, "SNOMED-CT", false);
assertReceivedTransactionCount(0);
awaitUntilReceivedTransactionCount(0);

ourLog.info("** About to update subscription topic");
SubscriptionTopic subscriptionTopicTemp = myClient.read(SubscriptionTopic.class, subscriptionTopic.getId());
Expand All @@ -612,14 +612,14 @@ public void testUpdateSubscriptionToMatchLater() throws Exception {
Observation observation2 = sendObservationExpectDelivery();

// Should see a subscription notification this time
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);

deleteSubscription(subscription);

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

// No more matches
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
}

private static void setSubscriptionTopicCriteria(SubscriptionTopic subscriptionTopicTemp, String theCriteria) {
Expand All @@ -645,7 +645,7 @@ public void testRestHookSubscriptionApplicationXmlJson() throws Exception {
Observation observation1 = sendObservationExpectDelivery();

// Should see 1 subscription notification
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
assertEquals(Constants.CT_FHIR_XML_NEW, getLastSystemProviderContentType());
}

Expand Down Expand Up @@ -685,7 +685,7 @@ public void testDisableSubscription() throws Exception {
Observation sentObservation = sendObservationExpectDelivery();

// Should see 1 subscription notification
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
Observation receivedObservation = assertBundleAndGetObservation(subscription, sentObservation);

// Disable
Expand All @@ -696,7 +696,7 @@ public void testDisableSubscription() throws Exception {
sendObservation(OBS_CODE, "SNOMED-CT", false);

// Should see no new delivery
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
}

@Test
Expand Down Expand Up @@ -786,26 +786,26 @@ public void testCustomSearchParam() throws Exception {
Observation observation = new Observation();
observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("Catheter"));
createResource(observation, true);
assertReceivedTransactionCount(1);
awaitUntilReceivedTransactionCount(1);
assertBundleAndGetObservation(subscription, observation);
}
{
Observation observation = new Observation();
observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("PD Catheter"));
createResource(observation, true);
assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);
assertBundleAndGetObservation(subscription, observation);
}
{
Observation observation = new Observation();
createResource(observation, false);
assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);
}
{
Observation observation = new Observation();
observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("XXX"));
createResource(observation, false);
assertReceivedTransactionCount(2);
awaitUntilReceivedTransactionCount(2);
}
}

Expand All @@ -823,12 +823,12 @@ private Observation assertBundleAndGetObservation(Subscription subscription, Obs
private SubscriptionTopic createObservationSubscriptionTopic(String theCode) throws InterruptedException {
SubscriptionTopic subscriptionTopic = buildSubscriptionTopic(theCode);
return createSubscriptionTopic(subscriptionTopic);
}
}

@Nonnull
private static SubscriptionTopic buildSubscriptionTopic(String theCode) {
SubscriptionTopic retval = new SubscriptionTopic();
retval.setUrl(SUBSCRIPTION_TOPIC_TEST_URL+ theCode);
retval.setUrl(SUBSCRIPTION_TOPIC_TEST_URL + theCode);
retval.setStatus(Enumerations.PublicationStatus.ACTIVE);
SubscriptionTopic.SubscriptionTopicResourceTriggerComponent trigger = retval.addResourceTrigger();
trigger.setResource("Observation");
Expand Down
2 changes: 1 addition & 1 deletion test-job-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
JAVA_HOME_11_X64: /usr/java/openjdk-17
inputs:
mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
goals: 'clean test jacoco:report -pl ${{ p.module }}'
goals: 'clean verify jacoco:report -pl ${{ p.module }}'
# These are Maven CLI options (and show up in the build logs) - "-nsu"=Don't update snapshots. We can remove this when Maven OSS is more healthy
options: '-P JACOCO,CI,ERRORPRONE -e -B -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER) -Dmaven.wagon.http.pool=false -Dhttp.keepAlive=false -Dstyle.color=always -Djansi.force=true'
# These are JVM options (and don't show up in the build logs)
Expand Down

0 comments on commit 350d1a4

Please sign in to comment.