Reindex operation fails when operation is executed on a specific partition (#5311)
* adding initial test. * adding solution * adding changeLog. * satisfying spotless check. * fixing changelog * addressing code review comments. --------- Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
parent
43e45db85a
commit
67e421649b
|
@ -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."
|
|
@ -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<VoidModel> myDataSink;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private ReindexStep myReindexStep;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<HapiTransactionService.ExecutionBuilder> 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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,18 +28,11 @@ import ca.uhn.fhir.jpa.config.HapiJpaConfig;
|
||||||
import ca.uhn.fhir.jpa.config.PackageLoaderConfig;
|
import ca.uhn.fhir.jpa.config.PackageLoaderConfig;
|
||||||
import ca.uhn.fhir.jpa.config.r4.JpaR4Config;
|
import ca.uhn.fhir.jpa.config.r4.JpaR4Config;
|
||||||
import ca.uhn.fhir.jpa.config.util.HapiEntityManagerFactoryUtil;
|
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.dialect.HapiFhirH2Dialect;
|
||||||
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
|
|
||||||
import ca.uhn.fhir.jpa.searchparam.config.NicknameServiceConfig;
|
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.CircularQueueCaptureQueriesListener;
|
||||||
import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener;
|
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.rest.server.interceptor.RequestValidatingInterceptor;
|
||||||
import ca.uhn.fhir.subscription.api.IResourceModifiedMessagePersistenceSvc;
|
|
||||||
import ca.uhn.fhir.system.HapiTestSystemProperties;
|
import ca.uhn.fhir.system.HapiTestSystemProperties;
|
||||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||||
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
|
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class ReindexStep implements IJobStepWorker<ReindexJobParameters, Resourc
|
||||||
myHapiTransactionService
|
myHapiTransactionService
|
||||||
.withRequest(requestDetails)
|
.withRequest(requestDetails)
|
||||||
.withTransactionDetails(transactionDetails)
|
.withTransactionDetails(transactionDetails)
|
||||||
|
.withRequestPartitionId(theJobParameters.getRequestPartitionId())
|
||||||
.execute(reindexJob);
|
.execute(reindexJob);
|
||||||
|
|
||||||
return new RunOutcome(data.size());
|
return new RunOutcome(data.size());
|
||||||
|
|
|
@ -478,6 +478,11 @@ public class HapiTransactionService implements IHapiTransactionService {
|
||||||
|
|
||||||
return doExecute(this, callback);
|
return doExecute(this, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public RequestPartitionId getRequestPartitionIdForTesting() {
|
||||||
|
return myRequestPartitionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue