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
parent 0926186f60
commit 8a4864e03f
2 changed files with 10 additions and 5 deletions

View File

@@ -21,16 +21,20 @@ import java.text.ParseException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
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 +69,7 @@ public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
@Test
@Override
public void testExecuteSelectWithNativeQueryReturningEntityClass()
throws ParseException {
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
super.testExecuteSelectWithNativeQueryReturningEntityClass();
}

View File

@@ -40,6 +40,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;
@@ -52,6 +53,7 @@ import org.springframework.transaction.annotation.Transactional;
* @since 2.2
*/
@RunWith(SpringRunner.class)
@DirtiesContext
public class JpaExecutorTests {
@Autowired
@@ -61,7 +63,7 @@ public class JpaExecutorTests {
private BeanFactory beanFactory;
/**
* In this test, the {@link JpaExecutor}'s poll method will be called without
* In this test, the {@link JpaExecutor}'s p\oll method will be called without
* specifying a 'query', 'namedQuery' or 'entityClass' property. This should
* result in an {@link IllegalArgumentException}.
*/