final MessageChannelPartitionHandler partitionHandler = new MessageChannelPartitionHandler(); partitionHandler.setStepName(getStepName()); partitionHandler.setGridSize(getGridSize()); partitionHandler.setMessagingOperations(this.messagingTemplate); partitionHandler.setJobExplorer(this.jobExplorer); partitionHandler.setPollInterval(this.pollInterval); partitionHandler.setTimeout(this.timeout); partitionHandler.setReplyChannel(replies); StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows .from(this.inputChannel) partitionHandler.afterPropertiesSet(); super.partitionHandler(partitionHandler);
@Test public void testNoPartitions() throws Exception { //execute with no default set messageChannelPartitionHandler = new MessageChannelPartitionHandler(); //mock StepExecution masterStepExecution = mock(StepExecution.class); StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class); //execute Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution); //verify assertTrue(executions.isEmpty()); }
@SuppressWarnings("rawtypes") @Test(expected = MessageTimeoutException.class) public void messageReceiveTimeout() throws Exception { //execute with no default set messageChannelPartitionHandler = new MessageChannelPartitionHandler(); //mock StepExecution masterStepExecution = mock(StepExecution.class); StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class); MessagingTemplate operations = mock(MessagingTemplate.class); Message message = mock(Message.class); //when HashSet<StepExecution> stepExecutions = new HashSet<>(); stepExecutions.add(new StepExecution("step1", new JobExecution(5L))); when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions); when(message.getPayload()).thenReturn(Collections.emptyList()); //set messageChannelPartitionHandler.setMessagingOperations(operations); //execute messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution); }
@Test public void testHandleWithJobRepositoryPolling() throws Exception { messageChannelPartitionHandler = new MessageChannelPartitionHandler(); messageChannelPartitionHandler.setMessagingOperations(operations); messageChannelPartitionHandler.setJobExplorer(jobExplorer); messageChannelPartitionHandler.setStepName("step1"); messageChannelPartitionHandler.setPollInterval(500L); messageChannelPartitionHandler.afterPropertiesSet(); Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
@Test(expected = TimeoutException.class) public void testHandleWithJobRepositoryPollingTimeout() throws Exception { messageChannelPartitionHandler = new MessageChannelPartitionHandler(); messageChannelPartitionHandler.setMessagingOperations(operations); messageChannelPartitionHandler.setJobExplorer(jobExplorer); messageChannelPartitionHandler.setStepName("step1"); messageChannelPartitionHandler.setTimeout(1000L); messageChannelPartitionHandler.afterPropertiesSet(); messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
@Bean public PartitionHandler partitionHandler(MessagingTemplate messagingTemplate) throws Exception { MessageChannelPartitionHandler partitionHandler = new MessageChannelPartitionHandler(); partitionHandler.setStepName("slaveStep"); partitionHandler.setGridSize(GRID_SIZE); partitionHandler.setMessagingOperations(messagingTemplate); partitionHandler.setPollInterval(5000l); partitionHandler.setJobExplorer(this.jobExplorer); partitionHandler.afterPropertiesSet(); return partitionHandler; }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testHandleWithReplyChannel() throws Exception { //execute with no default set messageChannelPartitionHandler = new MessageChannelPartitionHandler(); //mock StepExecution masterStepExecution = mock(StepExecution.class); StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class); MessagingTemplate operations = mock(MessagingTemplate.class); Message message = mock(Message.class); PollableChannel replyChannel = mock(PollableChannel.class); //when HashSet<StepExecution> stepExecutions = new HashSet<>(); stepExecutions.add(new StepExecution("step1", new JobExecution(5L))); when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions); when(message.getPayload()).thenReturn(Collections.emptyList()); when(operations.receive(replyChannel)).thenReturn(message); //set messageChannelPartitionHandler.setMessagingOperations(operations); messageChannelPartitionHandler.setReplyChannel(replyChannel); //execute Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution); //verify assertNotNull(executions); assertTrue(executions.isEmpty()); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testHandleNoReply() throws Exception { //execute with no default set messageChannelPartitionHandler = new MessageChannelPartitionHandler(); //mock StepExecution masterStepExecution = mock(StepExecution.class); StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class); MessagingTemplate operations = mock(MessagingTemplate.class); Message message = mock(Message.class); //when HashSet<StepExecution> stepExecutions = new HashSet<>(); stepExecutions.add(new StepExecution("step1", new JobExecution(5L))); when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions); when(message.getPayload()).thenReturn(Collections.emptyList()); when(operations.receive((PollableChannel) any())).thenReturn(message); //set messageChannelPartitionHandler.setMessagingOperations(operations); //execute Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution); //verify assertNotNull(executions); assertTrue(executions.isEmpty()); }