Add method StepExecutionDao.countStepExecutions to eliminate for-loop in SimpleJobRepository.getStepExecutionCount
Resolves #3657
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
56fbc270e2
commit
b50c665f04
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2013 the original author or authors.
|
||||
* Copyright 2008-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -75,4 +76,16 @@ public class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
|
||||
.length() < stepExecution.getExitStatus().getExitDescription().length());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testCountStepExecutions() {
|
||||
// Given
|
||||
dao.saveStepExecution(stepExecution);
|
||||
|
||||
// When
|
||||
int result = dao.countStepExecutions(jobInstance, stepExecution.getStepName());
|
||||
|
||||
// Then
|
||||
assertEquals(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -117,4 +117,26 @@ public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
|
||||
assertEquals(BatchStatus.COMPLETED, jobStepExecution.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountStepExecutions() {
|
||||
// Given
|
||||
StepExecutionDao tested = new MapStepExecutionDao();
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 88L, null, null);
|
||||
|
||||
StepExecution firstStepExecution = new StepExecution("Step one", jobExecution);
|
||||
firstStepExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
tested.saveStepExecution(firstStepExecution);
|
||||
|
||||
StepExecution secondStepExecution = new StepExecution("Step two", jobExecution);
|
||||
secondStepExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
tested.saveStepExecution(secondStepExecution);
|
||||
|
||||
// When
|
||||
int result = tested.countStepExecutions(jobInstance, firstStepExecution.getStepName());
|
||||
|
||||
// Then
|
||||
assertEquals(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2018 the original author or authors.
|
||||
* Copyright 2006-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.batch.core.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -56,6 +57,7 @@ import org.springframework.batch.core.step.StepSupport;
|
||||
* @author Lucas Ward
|
||||
* @author Will Schipp
|
||||
* @author Dimitrios Liapis
|
||||
* @author Baris Cubukcuoglu
|
||||
*
|
||||
*/
|
||||
public class SimpleJobRepositoryTests {
|
||||
@@ -272,4 +274,16 @@ public class SimpleJobRepositoryTests {
|
||||
jobRepository.createJobExecution("foo", new JobParameters());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionCount() {
|
||||
// Given
|
||||
int expectedResult = 1;
|
||||
when(stepExecutionDao.countStepExecutions(jobInstance, "stepName")).thenReturn(expectedResult);
|
||||
|
||||
// When
|
||||
int actualResult = jobRepository.getStepExecutionCount(jobInstance, "stepName");
|
||||
|
||||
// Then
|
||||
assertEquals(expectedResult, actualResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user