Skip to content

Commit

Permalink
Add a bit more logging for occasional failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jun 1, 2018
1 parent 7f87def commit d52c1ed
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
7 changes: 0 additions & 7 deletions hapi-fhir-jpaserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,6 @@
<artifactId>jaxb-impl</artifactId>
<version>${jaxb_core_version}</version>
</dependency>
<!--
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb_runtime_version}</version>
</dependency>
-->
</dependencies>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -87,6 +87,7 @@ public class SearchBuilder implements ISearchBuilder {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchBuilder.class);
private static Long NO_MORE = -1L;
private static HandlerTypeEnum ourLastHandlerMechanismForUnitTest;
private static SearchParameterMap ourLastHandlerParamsForUnitTest;
private List<Long> myAlsoIncludePids;
private CriteriaBuilder myBuilder;
private BaseHapiFhirDao<?> myCallingDao;
Expand Down Expand Up @@ -1017,6 +1018,8 @@ private Predicate createPredicateNumeric(String theResourceName, String theParam
num = builder.or(lowPred, highPred);
}
break;
case ENDS_BEFORE:
case STARTS_AFTER:
default:
String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, invalidMessageName, thePrefix.getValue(), theParam.getValueAsQueryToken(myContext));
throw new InvalidRequestException(msg);
Expand Down Expand Up @@ -1302,6 +1305,7 @@ public Iterator<Long> createQuery(SearchParameterMap theParams, String theSearch
}

Set<String> uniqueQueryStrings = BaseHapiFhirDao.extractCompositeStringUniquesValueChains(myResourceName, params);
ourLastHandlerParamsForUnitTest = theParams;
ourLastHandlerMechanismForUnitTest = HandlerTypeEnum.UNIQUE_INDEX;
return new UniqueIndexIterator(uniqueQueryStrings);

Expand All @@ -1313,6 +1317,7 @@ public Iterator<Long> createQuery(SearchParameterMap theParams, String theSearch
}
}

