test cleanup

This commit is contained in:
Ken Stevens 2019-10-02 07:31:16 -04:00
parent 82543c01d6
commit ba37ce0588
6 changed files with 37 additions and 28 deletions

View File

@ -1,18 +1,27 @@
package ca.uhn.fhir.jpa.subscription.module; package ca.uhn.fhir.jpa.subscription.module;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry;
import ca.uhn.fhir.jpa.subscription.module.channel.SubscriptionChannelRegistry;
import ca.uhn.fhir.jpa.subscription.module.config.TestSubscriptionDstu3Config; import ca.uhn.fhir.jpa.subscription.module.config.TestSubscriptionDstu3Config;
import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.StopWatch;
import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ContextConfiguration(classes = {TestSubscriptionDstu3Config.class}) @ContextConfiguration(classes = {TestSubscriptionDstu3Config.class})
public abstract class BaseSubscriptionDstu3Test extends BaseSubscriptionTest { public abstract class BaseSubscriptionDstu3Test extends BaseSubscriptionTest {
@Autowired
protected SubscriptionRegistry mySubscriptionRegistry;
@Autowired
protected SubscriptionChannelRegistry mySubscriptionChannelRegistry;
private final SubscriptionTestHelper mySubscriptionTestHelper = new SubscriptionTestHelper(); private final SubscriptionTestHelper mySubscriptionTestHelper = new SubscriptionTestHelper();
@ -53,4 +62,22 @@ public abstract class BaseSubscriptionDstu3Test extends BaseSubscriptionTest {
protected Subscription makeSubscriptionWithStatus(String theCriteria, String thePayload, String theEndpoint, Subscription.SubscriptionStatus status) { protected Subscription makeSubscriptionWithStatus(String theCriteria, String thePayload, String theEndpoint, Subscription.SubscriptionStatus status) {
return mySubscriptionTestHelper.makeSubscriptionWithStatus(theCriteria, thePayload, theEndpoint, status); return mySubscriptionTestHelper.makeSubscriptionWithStatus(theCriteria, thePayload, theEndpoint, status);
} }
protected void clearRegistry() {
mySubscriptionRegistry.unregisterAllSubscriptions();
await().until(this::registryEmpty);
}
private boolean registryEmpty() {
return mySubscriptionRegistry.size() == 0 && mySubscriptionChannelRegistry.size() == 0;
}
protected void assertRegistrySize(int theSize) {
assertRegistrySize(theSize, theSize);
}
protected void assertRegistrySize(int theSubscriptionRegistrySize, int theSubscriptionChannelRegistrySize) {
assertEquals(theSubscriptionRegistrySize, mySubscriptionRegistry.size());
assertEquals(theSubscriptionChannelRegistrySize, mySubscriptionChannelRegistry.size());
}
} }

View File

@ -14,19 +14,9 @@ public abstract class BaseSubscriptionRegistryTest extends BaseSubscriptionDstu3
public static final String ORIG_CRITERIA = "Patient?"; public static final String ORIG_CRITERIA = "Patient?";
public static final String NEW_CRITERIA = "Observation?"; public static final String NEW_CRITERIA = "Observation?";
@Autowired
SubscriptionRegistry mySubscriptionRegistry;
@Autowired
SubscriptionChannelRegistry mySubscriptionChannelRegistry;
@After @After
public void clearRegistryAfter() { public void clearRegistryAfter() {
mySubscriptionRegistry.unregisterAllSubscriptions(); super.clearRegistry();
await().until(this::registryEmpty);
}
public boolean registryEmpty() {
return mySubscriptionRegistry.size() == 0 && mySubscriptionChannelRegistry.size() == 0;
} }
protected Subscription createSubscription() { protected Subscription createSubscription() {
@ -45,14 +35,4 @@ public abstract class BaseSubscriptionRegistryTest extends BaseSubscriptionDstu3
channel.setEndpoint("http://unused.test.endpoint/"); channel.setEndpoint("http://unused.test.endpoint/");
theSubscription.setChannel(channel); theSubscription.setChannel(channel);
} }
protected void assertRegistrySize(int theSize) {
assertRegistrySize(theSize, theSize);
}
protected void assertRegistrySize(int theSubscriptionRegistrySize, int theSubscriptionChannelRegistrySize) {
assertEquals(theSubscriptionRegistrySize, mySubscriptionRegistry.size());
assertEquals(theSubscriptionChannelRegistrySize, mySubscriptionChannelRegistry.size());
}
} }

