-
tech stack
@SpringBootTest
@Testcontainers
abstract class AbstractIntegrationTest {
companion object {
@Container
val mysqlContainer = MySQLContainer("mysql:8.0.33")
.withConfigurationOverride("./db/mysql/conf.d")
@JvmStatic
@DynamicPropertySource
fun datasourceConfig(registry: DynamicPropertyRegistry) {
registry.add("spring.datasource.url", mysqlContainer::getJdbcUrl)
registry.add("spring.datasource.username", mysqlContainer::getUsername)
registry.add("spring.datasource.password", mysqlContainer::getPassword)
}
}
}
class BookmarkRepositoryTest(
@Autowired val bookmarkRepository: BookmarkRepository
) : AbstractIntegrationTest() {
@Test
fun `bookmarkRepository_save should return savedBookmark`() {
// given
val sampleBookmark = Bookmark(
user_id = 1,
show_id = 1
)
// when
val savedBookmark = bookmarkRepository.save(sampleBookmark)
// then
assertThat(savedBookmark).isEqualTo(sampleBookmark)
}
// test methods...
}
class ReservationRepositoryTest(
@Autowired val bookmarkRepository: ReservationRepository
) : AbstractIntegrationTest() {
// Test methods...
} OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
BookmarkRepositoryTest > bookmarkRepository_findByIdOrNull should return foundBookmark() FAILED
org.springframework.transaction.CannotCreateTransactionException at BookmarkRepositoryTest.kt:38
Caused by: org.hibernate.exception.JDBCConnectionException at BookmarkRepositoryTest.kt:38
Caused by: java.sql.SQLTransientConnectionException at BookmarkRepositoryTest.kt:38
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:175
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at null:-1
Caused by: java.net.ConnectException at Net.java:-2
BookmarkRepositoryTest > bookmarkRepository_findAll should return list of Bookmarks() FAILED
org.springframework.transaction.CannotCreateTransactionException at BookmarkRepositoryTest.kt:74
Caused by: org.hibernate.exception.JDBCConnectionException at BookmarkRepositoryTest.kt:74
Caused by: java.sql.SQLTransientConnectionException at BookmarkRepositoryTest.kt:74
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:175
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at null:-1
Caused by: java.net.ConnectException at Net.java:-2
BookmarkRepositoryTest > bookmarkRepository_save should return savedBookmark() FAILED
org.springframework.transaction.CannotCreateTransactionException at BookmarkRepositoryTest.kt:24
Caused by: org.hibernate.exception.JDBCConnectionException at BookmarkRepositoryTest.kt:24
Caused by: java.sql.SQLTransientConnectionException at BookmarkRepositoryTest.kt:24
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:175
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at null:-1
Caused by: java.net.ConnectException at Net.java:-2
BookmarkRepositoryTest > bookmarkRepository_deleteById should delete requestedBookmark() FAILED
org.springframework.transaction.CannotCreateTransactionException at BookmarkRepositoryTest.kt:55
Caused by: org.hibernate.exception.JDBCConnectionException at BookmarkRepositoryTest.kt:55
Caused by: java.sql.SQLTransientConnectionException at BookmarkRepositoryTest.kt:55
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:175
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at null:-1
Caused by: java.net.ConnectException at Net.java:-2
I think I failed to managed Container's life cycle I don't understand why All DB connections in a One Class has to be fail, and another class always SUCCESS
I think container has to be running before all |
Beta Was this translation helpful? Give feedback.
Answered by
junha-ahn
Jul 22, 2023
Replies: 1 comment
-
I solved this problem, just do not use Because
How to Avoid THIS
@SpringBootTest
@Testcontainers
abstract class AbstractIntegrationTest {
companion object {
val mysqlContainer = MySQLContainer("mysql:8.0.33")
.withConfigurationOverride("./db/mysql/conf.d")
@JvmStatic
@DynamicPropertySource
fun datasourceConfig(registry: DynamicPropertyRegistry) {
mysqlContainer.start()
registry.add("spring.datasource.url", mysqlContainer::getJdbcUrl)
registry.add("spring.datasource.username", mysqlContainer::getUsername)
registry.add("spring.datasource.password", mysqlContainer::getPassword)
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
junha-ahn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved this problem, just do not use
@testcontainer
anotationBecause
@testcontainer
start container when first method in a ONE Test Class, and stop if the last method finisehdHow to Avoid THIS
@DirtiesContext
every test class