Skip to content

Commit

Permalink
GH-3061: Add @DirtiesContext to JPA tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
artembilan authored and garyrussell committed Nov 4, 2019
1 parent 9199deb commit 5c6f65f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Expand Up @@ -21,16 +21,18 @@
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
Expand Down Expand Up @@ -65,8 +67,7 @@ public void testExecuteUpdateWithNativeQuery() {

@Test
@Override
public void testExecuteSelectWithNativeQueryReturningEntityClass()
throws ParseException {
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
super.testExecuteSelectWithNativeQueryReturningEntityClass();
}

Expand Down
Expand Up @@ -42,6 +42,7 @@
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;

Expand All @@ -54,6 +55,7 @@
* @since 2.2
*/
@RunWith(SpringRunner.class)
@DirtiesContext
public class JpaExecutorTests {

@Autowired
Expand Down

0 comments on commit 5c6f65f

Please sign in to comment.