Skip to content

Commit 8a4864e

Browse files
committed
GH-3061: Add @DirtiesContext to JPA tests
Fixes #3061 Without a `@DirtiesContext` we keep not only a ctx in the cache, but also an embedded DB instance, which is shared between contexts. When ctx cache clean up happens, several ctxes would like to destroy their associated embedded DB which, essentially, is the same in-memory instance * The `@DirtiesContext` give us a chance to destroy embedded DB for the particular ctx in isolation
1 parent 0926186 commit 8a4864e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/HibernateJpaOperationsTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323

24+
import org.springframework.test.annotation.DirtiesContext;
2425
import org.springframework.test.context.ContextConfiguration;
2526
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
27+
import org.springframework.test.context.junit4.SpringRunner;
2628

2729
/**
2830
* @author Gunnar Hillert
31+
* @author Artem Bilan
32+
*
2933
* @since 2.2
3034
*
3135
*/
32-
@RunWith(SpringJUnit4ClassRunner.class)
33-
@ContextConfiguration
36+
@RunWith(SpringRunner.class)
37+
@DirtiesContext
3438
public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
3539

3640
@Test
@@ -65,8 +69,7 @@ public void testExecuteUpdateWithNativeQuery() {
6569

6670
@Test
6771
@Override
68-
public void testExecuteSelectWithNativeQueryReturningEntityClass()
69-
throws ParseException {
72+
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
7073
super.testExecuteSelectWithNativeQueryReturningEntityClass();
7174
}
7275

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.springframework.integration.support.MessageBuilder;
4141
import org.springframework.integration.test.util.TestUtils;
4242
import org.springframework.messaging.Message;
43+
import org.springframework.test.annotation.DirtiesContext;
4344
import org.springframework.test.context.junit4.SpringRunner;
4445
import org.springframework.transaction.annotation.Transactional;
4546

@@ -52,6 +53,7 @@
5253
* @since 2.2
5354
*/
5455
@RunWith(SpringRunner.class)
56+
@DirtiesContext
5557
public class JpaExecutorTests {
5658

5759
@Autowired
@@ -61,7 +63,7 @@ public class JpaExecutorTests {
6163
private BeanFactory beanFactory;
6264

6365
/**
64-
* In this test, the {@link JpaExecutor}'s poll method will be called without
66+
* In this test, the {@link JpaExecutor}'s p\oll method will be called without
6567
* specifying a 'query', 'namedQuery' or 'entityClass' property. This should
6668
* result in an {@link IllegalArgumentException}.
6769
*/

0 commit comments

Comments
 (0)