Skip to content

Commit 5c6f65f

Browse files
artembilangaryrussell
authored andcommitted
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 9199deb commit 5c6f65f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

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

24-
import org.springframework.test.context.ContextConfiguration;
25-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
import org.springframework.test.annotation.DirtiesContext;
25+
import org.springframework.test.context.junit4.SpringRunner;
2626

2727
/**
2828
* @author Gunnar Hillert
29+
* @author Artem Bilan
30+
*
2931
* @since 2.2
3032
*
3133
*/
32-
@RunWith(SpringJUnit4ClassRunner.class)
33-
@ContextConfiguration
34+
@RunWith(SpringRunner.class)
35+
@DirtiesContext
3436
public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
3537

3638
@Test
@@ -65,8 +67,7 @@ public void testExecuteUpdateWithNativeQuery() {
6567

6668
@Test
6769
@Override
68-
public void testExecuteSelectWithNativeQueryReturningEntityClass()
69-
throws ParseException {
70+
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
7071
super.testExecuteSelectWithNativeQueryReturningEntityClass();
7172
}
7273

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.integration.support.MessageBuilder;
4343
import org.springframework.integration.test.util.TestUtils;
4444
import org.springframework.messaging.Message;
45+
import org.springframework.test.annotation.DirtiesContext;
4546
import org.springframework.test.context.junit4.SpringRunner;
4647
import org.springframework.transaction.annotation.Transactional;
4748

@@ -54,6 +55,7 @@
5455
* @since 2.2
5556
*/
5657
@RunWith(SpringRunner.class)
58+
@DirtiesContext
5759
public class JpaExecutorTests {
5860

5961
@Autowired

0 commit comments

Comments
 (0)