public class BatchRequestJobTest {
@Test
public void testDoWork() throws Exception {
ExecutionScheduleManager scheduleManagerMock = createMock(ExecutionScheduleManager.class);
BatchRequestJob batchRequestJob = new BatchRequestJob(scheduleManagerMock, 100L);
String clusterName = "mycluster";
long requestId = 11L;
long executionId = 31L;
long batchId = 1L;
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(BatchRequestJob.BATCH_REQUEST_EXECUTION_ID_KEY, executionId);
properties.put(BatchRequestJob.BATCH_REQUEST_BATCH_ID_KEY, batchId);
properties.put(BatchRequestJob.BATCH_REQUEST_CLUSTER_NAME_KEY, clusterName);
HashMap<String, Integer> taskCounts = new HashMap<String, Integer>()
{{ put(BatchRequestJob.BATCH_REQUEST_FAILED_TASKS_KEY, 0);
put(BatchRequestJob.BATCH_REQUEST_TOTAL_TASKS_KEY, 0); }};
BatchRequestResponse pendingResponse = new BatchRequestResponse();
pendingResponse.setStatus(HostRoleStatus.PENDING.toString());
BatchRequestResponse inProgressResponse = new BatchRequestResponse();
inProgressResponse.setStatus(HostRoleStatus.IN_PROGRESS.toString());
BatchRequestResponse completedResponse = new BatchRequestResponse();
completedResponse.setStatus(HostRoleStatus.COMPLETED.toString());
Capture<Long> executionIdCapture = new Capture<Long>();
Capture<Long> batchIdCapture = new Capture<Long>();
Capture<String> clusterNameCapture = new Capture<String>();
expect(scheduleManagerMock.executeBatchRequest(captureLong(executionIdCapture),
captureLong(batchIdCapture),
capture(clusterNameCapture))).andReturn(requestId);
expect(scheduleManagerMock.getBatchRequestResponse(requestId, clusterName)).
andReturn(pendingResponse).times(2);
expect(scheduleManagerMock.getBatchRequestResponse(requestId, clusterName)).
andReturn(inProgressResponse).times(4);
expect(scheduleManagerMock.getBatchRequestResponse(requestId, clusterName)).
andReturn(completedResponse).once();
expect(scheduleManagerMock.hasToleranceThresholdExceeded(executionId,
clusterName, taskCounts)).andReturn(false);
scheduleManagerMock.updateBatchRequest(eq(executionId), eq(batchId), eq(clusterName),
anyObject(BatchRequestResponse.class), eq(true));
expectLastCall().anyTimes();
replay(scheduleManagerMock);