extend pointcutlatch and simplify FhirClientResourceRetriever (#1737)

* extend pointcutlatch and simplify FhirClientResourceRetriever

* extend pointcutlatch and simplify FhirClientResourceRetriever
This commit is contained in:
Ken Stevens 2020-02-28 16:38:13 -05:00 committed by GitHub
parent 8c78e465b1
commit b2f9dd4578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 11 deletions

View File

@ -45,6 +45,6 @@ public class FhirClientResourceRetriever implements IResourceRetriever {
public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException {
RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(payloadId.getResourceType());
return myClient.search().forResource(resourceDef.getName()).withIdAndCompartment(payloadId.getIdPart(), payloadId.getResourceType()).execute();
return myClient.read().resource(resourceDef.getName()).withId(payloadId).execute();
}
}

View File

@ -51,6 +51,7 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
private int myDefaultTimeoutSeconds = DEFAULT_TIMEOUT_SECONDS;
private final Pointcut myPointcut;
private int myInitialCount;
private boolean myExactMatch;
public PointcutLatch(Pointcut thePointcut) {
@ -69,19 +70,32 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
}
@Override
public void setExpectedCount(int count) {
public void setExpectedCount(int theCount) {
this.setExpectedCount(theCount, true);
}
public void setExpectedCount(int theCount, boolean theExactMatch) {
if (myCountdownLatch.get() != null) {
throw new PointcutLatchException("setExpectedCount() called before previous awaitExpected() completed.");
}
createLatch(count);
ourLog.info("Expecting {} calls to {} latch", count, name);
myExactMatch = theExactMatch;
createLatch(theCount);
if (theExactMatch) {
ourLog.info("Expecting exactly {} calls to {} latch", theCount, name);
} else {
ourLog.info("Expecting at least {} calls to {} latch", theCount, name);
}
}
private void createLatch(int count) {
public void setExpectAtLeast(int theCount) {
setExpectedCount(theCount, false);
}
private void createLatch(int theCount) {
myFailures.set(Collections.synchronizedList(new ArrayList<>()));
myCalledWith.set(Collections.synchronizedList(new ArrayList<>()));
myCountdownLatch.set(new CountDownLatch(count));
myInitialCount = count;
myCountdownLatch.set(new CountDownLatch(theCount));
myInitialCount = theCount;
}
private void addFailure(String failure) {
@ -153,10 +167,14 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
@Override
public void invoke(Pointcut thePointcut, HookParams theArgs) {
CountDownLatch latch = myCountdownLatch.get();
if (latch == null) {
throw new PointcutLatchException("invoke() called outside of setExpectedCount() .. awaitExpected(). Probably got more invocations than expected or clear() was called before invoke() arrived.", theArgs);
} else if (latch.getCount() <= 0) {
addFailure("invoke() called when countdown was zero.");
if (myExactMatch) {
if (latch == null) {
throw new PointcutLatchException("invoke() called outside of setExpectedCount() .. awaitExpected(). Probably got more invocations than expected or clear() was called before invoke() arrived.", theArgs);
} else if (latch.getCount() <= 0) {
addFailure("invoke() called when countdown was zero.");
}
} else if (latch == null || latch.getCount() <= 0) {
return;
}
if (myCalledWith.get() != null) {