Skip to content

Commit 4c92983

Browse files
committed
Initial commit of tests and potential hash fix
1 parent 46cb1bf commit 4c92983

File tree

5 files changed

+1335
-3
lines changed

5 files changed

+1335
-3
lines changed

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,8 @@ public Set<JpaPid> loadIncludes(SearchBuilderLoadIncludesParameters<JpaPid> theP
16111611
for (JpaPid next : pidsToInclude) {
16121612
if (!original.contains(next) && !allAdded.contains(next)) {
16131613
nextRoundMatches.add(next);
1614+
} else {
1615+
ourLog.trace("Skipping include since it has already been seen. [jpaPid={}]", next);
16141616
}
16151617
}
16161618

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/tasks/SearchTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ private void doSearch() {
658658
*/
659659
int syncSize = mySyncSize;
660660
while (resultIterator.hasNext()) {
661-
myUnsyncedPids.add(resultIterator.next());
661+
JpaPid next = resultIterator.next();
662+
myUnsyncedPids.add(next);
662663

663664
boolean shouldSync = myUnsyncedPids.size() >= syncSize;
664665

hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/dao/JpaPid.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public boolean equals(Object theO) {
142142
return false;
143143
}
144144
JpaPid jpaPid = (JpaPid) theO;
145-
return Objects.equals(myId, jpaPid.myId) && Objects.equals(myPartitionIdValue, jpaPid.myPartitionIdValue);
145+
return Objects.equals(myId, jpaPid.myId);
146+
// return Objects.equals(myId, jpaPid.myId) && Objects.equals(myPartitionIdValue, jpaPid.myPartitionIdValue);
146147
}
147148

148149
/**
@@ -151,7 +152,8 @@ public boolean equals(Object theO) {
151152
*/
152153
@Override
153154
public int hashCode() {
154-
return Objects.hash(myId, myPartitionIdValue);
155+
// return Objects.hash(myId, myPartitionIdValue);
156+
return Objects.hash(myId);
155157
}
156158

157159
@Override

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
1313
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
1414
import ca.uhn.fhir.jpa.model.util.JpaConstants;
15+
import ca.uhn.fhir.model.api.Include;
1516
import ca.uhn.fhir.rest.api.Constants;
1617
import ca.uhn.fhir.rest.api.server.RequestDetails;
1718
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
@@ -36,9 +37,12 @@
3637
import org.hl7.fhir.r4.model.CapabilityStatement;
3738
import org.hl7.fhir.r4.model.Condition;
3839
import org.hl7.fhir.r4.model.IdType;
40+
import org.hl7.fhir.r4.model.IntegerType;
3941
import org.hl7.fhir.r4.model.Organization;
42+
import org.hl7.fhir.r4.model.Parameters;
4043
import org.hl7.fhir.r4.model.Patient;
4144
import org.hl7.fhir.r4.model.Resource;
45+
import org.hl7.fhir.r4.model.StringType;
4246
import org.junit.jupiter.api.AfterEach;
4347
import org.junit.jupiter.api.BeforeEach;
4448
import org.junit.jupiter.api.Disabled;
@@ -52,6 +56,7 @@
5256

5357
import java.io.IOException;
5458
import java.nio.charset.StandardCharsets;
59+
import java.util.ArrayList;
5560
import java.util.Arrays;
5661
import java.util.Collection;
5762
import java.util.Date;
@@ -83,6 +88,62 @@ public void after() throws Exception {
8388
assertFalse(myPartitionSettings.isAllowUnqualifiedCrossPartitionReference());
8489
}
8590

91+
@ParameterizedTest
92+
@ValueSource(ints = {1, 50})
93+
public void testPartitioningDoesNotReturnDuplicatesOnDoubleInclude(int theCount) {
94+
myTenantClientInterceptor.setTenantId(TENANT_A);
95+
IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue());
96+
IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code"));
97+
createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString()));
98+
Parameters parameters = new Parameters();
99+
parameters.addParameter().setName("_count").setValue(new IntegerType(theCount));
100+
parameters.addParameter().setName("_format").setValue(new StringType("json"));
101+
Bundle execute = myClient.search().forResource("Patient").include(new Include("*")).revInclude(new Include("*")).count(theCount).returnBundle(Bundle.class).execute();
102+
103+
104+
List<String> foundIds = new ArrayList<>();
105+
foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
106+
//Ensure no duplicates in first page
107+
assertThat(foundIds).doesNotHaveDuplicates();
108+
109+
while (execute.getLink("next") != null) {
110+
execute = myClient.loadPage().next(execute).execute();
111+
foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
112+
}
113+
assertThat(foundIds).doesNotHaveDuplicates();
114+
assertThat(foundIds).hasSize(3);
115+
}
116+
117+
@ParameterizedTest
118+
@ValueSource(ints = {1, 50})
119+
public void testPartitioningDoesNotReturnDuplicatesOnPatientEverything(int theCount) throws IOException {
120+
myTenantClientInterceptor.setTenantId(TENANT_A);
121+
IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue());
122+
IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code"));
123+
createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString()));
124+
125+
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
126+
systemRequestDetails.setTenantId(TENANT_A);
127+
128+
Parameters parameters = new Parameters();
129+
parameters.addParameter().setName("_count").setValue(new IntegerType(theCount));
130+
parameters.addParameter().setName("_format").setValue(new StringType("json"));
131+
132+
Bundle everything = myClient.operation().onInstance(patient.toUnqualifiedVersionless().toString()).named("$everything").withParameters(parameters).returnResourceType(Bundle.class).execute();
133+
134+
List<String> foundIds = new ArrayList<>();
135+
foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
136+
//Ensure no duplicates in first page
137+
assertThat(foundIds).doesNotHaveDuplicates();
138+
139+
while (everything.getLink("next") != null) {
140+
everything = myClient.loadPage().next(everything).execute();
141+
foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
142+
}
143+
assertThat(foundIds).doesNotHaveDuplicates();
144+
assertThat(foundIds).hasSize(3);
145+
}
146+
86147
@Test
87148
public void testFetchCapabilityStatement() {
88149
myTenantClientInterceptor.setTenantId(TENANT_A);

0 commit comments

Comments
 (0)