Add some test logging

This commit is contained in:
jamesagnew 2019-11-08 05:53:59 -05:00
parent c027ff27c3
commit 7c8342dcc1
3 changed files with 179 additions and 124 deletions

View File

@ -1599,6 +1599,33 @@ public enum Pointcut {
),
/**
* THIS IS AN EXPERIMENTAL HOOK AND MAY BE REMOVED OR CHANGED WITHOUT WARNING.
*
* Note that this is a performance tracing hook. Use with caution in production
* systems, since calling it may (or may not) carry a cost.
* <p>
* This hook is invoked when a search has found an individual ID.
* </p>
* Hooks may accept the following parameters:
* <ul>
* <li>
* java.lang.Integer - The query ID
* </li>
* <li>
* java.lang.Object - The ID
* </li>
* </ul>
* <p>
* Hooks should return <code>void</code>.
* </p>
*/
JPA_PERFTRACE_SEARCH_FOUND_ID(void.class,
"java.lang.Integer",
"java.lang.Object"
),
/**
* Note that this is a performance tracing hook. Use with caution in production
* systems, since calling it may (or may not) carry a cost.

View File

@ -3141,6 +3141,8 @@ public class SearchBuilder implements ISearchBuilder {
private final SearchRuntimeDetails mySearchRuntimeDetails;
private final RequestDetails myRequest;
private final boolean myHaveRawSqlHooks;
private final boolean myHavePerftraceFoundIdHook;
private boolean myFirst = true;
private IncludesIterator myIncludesIterator;
private Long myNext;
@ -3159,13 +3161,16 @@ public class SearchBuilder implements ISearchBuilder {
if (myParams.getEverythingMode() != null) {
myStillNeedToFetchIncludes = true;
}
myHavePerftraceFoundIdHook =JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_SEARCH_FOUND_ID, myInterceptorBroadcaster, myRequest);
myHaveRawSqlHooks = JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_RAW_SQL, myInterceptorBroadcaster, myRequest);
}
private void fetchNext() {
boolean haveRawSqlHooks = JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_RAW_SQL, myInterceptorBroadcaster, myRequest);
try {
if (haveRawSqlHooks) {
if (myHaveRawSqlHooks) {
CurrentThreadCaptureQueriesListener.startCapturing();
}
@ -3206,6 +3211,13 @@ public class SearchBuilder implements ISearchBuilder {
if (myNext == null) {
while (myResultsIterator.hasNext()) {
Long next = myResultsIterator.next();
if (myHavePerftraceFoundIdHook) {
HookParams params = new HookParams()
.add(Integer.class, System.identityHashCode(this))
.add(Object.class, next);
JpaInterceptorBroadcaster.doCallHooks(myInterceptorBroadcaster, myRequest, Pointcut.JPA_PERFTRACE_SEARCH_FOUND_ID, params);
}
if (next != null) {
if (myPidSet.add(next)) {
myNext = next;
@ -3244,7 +3256,7 @@ public class SearchBuilder implements ISearchBuilder {
mySearchRuntimeDetails.setFoundMatchesCount(myPidSet.size());
} finally {
if (haveRawSqlHooks) {
if (myHaveRawSqlHooks) {
SqlQueryList capturedQueries = CurrentThreadCaptureQueriesListener.getCurrentQueueAndStopCapturing();
HookParams params = new HookParams()
.add(RequestDetails.class, myRequest)

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.entity.ResourceReindexJobEntity;
@ -35,7 +37,6 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -260,7 +261,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
fooSp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE);
mySearchParameterDao.create(fooSp, mySrd);
runInTransaction(()->{
runInTransaction(() -> {
List<ResourceReindexJobEntity> allJobs = myResourceReindexJobDao.findAll();
assertEquals(1, allJobs.size());
assertEquals("Patient", allJobs.get(0).getResourceType());
@ -450,6 +451,17 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
@Test
public void testCustomParameterMatchingManyValues() {
List<String> found = new ArrayList<>();
class Interceptor {
@Hook(Pointcut.JPA_PERFTRACE_SEARCH_FOUND_ID)
public void foundId(Integer theSearchId, Object theId) {
found.add(theSearchId + "/" + theId);
}
}
Interceptor interceptor = new Interceptor();
myInterceptorRegistry.registerInterceptor(interceptor);
try {
myDaoConfig.setAllowContainsSearches(true);
// Add a custom search parameter
@ -526,19 +538,21 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
.execute();
}
List<IBaseResource> resources = BundleUtil.toListOfResources(myFhirCtx, bundle);
resources.forEach(t->actualIds.add(t.getIdElement().getIdPartAsLong()));
resources.forEach(t -> actualIds.add(t.getIdElement().getIdPartAsLong()));
foundCount += resources.size();
} while (bundle.getLink("next") != null);
ourLog.info("Found: {}", found);
runInTransaction(()->{
runInTransaction(() -> {
List<Search> searches = mySearchEntityDao.findAll();
assertEquals(1, searches.size());
Search search = searches.get(0);
String message = "\nWanted: " + ids + "\n" +
"Actual: " + actualIds + "\n" +
"Found : " + found + "\n" +
search.toString();
assertEquals(message, 200, search.getNumFound());
assertEquals(message, 200, search.getTotalCount().intValue());
@ -546,7 +560,9 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
});
assertEquals(200, foundCount);
} finally {
myInterceptorRegistry.unregisterInterceptor(interceptor);
}
}