Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix batching of mdm-clear tasks (#3295)
* Fix batching of mdm-clear tasks. * Fix batching of mdm-clear tasks. Co-authored-by: ianmarshall <ian@simpatico.ai>
- Loading branch information
1 parent
55ad98d
commit e6fd5c9
Showing
5 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.../main/resources/ca/uhn/hapi/fhir/changelog/5_7_0/3295-fix-mdm-clear-batch-exceptions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
type: fix | ||
issue: 3295 | ||
title: "When $mdm-clear operation batch was split into multiple threads, ResourceVersionConflictExceptions were being | ||
thrown. This issue has been fixed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/batch/mdm/job/MdmLinkDeleterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ca.uhn.fhir.jpa.batch.mdm.job; | ||
|
||
import ca.uhn.fhir.jpa.api.config.DaoConfig; | ||
import ca.uhn.fhir.jpa.dao.data.IMdmLinkDao; | ||
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 org.springframework.transaction.PlatformTransactionManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.anyList; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class MdmLinkDeleterTest { | ||
@Mock | ||
private DaoConfig myDaoConfig; | ||
@Mock | ||
private PlatformTransactionManager myPlatformTransactionManager; | ||
@Mock | ||
private IMdmLinkDao myMdmLinkDao; | ||
|
||
@Captor | ||
ArgumentCaptor<List<Long>> myPidListCaptor; | ||
|
||
@InjectMocks | ||
private MdmLinkDeleter myMdmLinkDeleter; | ||
|
||
@Test | ||
public void testMdmLinkDeleterSplitsPidList() throws Exception { | ||
int threadCount = 4; | ||
int batchSize = 5; | ||
when(myDaoConfig.getReindexBatchSize()).thenReturn(batchSize); | ||
when(myDaoConfig.getReindexThreadCount()).thenReturn(threadCount); | ||
|
||
List<Long> allPidsList = new ArrayList<>(); | ||
int count = threadCount*batchSize; | ||
for (long i = 0; i < count; ++i) { | ||
allPidsList.add(i); | ||
} | ||
myMdmLinkDeleter.process(allPidsList); | ||
|
||
verify(myMdmLinkDao, times(threadCount)).findAllById(myPidListCaptor.capture()); | ||
verify(myMdmLinkDao, times(threadCount)).deleteAll(anyList()); | ||
verifyNoMoreInteractions(myMdmLinkDao); | ||
List<List<Long>> pidListList = myPidListCaptor.getAllValues(); | ||
assertEquals(threadCount, pidListList.size()); | ||
for (List<Long> pidList : pidListList) { | ||
assertEquals(batchSize, pidList.size()); | ||
} | ||
} | ||
|
||
} |