ourLastHandlerParamsForUnitTest = theParams;
ourLastHandlerMechanismForUnitTest = HandlerTypeEnum.STANDARD_QUERY;
return new QueryIterator();
}
Expand Down Expand Up @@ -1526,6 +1531,8 @@ private boolean createSort(CriteriaBuilder theBuilder, Root<ResourceTable> theFr
sortAttrName = new String[] {"myValue"};
joinType = JoinEnum.QUANTITY;
break;
case COMPOSITE:
case HAS:
default:
throw new InvalidRequestException("This server does not support _sort specifications of type " + param.getParamType() + " - Can't serve _sort=" + theSort.getParamName());
}
Expand Down Expand Up @@ -1698,7 +1705,6 @@ public HashSet<Long> loadReverseIncludes(IDao theCallingDao, FhirContext theCont
roundCounts++;

HashSet<Long> pidsToInclude = new HashSet<>();
Set<Long> nextRoundOmit = new HashSet<>();

for (Iterator<Include> iter = includes.iterator(); iter.hasNext(); ) {
Include nextInclude = iter.next();
Expand Down Expand Up @@ -1793,8 +1799,6 @@ public HashSet<Long> loadReverseIncludes(IDao theCallingDao, FhirContext theCont
}
}

pidsToInclude.removeAll(nextRoundOmit);

addedSomeThisRound = allAdded.addAll(pidsToInclude);
nextRoundMatches = pidsToInclude;
} while (includes.size() > 0 && nextRoundMatches.size() > 0 && addedSomeThisRound);
Expand Down Expand Up @@ -1970,6 +1974,8 @@ private IQueryParameterType toParameterType(RuntimeSearchParam theParam) {
case REFERENCE:
qp = new ReferenceParam();
break;
case URI:
case HAS:
default:
throw new InternalErrorException("Don't know how to convert param type: " + theParam.getParamType());
}
Expand Down Expand Up @@ -2068,14 +2074,18 @@ private static List<Long> filterResourceIdsByLastUpdated(EntityManager theEntity

@VisibleForTesting
public static HandlerTypeEnum getLastHandlerMechanismForUnitTest() {
ourLog.info("Retrieving last handler mechanism: {}", ourLastHandlerMechanismForUnitTest);
return ourLastHandlerMechanismForUnitTest;
}

@VisibleForTesting
public static SearchParameterMap getLastHandlerParamsForUnitTest() {
return ourLastHandlerParamsForUnitTest;
}

@VisibleForTesting
public static void resetLastHandlerMechanismForUnitTest() {
ourLog.info("Clearing last handler mechanism (was {})", ourLastHandlerMechanismForUnitTest);
ourLastHandlerMechanismForUnitTest = null;
ourLastHandlerParamsForUnitTest = null;
}

static Predicate[] toArray(List<Predicate> thePredicates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public void clearCachedDataForUnitTest() {
mySearchEntity = null;
}

protected List<IBaseResource> doHistoryInTransaction(int theFromIndex, int theToIndex) {
private List<IBaseResource> doHistoryInTransaction(int theFromIndex, int theToIndex) {
List<ResourceHistoryTable> results;

CriteriaBuilder cb = myEntityManager.getCriteriaBuilder();
CriteriaQuery<ResourceHistoryTable> q = cb.createQuery(ResourceHistoryTable.class);
Root<ResourceHistoryTable> from = q.from(ResourceHistoryTable.class);
List<Predicate> predicates = new ArrayList<Predicate>();
List<Predicate> predicates = new ArrayList<>();

if (mySearchEntity.getResourceType() == null) {
// All resource types
Expand Down Expand Up @@ -215,6 +215,7 @@ public List<IBaseResource> doInTransaction(TransactionStatus theStatus) {
}
}

@Override
public String getUuid() {
return myUuid;
}
Expand All @@ -223,7 +224,7 @@ public boolean isCacheHit() {
return myCacheHit;
}

public void setCacheHit(boolean theCacheHit) {
void setCacheHit(boolean theCacheHit) {
myCacheHit = theCacheHit;
}

Expand Down Expand Up @@ -253,7 +254,7 @@ public void setSearchDao(ISearchDao theSearchDao) {
mySearchDao = theSearchDao;
}

protected void setSearchEntity(Search theSearchEntity) {
void setSearchEntity(Search theSearchEntity) {
mySearchEntity = theSearchEntity;
}

Expand All @@ -269,8 +270,8 @@ public Integer size() {
return Math.max(0, size);
}

protected List<IBaseResource> toResourceList(ISearchBuilder sb, List<Long> pidsSubList) {
Set<Long> includedPids = new HashSet<Long>();
List<IBaseResource> toResourceList(ISearchBuilder sb, List<Long> pidsSubList) {
Set<Long> includedPids = new HashSet<>();
if (mySearchEntity.getSearchType() == SearchTypeEnum.SEARCH) {
includedPids.addAll(sb.loadReverseIncludes(myDao, myContext, myEntityManager, pidsSubList, mySearchEntity.toRevIncludesList(), true, mySearchEntity.getLastUpdated()));
includedPids.addAll(sb.loadReverseIncludes(myDao, myContext, myEntityManager, pidsSubList, mySearchEntity.toIncludesList(), false, mySearchEntity.getLastUpdated()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public void testSearchSynchronousUsingUniqueComposite() {
params.add("birthdate", new DateParam("2011-01-01"));
IBundleProvider results = myPatientDao.search(params);
assertThat(toUnqualifiedVersionlessIdValues(results), containsInAnyOrder(id1.getValue()));
assertEquals(SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
}


Expand All @@ -777,7 +777,7 @@ public void testSearchUsingUniqueComposite() {
IBundleProvider results = myPatientDao.search(params);
String searchId = results.getUuid();
assertThat(toUnqualifiedVersionlessIdValues(results), containsInAnyOrder(id1));
assertEquals(SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());

// Other order
SearchBuilder.resetLastHandlerMechanismForUnitTest();
Expand All @@ -796,14 +796,14 @@ public void testSearchUsingUniqueComposite() {
params.add("birthdate", new DateParam("2011-01-03"));
results = myPatientDao.search(params);
assertThat(toUnqualifiedVersionlessIdValues(results), empty());
assertEquals(SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());

SearchBuilder.resetLastHandlerMechanismForUnitTest();
params = new SearchParameterMap();
params.add("birthdate", new DateParam("2011-01-03"));
results = myPatientDao.search(params);
assertThat(toUnqualifiedVersionlessIdValues(results), empty());
assertEquals(SearchBuilder.HandlerTypeEnum.STANDARD_QUERY, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.STANDARD_QUERY, SearchBuilder.getLastHandlerMechanismForUnitTest());

}

Expand Down Expand Up @@ -869,7 +869,7 @@ public void testUniqueValuesAreIndexed_Reference_UsingModifierSyntax() {

SearchBuilder.resetLastHandlerMechanismForUnitTest();
IIdType id1 = myPatientDao.update(pt1, "Patient?name=FAMILY1&organization:Organization=ORG").getId().toUnqualifiedVersionless();
assertEquals(SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
uniques = myResourceIndexedCompositeStringUniqueDao.findAll();
assertEquals(1, uniques.size());
assertEquals("Patient/" + id1.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue());
Expand All @@ -883,7 +883,7 @@ public void testUniqueValuesAreIndexed_Reference_UsingModifierSyntax() {

SearchBuilder.resetLastHandlerMechanismForUnitTest();
id1 = myPatientDao.update(pt1, "Patient?name=FAMILY1&organization:Organization=ORG").getId().toUnqualifiedVersionless();
assertEquals(SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
assertEquals(SearchBuilder.getLastHandlerParamsForUnitTest().toString(), SearchBuilder.HandlerTypeEnum.UNIQUE_INDEX, SearchBuilder.getLastHandlerMechanismForUnitTest());
uniques = myResourceIndexedCompositeStringUniqueDao.findAll();
assertEquals(1, uniques.size());
assertEquals("Patient/" + id1.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue());
Expand Down

0 comments on commit d52c1ed

Please sign in to comment.