Minor addition to PointcutLatch to support an inline runnable

This commit is contained in:
Tadgh 2020-07-17 12:06:19 -07:00
parent aebdef1e3f
commit e540e4b0a2
3 changed files with 28 additions and 36 deletions

View File

@ -1,10 +1,11 @@
package ca.uhn.fhir.jpa.entity;
public enum EmpiTargetType {
PATIENT("patient"),
PRACTITIONER("practitioner");
PATIENT,
PRACTITIONER,
PERSON;
EmpiTargetType(String thePractitioner) {}
EmpiTargetType(){}
public static EmpiTargetType valueOfCaseInsensitive(String theValue) {
return valueOf(EmpiTargetType.class, theValue.toUpperCase());

View File

@ -2,20 +2,15 @@ package ca.uhn.fhir.jpa.empi.provider;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.test.concurrency.PointcutLatch;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Nonnull;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ -23,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.fail;
public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
protected Practitioner myPractitioner;
protected StringType myPractitionerId;
protected Person myPractitionerPerson;
@ -33,6 +27,7 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
IInterceptorService myInterceptorService;
PointcutLatch afterEmpiLatch = new PointcutLatch(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED);
@BeforeEach
public void before() {
super.before();
@ -42,9 +37,6 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue());
myInterceptorService.registerAnonymousInterceptor(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, afterEmpiLatch);
}
@AfterEach
public void after() {
afterEmpiLatch.clear();
}
@ -55,20 +47,20 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
StringType criteria = null;
myEmpiProviderR4.clearEmpiLinks(null);
myEmpiProviderR4.batchRunEmpi(practitionerType, criteria, null);
afterEmpiLatch.runWithExpectedCount(1, () -> {
myEmpiProviderR4.batchRunEmpi(practitionerType, criteria, null);
});
assertLinkCount(1);
}
@Test
public void testBatchRunOnAllPatients() {
public void testBatchRunOnAllPatients() throws InterruptedException {
assertLinkCount(2);
StringType patientType = new StringType("Patient");
StringType criteria = null;
myEmpiProviderR4.clearEmpiLinks(null);
myEmpiProviderR4.batchRunEmpi(patientType, criteria, null);
afterEmpiLatch.runWithExpectedCount(1, () -> {
myEmpiProviderR4.batchRunEmpi(patientType, criteria, null);
});
assertLinkCount(1);
}
@ -77,13 +69,11 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
StringType observationType= new StringType("Observation");
StringType criteria = null;
myEmpiProviderR4.clearEmpiLinks(null);
afterEmpiLatch.setExpectedCount(1);
try {
myEmpiProviderR4.batchRunEmpi(observationType, criteria, null);
fail();
} catch(InvalidRequestException e) {
assertThat(e.getMessage(), is(equalTo("$empi-run does not support resource type: Observation")));
assertThat(e.getMessage(), is(equalTo("$empi-batch-run does not support resource type: Observation")));
}
}
@ -94,9 +84,10 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
StringType criteria = null;
myEmpiProviderR4.clearEmpiLinks(null);
afterEmpiLatch.setExpectedCount(1);
myEmpiProviderR4.batchRunEmpi(patientType, criteria, null);
afterEmpiLatch.awaitExpected();
afterEmpiLatch.runWithExpectedCount(1, () -> {
myEmpiProviderR4.batchRunEmpi(patientType, criteria, null);
});
assertLinkCount(1);
}
@ -114,15 +105,4 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
assertThat(e.getMessage(), is(equalTo("Failed to parse match URL[Patient?death-date=2020-06-01] - Resource type Practitioner does not have a parameter with name: death-date")));
}
}
@Nonnull
protected EmpiLink getOnlyPractitionerLink() {
return myEmpiLinkDaoSvc.findEmpiLinkByTarget(myPractitioner).get();
}
@Nonnull
protected List<EmpiLink> getPractitionerLinks() {
return myEmpiLinkDaoSvc.findEmpiLinksByTarget(myPractitioner);
}
}

View File

@ -67,6 +67,17 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
myPointcut = null;
}
public void runWithExpectedCount(int theExpectedCount, Runnable r) {
this.setExpectedCount(theExpectedCount);
r.run();
try {
this.awaitExpected();
} catch (InterruptedException theE) {
ourLog.error("InterruptedException while awaiting invocation of {}", this.myPointcut.name());
theE.printStackTrace();
}
}
public long getLastInvoke() {
return myLastInvoke.get();
}