GH-3061: Add @DirtiesContext to JPA tests

Fixes https://github.com/spring-projects/spring-integration/issues/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
This commit is contained in:
Artem Bilan
2019-10-01 10:49:17 -04:00
committed by Gary Russell
parent 9199deb742
commit 5c6f65f218
2 changed files with 9 additions and 6 deletions

View File

@@ -21,16 +21,18 @@ import java.text.ParseException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Gunnar Hillert
* @author Artem Bilan
*
* @since 2.2
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@RunWith(SpringRunner.class)
@DirtiesContext
public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
@Test
@@ -65,8 +67,7 @@ public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
@Test
@Override
public void testExecuteSelectWithNativeQueryReturningEntityClass()
throws ParseException {
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
super.testExecuteSelectWithNativeQueryReturningEntityClass();
}

View File

@@ -42,6 +42,7 @@ import org.springframework.integration.jpa.test.entity.StudentDomain;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -54,6 +55,7 @@ import org.springframework.transaction.annotation.Transactional;
* @since 2.2
*/
@RunWith(SpringRunner.class)
@DirtiesContext
public class JpaExecutorTests {
@Autowired