TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(this.step); if (taskExecutor == null) { taskExecutor = new SyncTaskExecutor(); partitionHandler.setGridSize(gridSize); partitionHandler.setTaskExecutor(taskExecutor); step.setPartitionHandler(partitionHandler);
@Override protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception { Assert.notNull(step, "A Step must be provided."); final Set<Future<StepExecution>> tasks = new HashSet<>(getGridSize()); final Set<StepExecution> result = new HashSet<>(); for (final StepExecution stepExecution : partitionStepExecutions) { final FutureTask<StepExecution> task = createTask(step, stepExecution); try { taskExecutor.execute(task); tasks.add(task); } catch (TaskRejectedException e) { // couldn't execute one of the tasks ExitStatus exitStatus = ExitStatus.FAILED .addExitDescription("TaskExecutor rejected the task for this step."); /* * Set the status in case the caller is tracking it through the * JobExecution. */ stepExecution.setStatus(BatchStatus.FAILED); stepExecution.setExitStatus(exitStatus); result.add(stepExecution); } } for (Future<StepExecution> task : tasks) { result.add(task.get()); } return result; }
@Before public void setUp() throws Exception { handler.setStep(new StepSupport() { @Override public void execute(StepExecution stepExecution) throws JobInterruptedException { count++; stepExecutions.add(stepExecution.getStepName()); } }); handler.afterPropertiesSet(); }
@Test public void testSetGridSize() throws Exception { handler.setGridSize(2); handler.handle(stepExecutionSplitter, stepExecution); assertEquals(2, count); assertEquals("[foo0, foo1]", stepExecutions.toString()); }
@Test public void testTaskExecutorFailure() throws Exception { handler.setGridSize(2); handler.setTaskExecutor(new TaskExecutor() { @Override public void execute(Runnable task) { if (count > 0) { throw new TaskRejectedException("foo"); } task.run(); } }); Collection<StepExecution> executions = handler.handle(stepExecutionSplitter, stepExecution); new DefaultStepExecutionAggregator().aggregate(stepExecution, executions); assertEquals(1, count); assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode()); }
@Test public void testPartitionStepWithProxyHandler() throws Exception { StepParserStepFactoryBean<Object, Object> fb = new StepParserStepFactoryBean<>(); fb.setBeanName("step1"); fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); fb.setTaskExecutor(new SyncTaskExecutor()); SimplePartitioner partitioner = new SimplePartitioner(); fb.setPartitioner(partitioner); TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(new StepSupport("foo")); ProxyFactory factory = new ProxyFactory(partitionHandler); fb.setPartitionHandler((PartitionHandler) factory.getProxy()); Object step = fb.getObject(); assertTrue(step instanceof PartitionStep); Object handler = ReflectionTestUtils.getField(step, "partitionHandler"); assertTrue(handler instanceof Advised); }
@Test public void testNullStep() throws Exception { handler = new TaskExecutorPartitionHandler(); try { handler.handle(stepExecutionSplitter, stepExecution); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("Step")); } }
@Test public void testConfiguration() throws Exception { handler = new TaskExecutorPartitionHandler(); try { handler.afterPropertiesSet(); fail("Expected IllegalStateException when no step is set"); } catch (IllegalStateException e) { // expected String message = e.getMessage(); assertEquals("Wrong message: " + message, "A Step must be provided.", message); } }
@Test public void testSetTaskExecutor() throws Exception { handler.setTaskExecutor(new SimpleAsyncTaskExecutor()); handler.handle(stepExecutionSplitter, stepExecution); assertEquals(1, count); }
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(getStep()); if (getTaskExecutor() == null) { taskExecutor(new SyncTaskExecutor()); partitionHandler.setGridSize(getGridSize()); partitionHandler.setTaskExecutor(getTaskExecutor()); step.setPartitionHandler(partitionHandler);
@Override protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception { Assert.notNull(step, "A Step must be provided."); final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize()); final Set<StepExecution> result = new HashSet<StepExecution>(); for (final StepExecution stepExecution : partitionStepExecutions) { final FutureTask<StepExecution> task = createTask(step, stepExecution); try { taskExecutor.execute(task); tasks.add(task); } catch (TaskRejectedException e) { // couldn't execute one of the tasks ExitStatus exitStatus = ExitStatus.FAILED .addExitDescription("TaskExecutor rejected the task for this step."); /* * Set the status in case the caller is tracking it through the * JobExecution. */ stepExecution.setStatus(BatchStatus.FAILED); stepExecution.setExitStatus(exitStatus); result.add(stepExecution); } } for (Future<StepExecution> task : tasks) { result.add(task.get()); } return result; }
private void configurePartitionStep(PartitionStep ts) { Assert.state(partitioner != null, "A Partitioner must be provided for a partition step"); Assert.state(step != null, "A Step must be provided for a partition step"); configureAbstractStep(ts); if (partitionHandler != null) { ts.setPartitionHandler(partitionHandler); } else { TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(step); if (taskExecutor == null) { taskExecutor = new SyncTaskExecutor(); } partitionHandler.setGridSize(gridSize); partitionHandler.setTaskExecutor(taskExecutor); ts.setPartitionHandler(partitionHandler); } SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, step, partitioner); ts.setStepExecutionSplitter(splitter); }
@Override protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception { Assert.notNull(step, "A Step must be provided."); final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize()); final Set<StepExecution> result = new HashSet<StepExecution>(); for (final StepExecution stepExecution : partitionStepExecutions) { final FutureTask<StepExecution> task = createTask(step, stepExecution); try { taskExecutor.execute(task); tasks.add(task); } catch (TaskRejectedException e) { // couldn't execute one of the tasks ExitStatus exitStatus = ExitStatus.FAILED .addExitDescription("TaskExecutor rejected the task for this step."); /* * Set the status in case the caller is tracking it through the * JobExecution. */ stepExecution.setStatus(BatchStatus.FAILED); stepExecution.setExitStatus(exitStatus); result.add(stepExecution); } } for (Future<StepExecution> task : tasks) { result.add(task.get()); } return result; }
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(this.step); if (taskExecutor == null) { taskExecutor = new SyncTaskExecutor(); partitionHandler.setGridSize(gridSize); partitionHandler.setTaskExecutor(taskExecutor); step.setPartitionHandler(partitionHandler);
@Override protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception { Assert.notNull(step, "A Step must be provided."); final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize()); final Set<StepExecution> result = new HashSet<StepExecution>(); for (final StepExecution stepExecution : partitionStepExecutions) { final FutureTask<StepExecution> task = createTask(step, stepExecution); try { taskExecutor.execute(task); tasks.add(task); } catch (TaskRejectedException e) { // couldn't execute one of the tasks ExitStatus exitStatus = ExitStatus.FAILED .addExitDescription("TaskExecutor rejected the task for this step."); /* * Set the status in case the caller is tracking it through the * JobExecution. */ stepExecution.setStatus(BatchStatus.FAILED); stepExecution.setExitStatus(exitStatus); result.add(stepExecution); } } for (Future<StepExecution> task : tasks) { result.add(task.get()); } return result; }
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(this.step); if (taskExecutor == null) { taskExecutor = new SyncTaskExecutor(); partitionHandler.setGridSize(gridSize); partitionHandler.setTaskExecutor(taskExecutor); step.setPartitionHandler(partitionHandler);
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(this.step); if (taskExecutor == null) { taskExecutor = new SyncTaskExecutor(); partitionHandler.setGridSize(gridSize); partitionHandler.setTaskExecutor(taskExecutor); step.setPartitionHandler(partitionHandler);
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(getStep()); if (getTaskExecutor() == null) { taskExecutor(new SyncTaskExecutor()); partitionHandler.setGridSize(getGridSize()); partitionHandler.setTaskExecutor(getTaskExecutor()); step.setPartitionHandler(partitionHandler);
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(getStep()); if (getTaskExecutor() == null) { taskExecutor(new SyncTaskExecutor()); partitionHandler.setGridSize(getGridSize()); partitionHandler.setTaskExecutor(getTaskExecutor()); step.setPartitionHandler(partitionHandler);
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(getStep()); if (getTaskExecutor() == null) { taskExecutor(new SyncTaskExecutor()); partitionHandler.setGridSize(getGridSize()); partitionHandler.setTaskExecutor(getTaskExecutor()); step.setPartitionHandler(partitionHandler);