mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-09 14:33:32 +00:00
extend pointcutlatch and simplify FhirClientResourceRetriever (#1737)
* extend pointcutlatch and simplify FhirClientResourceRetriever * extend pointcutlatch and simplify FhirClientResourceRetriever
This commit is contained in:
parent
8c78e465b1
commit
b2f9dd4578
@ -45,6 +45,6 @@ public class FhirClientResourceRetriever implements IResourceRetriever {
|
|||||||
public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException {
|
public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException {
|
||||||
RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(payloadId.getResourceType());
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
|
|||||||
private int myDefaultTimeoutSeconds = DEFAULT_TIMEOUT_SECONDS;
|
private int myDefaultTimeoutSeconds = DEFAULT_TIMEOUT_SECONDS;
|
||||||
private final Pointcut myPointcut;
|
private final Pointcut myPointcut;
|
||||||
private int myInitialCount;
|
private int myInitialCount;
|
||||||
|
private boolean myExactMatch;
|
||||||
|
|
||||||
|
|
||||||
public PointcutLatch(Pointcut thePointcut) {
|
public PointcutLatch(Pointcut thePointcut) {
|
||||||
@ -69,19 +70,32 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (myCountdownLatch.get() != null) {
|
||||||
throw new PointcutLatchException("setExpectedCount() called before previous awaitExpected() completed.");
|
throw new PointcutLatchException("setExpectedCount() called before previous awaitExpected() completed.");
|
||||||
}
|
}
|
||||||
createLatch(count);
|
myExactMatch = theExactMatch;
|
||||||
ourLog.info("Expecting {} calls to {} latch", count, name);
|
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<>()));
|
myFailures.set(Collections.synchronizedList(new ArrayList<>()));
|
||||||
myCalledWith.set(Collections.synchronizedList(new ArrayList<>()));
|
myCalledWith.set(Collections.synchronizedList(new ArrayList<>()));
|
||||||
myCountdownLatch.set(new CountDownLatch(count));
|
myCountdownLatch.set(new CountDownLatch(theCount));
|
||||||
myInitialCount = count;
|
myInitialCount = theCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFailure(String failure) {
|
private void addFailure(String failure) {
|
||||||
@ -153,10 +167,14 @@ public class PointcutLatch implements IAnonymousInterceptor, IPointcutLatch {
|
|||||||
@Override
|
@Override
|
||||||
public void invoke(Pointcut thePointcut, HookParams theArgs) {
|
public void invoke(Pointcut thePointcut, HookParams theArgs) {
|
||||||
CountDownLatch latch = myCountdownLatch.get();
|
CountDownLatch latch = myCountdownLatch.get();
|
||||||
if (latch == null) {
|
if (myExactMatch) {
|
||||||
throw new PointcutLatchException("invoke() called outside of setExpectedCount() .. awaitExpected(). Probably got more invocations than expected or clear() was called before invoke() arrived.", theArgs);
|
if (latch == null) {
|
||||||
} else if (latch.getCount() <= 0) {
|
throw new PointcutLatchException("invoke() called outside of setExpectedCount() .. awaitExpected(). Probably got more invocations than expected or clear() was called before invoke() arrived.", theArgs);
|
||||||
addFailure("invoke() called when countdown was zero.");
|
} else if (latch.getCount() <= 0) {
|
||||||
|
addFailure("invoke() called when countdown was zero.");
|
||||||
|
}
|
||||||
|
} else if (latch == null || latch.getCount() <= 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myCalledWith.get() != null) {
|
if (myCalledWith.get() != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user