From f6c49f62c8510fe06a7f7cdb1e5bc4929a76742e Mon Sep 17 00:00:00 2001 From: karen-hedges <133129444+karen-hedges@users.noreply.github.com> Date: Sun, 2 Feb 2025 12:33:29 +0000 Subject: [PATCH] DMP-4646 Implement batching in ArmRpoPolling automated task Started to add batchsize to ArmRpoPolling automated task --- .../config/ArmRpoPollAutomatedTaskConfig.java | 1 + .../impl/ArmRpoPollServiceImplTest.java | 31 +++++++++---------- .../impl/ArmRpoPollAutomatedTaskTest.java | 11 +++++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/darts/task/config/ArmRpoPollAutomatedTaskConfig.java b/src/main/java/uk/gov/hmcts/darts/task/config/ArmRpoPollAutomatedTaskConfig.java index c9369ff399..7d2d885efe 100644 --- a/src/main/java/uk/gov/hmcts/darts/task/config/ArmRpoPollAutomatedTaskConfig.java +++ b/src/main/java/uk/gov/hmcts/darts/task/config/ArmRpoPollAutomatedTaskConfig.java @@ -14,4 +14,5 @@ public class ArmRpoPollAutomatedTaskConfig extends AbstractAutomatedTaskConfig { private Duration pollDuration; + } diff --git a/src/test/java/uk/gov/hmcts/darts/arm/service/impl/ArmRpoPollServiceImplTest.java b/src/test/java/uk/gov/hmcts/darts/arm/service/impl/ArmRpoPollServiceImplTest.java index 7545163587..9ab4d2f754 100644 --- a/src/test/java/uk/gov/hmcts/darts/arm/service/impl/ArmRpoPollServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/darts/arm/service/impl/ArmRpoPollServiceImplTest.java @@ -84,7 +84,6 @@ class ArmRpoPollServiceImplTest { private ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity; private static final ArmRpoHelperMocks ARM_RPO_HELPER_MOCKS = new ArmRpoHelperMocks(); private final Duration pollDuration = Duration.ofHours(4); - private int batchSize = 10; private ArmRpoPollServiceImpl armRpoPollService; @@ -127,7 +126,7 @@ void pollArmRpo_shouldPollSuccessfully_whenSaveBackgroundCompleted() throws IOEx when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -172,7 +171,7 @@ void pollArmRpo_shouldPollSuccessfully_whenSaveBackgroundCompletedForManualRun() when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(true, pollDuration, batchSize); + armRpoPollService.pollArmRpo(true, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -217,7 +216,7 @@ void pollArmRpo_shouldPollSuccessfully_whenGetExtendedSearchesByMatterInProgress when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -262,7 +261,7 @@ void pollArmRpo_shouldPollSuccessfully_whenCreateExportBasedOnSearchResultsTable when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -304,7 +303,7 @@ void pollArmRpo_shouldPollSuccessfully_whenGetExtendedProductionsByMatterInProgr when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedProductionsByMatter(eq("bearerToken"), eq(1), contains(PRODUCTION_NAME), eq(userAccountEntity)); @@ -344,7 +343,7 @@ void pollArmRpo_shouldPollSuccessfully_whenCreateExportBasedOnSearchResultsTable when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(true, pollDuration, batchSize); + armRpoPollService.pollArmRpo(true, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -389,7 +388,7 @@ void pollArmRpo_shouldPollSuccessfully_whenDownloadProductionFailedOnPreviousAtt when(fileOperationService.saveFileToTempWorkspace(any(InputStream.class), anyString(), any(), anyBoolean())).thenReturn(filePath); // when - armRpoPollService.pollArmRpo(true, pollDuration, batchSize); + armRpoPollService.pollArmRpo(true, pollDuration, BATCH_SIZE); // then verify(armRpoApi).getExtendedSearchesByMatter("bearerToken", 1, userAccountEntity); @@ -418,7 +417,7 @@ void pollArmRpo_shouldPollNotFindLatestExecutionDetail_OnStepDownloadProductionF armRpoExecutionDetailEntity.setArmRpoState(ARM_RPO_HELPER_MOCKS.getDownloadProductionRpoState()); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -433,7 +432,7 @@ void pollArmRpo_shouldPollNotFindLatestExecutionDetailForManualRun_OnStepDownloa armRpoExecutionDetailEntity.setArmRpoState(ARM_RPO_HELPER_MOCKS.getDownloadProductionRpoState()); // when - armRpoPollService.pollArmRpo(true, pollDuration, batchSize); + armRpoPollService.pollArmRpo(true, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -447,7 +446,7 @@ void pollArmRpo_shouldHandleNoExecutionDetailEntity() { when(armRpoService.getLatestArmRpoExecutionDetailEntity()).thenReturn(null); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -464,7 +463,7 @@ void pollArmRpo_shouldHandleNoBearerToken() { when(armApiService.getArmBearerToken()).thenReturn(null); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -486,7 +485,7 @@ void pollArmRpo_shouldHandleCreateExportInProgress() { when(armRpoApi.createExportBasedOnSearchResultsTable(anyString(), anyInt(), any(), anyString(), any(), any(UserAccountEntity.class))).thenReturn(false); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -511,7 +510,7 @@ void pollArmRpo_shouldHandleGetExtendedSearchesByMatterGetInProgress() { ArmRpoInProgressException.class); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -537,7 +536,7 @@ void pollArmRpo_shouldHandleNoProductionFiles() { when(armRpoApi.getProductionOutputFiles(anyString(), anyInt(), any(UserAccountEntity.class))).thenReturn(List.of()); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); @@ -569,7 +568,7 @@ void pollArmRpo_shouldHandleExceptionDuringPolling_whenCreateExportBasedOnSearch new ArmRpoException("Test exception")); // when - armRpoPollService.pollArmRpo(false, pollDuration, batchSize); + armRpoPollService.pollArmRpo(false, pollDuration, BATCH_SIZE); // then verify(armRpoService).getLatestArmRpoExecutionDetailEntity(); diff --git a/src/test/java/uk/gov/hmcts/darts/task/runner/impl/ArmRpoPollAutomatedTaskTest.java b/src/test/java/uk/gov/hmcts/darts/task/runner/impl/ArmRpoPollAutomatedTaskTest.java index d76dc112e8..9a3b32d30c 100644 --- a/src/test/java/uk/gov/hmcts/darts/task/runner/impl/ArmRpoPollAutomatedTaskTest.java +++ b/src/test/java/uk/gov/hmcts/darts/task/runner/impl/ArmRpoPollAutomatedTaskTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.darts.arm.service.ArmRpoPollService; import uk.gov.hmcts.darts.common.repository.AutomatedTaskRepository; @@ -13,6 +12,10 @@ import java.time.Duration; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + @ExtendWith(MockitoExtension.class) class ArmRpoPollAutomatedTaskTest { @@ -29,8 +32,10 @@ class ArmRpoPollAutomatedTaskTest { @Test void runTask() { - armRpoPollAutomatedTaskConfig.setPollDuration(Duration.ofSeconds(5)); // given + Duration pollDuration = Duration.ofSeconds(5); + when(armRpoPollAutomatedTaskConfig.getPollDuration()).thenReturn(pollDuration); + ArmRpoPollingAutomatedTask armRpoPollAutomatedTask = new ArmRpoPollingAutomatedTask( automatedTaskRepository, armRpoPollAutomatedTaskConfig, @@ -43,6 +48,6 @@ void runTask() { armRpoPollAutomatedTask.runTask(); // then - Mockito.verify(armRpoPollService, Mockito.times(1)).pollArmRpo(false, Duration.ofSeconds(5), 1); + verify(armRpoPollService, times(1)).pollArmRpo(false, pollDuration, 0); } } \ No newline at end of file