From 4d415fa4c0e3a250fcec23a5d8a3cecf7d3c0dc7 Mon Sep 17 00:00:00 2001 From: dsyer Date: Tue, 7 Sep 2010 10:51:17 +0000 Subject: [PATCH] Fix connection pool issue in tests: tracked down to not using @Transactional --- .../batch/core/IgnoredTestSuite.java | 38 +++++++++++++++++++ .../dao/JdbcJobInstanceDaoTests.java | 4 ++ ...NoSuchBatchDomainObjectExceptionTests.java | 9 +++-- ...syncChunkOrientedStepIntegrationTests.java | 17 ++++++++- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/IgnoredTestSuite.java diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/IgnoredTestSuite.java b/spring-batch-core/src/test/java/org/springframework/batch/core/IgnoredTestSuite.java new file mode 100644 index 000000000..b6116a0f9 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/IgnoredTestSuite.java @@ -0,0 +1,38 @@ +/* + * Copyright 2009-2010 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.core; + +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.springframework.batch.core.repository.dao.JdbcJobInstanceDaoTests; +import org.springframework.batch.core.step.tasklet.AsyncChunkOrientedStepIntegrationTests; + +/** + * A test suite that is ignored, but can be resurrected to help debug ordering + * issues in tests. + * + * @author Dave Syer + * + */ +@RunWith(Suite.class) +@SuiteClasses(value = { AsyncChunkOrientedStepIntegrationTests.class, JdbcJobInstanceDaoTests.class }) +@Ignore +public class IgnoredTestSuite { + +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java index bc1748e56..c152bc40c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java @@ -57,6 +57,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { } + @Transactional @Test public void testFindJobInstanceByExecution() { @@ -69,6 +70,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { assertEquals(jobInstance, returnedInstance); } + @Transactional @Test public void testCreateJobKey() { @@ -80,6 +82,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { } + @Transactional @Test public void testCreateJobKeyWithNullParameter() { @@ -94,6 +97,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { } + @Transactional @Test public void testCreateJobKeyOrdering() { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/NoSuchBatchDomainObjectExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/NoSuchBatchDomainObjectExceptionTests.java index f0b353430..f42f63d16 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/NoSuchBatchDomainObjectExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/NoSuchBatchDomainObjectExceptionTests.java @@ -15,16 +15,17 @@ */ package org.springframework.batch.core.repository.dao; -import org.springframework.batch.core.repository.dao.NoSuchObjectException; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; /** * @author Dave Syer - * + * */ -public class NoSuchBatchDomainObjectExceptionTests extends TestCase { +public class NoSuchBatchDomainObjectExceptionTests { + @Test public void testCreateException() throws Exception { NoSuchObjectException e = new NoSuchObjectException("Foo"); assertEquals("Foo", e.getMessage()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java index 125531867..517fb99b4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import org.apache.commons.dbcp.BasicDataSource; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -72,12 +73,26 @@ public class AsyncChunkOrientedStepIntegrationTests { private RepeatTemplate chunkOperations; + private int maxActive; + + private int maxIdle; + private ItemReader getReader(String[] args) { return new ListItemReader(Arrays.asList(args)); } + + @After + public void reset() { + // Reset concurrency settings to something reasonable + dataSource.setMaxActive(maxActive); + dataSource.setMaxIdle(maxIdle); + } @Before - public void onSetUp() throws Exception { + public void init() throws Exception { + + maxActive = dataSource.getMaxActive(); + maxIdle = dataSource.getMaxIdle(); // Force deadlock with batch waiting for DB pool and vice versa dataSource.setMaxActive(1);