Skip to content

Commit

Permalink
DMP-4646 Implement batching in ArmRpoPolling automated task
Browse files Browse the repository at this point in the history
Started to add batchsize to  ArmRpoPolling automated task
  • Loading branch information
karen-hedges committed Feb 4, 2025
1 parent bb7dc1d commit f6c49f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
public class ArmRpoPollAutomatedTaskConfig extends AbstractAutomatedTaskConfig {

private Duration pollDuration;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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,
Expand All @@ -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);
}
}

0 comments on commit f6c49f6

Please sign in to comment.