diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5312-reindexstep-failing-when-executing-on-partition.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5312-reindexstep-failing-when-executing-on-partition.yaml new file mode 100644 index 00000000000..bd186c81feb --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5312-reindexstep-failing-when-executing-on-partition.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5312 +jira: SMILE-7323 +title: "Previously, issuing a reindex operation for resources on a specific partition would fail. This problem has been fixed." diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/tx/ReindexStepTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/tx/ReindexStepTest.java new file mode 100644 index 00000000000..15cf9ed79e2 --- /dev/null +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/tx/ReindexStepTest.java @@ -0,0 +1,64 @@ +package ca.uhn.fhir.jpa.dao.tx; + +import ca.uhn.fhir.batch2.api.IJobDataSink; +import ca.uhn.fhir.batch2.api.VoidModel; +import ca.uhn.fhir.batch2.jobs.chunk.ResourceIdListWorkChunkJson; +import ca.uhn.fhir.batch2.jobs.reindex.ReindexJobParameters; +import ca.uhn.fhir.batch2.jobs.reindex.ReindexStep; +import ca.uhn.fhir.interceptor.model.RequestPartitionId; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class ReindexStepTest { + + @Mock + private HapiTransactionService myHapiTransactionService; + @Mock + private IJobDataSink myDataSink; + + @InjectMocks + private ReindexStep myReindexStep; + + @Captor + private ArgumentCaptor builderArgumentCaptor; + + @Test + public void testMethodReindex_withRequestPartitionId_willExecuteWithPartitionId(){ + // given + Integer expectedPartitionId = 1; + ResourceIdListWorkChunkJson data = new ResourceIdListWorkChunkJson(); + ReindexJobParameters reindexJobParameters = new ReindexJobParameters(); + reindexJobParameters.setRequestPartitionId(RequestPartitionId.fromPartitionId(expectedPartitionId)); + when(myHapiTransactionService.withRequest(any())).thenCallRealMethod(); + + // when + myReindexStep.doReindex(data, myDataSink, "index-id", "chunk-id", reindexJobParameters); + + // then + assertMethodArgumentRequestPartitionId(expectedPartitionId); + + } + + private void assertMethodArgumentRequestPartitionId(Integer theExpectedPartitionId) { + verify(myHapiTransactionService, times(1)).doExecute(builderArgumentCaptor.capture(), any()); + HapiTransactionService.ExecutionBuilder methodArgumentExceptionBuilder = builderArgumentCaptor.getValue(); + RequestPartitionId methodArgumentRequestPartitionId = methodArgumentExceptionBuilder.getRequestPartitionIdForTesting(); + + assertThat(methodArgumentRequestPartitionId, notNullValue()); + assertThat(methodArgumentRequestPartitionId.getFirstPartitionIdOrNull(), equalTo(theExpectedPartitionId)); + } +} diff --git a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/config/TestR4Config.java b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/config/TestR4Config.java index a95f721fa83..98765d50c18 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/config/TestR4Config.java @@ -28,18 +28,11 @@ import ca.uhn.fhir.jpa.config.HapiJpaConfig; import ca.uhn.fhir.jpa.config.PackageLoaderConfig; import ca.uhn.fhir.jpa.config.r4.JpaR4Config; import ca.uhn.fhir.jpa.config.util.HapiEntityManagerFactoryUtil; -import ca.uhn.fhir.jpa.dao.tx.IHapiTransactionService; import ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect; -import ca.uhn.fhir.jpa.model.entity.StorageSettings; import ca.uhn.fhir.jpa.searchparam.config.NicknameServiceConfig; -import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; -import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedConsumer; -import ca.uhn.fhir.jpa.subscription.submit.svc.ResourceModifiedSubmitterSvc; import ca.uhn.fhir.jpa.util.CircularQueueCaptureQueriesListener; import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener; -import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; -import ca.uhn.fhir.subscription.api.IResourceModifiedMessagePersistenceSvc; import ca.uhn.fhir.system.HapiTestSystemProperties; import ca.uhn.fhir.validation.ResultSeverityEnum; import net.ttddyy.dsproxy.listener.SingleQueryCountHolder; diff --git a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexStep.java b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexStep.java index cbfe007fb37..0b301e55a77 100644 --- a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexStep.java +++ b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexStep.java @@ -103,6 +103,7 @@ public class ReindexStep implements IJobStepWorker