question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JdbcTaskExecutionDaoTests needs to clear(truncate) tables between each test

See original GitHub issue

On some machines with faster processors this this test fails, because data from a previous run is still present in the datastore used by the test. This is being expressed with the following exception:

15:15:10.265 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test class: context [DefaultTestContext@1ad4e testClass = Jdb
cTaskExecutionDaoTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@2f0c2b93 testClass = JdbcTaskEx
ecutionDaoTests, locations = '{}', classes = '{class org.springframework.cloud.task.configuration.TestConfiguration, class org.springframework.boot.autoconfigure.jdbc.EmbeddedDataS
ourceConfiguration, class org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySo
urceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7f7af971, org.springfram
ework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@65b66b08, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@
0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFact
ory$Customizer@499ef98e], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]], attributes = map['org.springframework.test.cont
ext.support.DependencyInjectionTestExecutionListener.reinjectDependencies' -> true]], class annotated with @DirtiesContext [false] with mode [null].
Tests run: 21, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.909 sec <<< FAILURE!
testFindAllDefaultSort(org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDaoTests)  Time elapsed: 0.019 sec  <<< FAILURE!
java.lang.AssertionError: expected:<3> but was:<4>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:834)
        at org.junit.Assert.assertEquals(Assert.java:645)
        at org.junit.Assert.assertEquals(Assert.java:631)
        at org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDaoTests.getPageIterator(JdbcTaskExecutionDaoTests.java:208)
        at org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDaoTests.testFindAllDefaultSort(JdbcTaskExecutionDaoTests.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
        at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cppwfscommented, Oct 30, 2018

SimpleSingleTaskAutoConfigurationWithDataSourceTests verifies that the Configuration for the singleInstanceTaskListener is working properly. (The singleInstanceTaskListener prevents a task from starting if another task with the same name is running. This is implemented by SI’s LogRegistry. ) I’m curious if a @DirtiesContext would resolve the issue, since it seems like the EmbeddedDataSourceConfiguration is bleeding over.

0reactions
hpoettkercommented, Jul 4, 2021

Is this issue still valid? It seems likely to me that the root cause of this issue is (or was) non-unique names for the embedded databases. The tests import Spring Boot’s EmbeddedDataSourceConfiguration, and with Spring Boot 2.3 they flipped the default for spring.datasource.generate-unique-name from false to true (https://github.com/spring-projects/spring-boot/issues/16747).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to clean database tables after each integration test when ...
Use the class JdbcTestUtils to delete the records from the tables you need to. ... are transactional and roll back at the end...
Read more >
Resetting Database Between Spring Integration Tests
The main issue of trying to reset the database is to find out what tables exist without hardcoding anything. This can be accomplished...
Read more >
The argument against clearing the database between tests
On every project, I had a small piece of test harness code that cleans the database between tests: @before_test def clean_session: for table...
Read more >
TRUNCATE vs DELETE: Clearing Data from a Postgres Table
Speed up tests interacting with Postgres siginficantly by clearing data with DELETE rather than TRUNCATE.
Read more >
TRUNCATE - IBM
Use the TRUNCATE command to remove all rows from a table. This has the same effect as the DELETE command, but is much...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found