View File

@ -102,6 +102,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base
mySubscriptionMatchingPost.clear(); mySubscriptionMatchingPost.clear();
mySubscriptionActivatedPost.clear(); mySubscriptionActivatedPost.clear();
ourObservationListener.clear(); ourObservationListener.clear();
super.clearRegistry();
} }
public <T extends IBaseResource> T sendResource(T theResource) throws InterruptedException { public <T extends IBaseResource> T sendResource(T theResource) throws InterruptedException {

View File

@ -10,7 +10,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class SubscriptionLoaderFhirClientTest extends BaseBlockingQueueSubscribableChannelDstu3Test { public class SubscriptionLoaderFhirClientTest extends BaseBlockingQueueSubscribableChannelDstu3Test {
@Test @Test
public void testSubscriptionLoaderFhirClient() throws InterruptedException { public void testSubscriptionLoaderFhirClient() throws InterruptedException {
String payload = "application/fhir+json"; String payload = "application/fhir+json";
@ -22,13 +22,13 @@ public class SubscriptionLoaderFhirClientTest extends BaseBlockingQueueSubscriba
subs.add(makeActiveSubscription(criteria1, payload, ourListenerServerBase)); subs.add(makeActiveSubscription(criteria1, payload, ourListenerServerBase));
subs.add(makeActiveSubscription(criteria2, payload, ourListenerServerBase)); subs.add(makeActiveSubscription(criteria2, payload, ourListenerServerBase));
mySubscriptionActivatedPost.setExpectedCount(2); mySubscriptionActivatedPost.setExpectedCount(2);
initSubscriptionLoader(subs, "uuid"); initSubscriptionLoader(subs, "uuid");
mySubscriptionActivatedPost.awaitExpected(); mySubscriptionActivatedPost.awaitExpected();
ourObservationListener.setExpectedCount(1); ourObservationListener.setExpectedCount(1);
sendObservation(myCode, "SNOMED-CT"); sendObservation(myCode, "SNOMED-CT");
ourObservationListener.awaitExpected(); ourObservationListener.awaitExpected();
waitForSize(0, ourCreatedObservations); waitForSize(0, ourCreatedObservations);
waitForSize(1, ourUpdatedObservations); waitForSize(1, ourUpdatedObservations);

View File

@ -41,9 +41,9 @@ public class SubscriptionLoaderTest extends BaseBlockingQueueSubscribableChannel
subs.add(makeActiveSubscription(criteria1, payload, ourListenerServerBase)); subs.add(makeActiveSubscription(criteria1, payload, ourListenerServerBase));
subs.add(makeActiveSubscription(criteria2, payload, ourListenerServerBase)); subs.add(makeActiveSubscription(criteria2, payload, ourListenerServerBase));
mySubscriptionActivatedPost.setExpectedCount(2); mySubscriptionActivatedPost.setExpectedCount(2);
initSubscriptionLoader(subs, "uuid"); initSubscriptionLoader(subs, "uuid");
mySubscriptionActivatedPost.awaitExpected(); mySubscriptionActivatedPost.awaitExpected();
assertEquals(0, myMockFhirClientSubscriptionProvider.getFailCount()); assertEquals(0, myMockFhirClientSubscriptionProvider.getFailCount());
} }
} }

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription;
import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscriptionChannelType; import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscriptionChannelType;
import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry;
import ca.uhn.fhir.jpa.subscription.module.channel.SubscriptionChannelRegistry;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;