gpt4 book ai didi

java - JdbcSQLException 超过 40 次测试

转载 作者:行者123 更新时间:2023-12-01 18:15:50 26 4
gpt4 key购买 nike

每当我尝试执行包含超过 40 个测试的测试类时,多余的测试都会失败。测试类由43个测试组成。无论我删除哪三个测试,其余的测试都会运行绿色。

使用的框架:

  • 朱尼特
  • Mockmvc
  • h2 数据库

堆栈跟踪:

Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
COMMIT [50000-197]
Error Code: 50000

at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicRollbackTransaction(DatabaseAccessor.java:1750)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.rollbackTransaction(DatasourceAccessor.java:690)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.rollbackTransaction(DatabaseAccessor.java:1732)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicRollbackTransaction(AbstractSession.java:844)
at org.eclipse.persistence.sessions.server.ClientSession.basicRollbackTransaction(ClientSession.java:209)
at org.eclipse.persistence.internal.sessions.AbstractSession.rollbackTransaction(AbstractSession.java:3968)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.rollbackTransaction(UnitOfWorkImpl.java:4776)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.rollbackTransaction(RepeatableWriteUnitOfWork.java:534)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.release(UnitOfWorkImpl.java:4576)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.rollback(EntityTransactionImpl.java:189)
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:559)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:838)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:812)
at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:128)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:216)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:443)
at org.springframework.test.context.junit.jupiter.SpringExtension.afterEach(SpringExtension.java:139)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterEachCallbacks$11(TestMethodTestDescriptor.java:218)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:230)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:228)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterEachCallbacks(TestMethodTestDescriptor.java:217)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:120)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
COMMIT [50000-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:307)
at org.h2.command.Command.executeUpdate(Command.java:274)
at org.h2.jdbc.JdbcConnection.commit(JdbcConnection.java:497)
at org.h2.jdbc.JdbcConnection.setAutoCommit(JdbcConnection.java:457)
at com.zaxxer.hikari.pool.ProxyConnection.setAutoCommit(ProxyConnection.java:388)
at com.zaxxer.hikari.pool.HikariProxyConnection.setAutoCommit(HikariProxyConnection.java)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicRollbackTransaction(DatabaseAccessor.java:1743)
... 52 more
Caused by: java.lang.RuntimeException: Unexpected code path
at org.h2.message.DbException.throwInternalError(DbException.java:254)
at org.h2.message.DbException.throwInternalError(DbException.java:267)
at org.h2.engine.Session.unlockAll(Session.java:985)
at org.h2.engine.Session.endTransaction(Session.java:760)
at org.h2.engine.Session.commit(Session.java:708)
at org.h2.command.dml.TransactionCommand.update(TransactionCommand.java:46)
at org.h2.command.CommandContainer.update(CommandContainer.java:102)
at org.h2.command.Command.executeUpdate(Command.java:261)
... 57 more
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
COMMIT [50000-197]
Error Code: 50000

at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicRollbackTransaction(DatabaseAccessor.java:1750)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.rollbackTransaction(DatasourceAccessor.java:690)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.rollbackTransaction(DatabaseAccessor.java:1732)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicRollbackTransaction(AbstractSession.java:844)
at org.eclipse.persistence.sessions.server.ClientSession.basicRollbackTransaction(ClientSession.java:209)
at org.eclipse.persistence.internal.sessions.AbstractSession.rollbackTransaction(AbstractSession.java:3968)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.rollbackTransaction(UnitOfWorkImpl.java:4776)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.rollbackTransaction(RepeatableWriteUnitOfWork.java:534)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.release(UnitOfWorkImpl.java:4576)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.rollback(EntityTransactionImpl.java:189)
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:559)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:838)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:812)
at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:128)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:216)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:443)
at org.springframework.test.context.junit.jupiter.SpringExtension.afterEach(SpringExtension.java:139)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterEachCallbacks$11(TestMethodTestDescriptor.java:218)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:230)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:228)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterEachCallbacks(TestMethodTestDescriptor.java:217)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:120)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: Unexpected code path"; SQL statement:
COMMIT [50000-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:307)
at org.h2.command.Command.executeUpdate(Command.java:274)
at org.h2.jdbc.JdbcConnection.commit(JdbcConnection.java:497)
at org.h2.jdbc.JdbcConnection.setAutoCommit(JdbcConnection.java:457)
at com.zaxxer.hikari.pool.ProxyConnection.setAutoCommit(ProxyConnection.java:388)
at com.zaxxer.hikari.pool.HikariProxyConnection.setAutoCommit(HikariProxyConnection.java)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicRollbackTransaction(DatabaseAccessor.java:1743)
... 52 more
Caused by: java.lang.RuntimeException: Unexpected code path
at org.h2.message.DbException.throwInternalError(DbException.java:254)
at org.h2.message.DbException.throwInternalError(DbException.java:267)
at org.h2.engine.Session.unlockAll(Session.java:985)
at org.h2.engine.Session.endTransaction(Session.java:760)
at org.h2.engine.Session.commit(Session.java:708)
at org.h2.command.dml.TransactionCommand.update(TransactionCommand.java:46)
at org.h2.command.CommandContainer.update(CommandContainer.java:102)
at org.h2.command.Command.executeUpdate(Command.java:261)
... 57 more

测试类头和示例测试:

@SpringBootTest(classes = [ProductionOrderTestApp::class, JobControllerTestData::class, JPAConfig::class,
JsonPatchHelper::class, JsonMergePatchHttpMessageConverter::class])
@TestPropertySource(locations = ["classpath:application_h2.properties"])
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Transactional
class ProductionOrderControllerIT {

@Autowired
private lateinit var productionOrderController: ProductionOrderController
@Autowired
private lateinit var globalExceptionHandler: GlobalExceptionHandler
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
private lateinit var genericTestRepository: GenericTestRepository
@Autowired
private lateinit var requestMappingHandlerAdapter: RequestMappingHandlerAdapter
@Autowired
private lateinit var productionOrderTestDataCreator: ProductionOrderTestDataCreator
@Autowired
private lateinit var productService: ProductService
@Autowired
private lateinit var mapper: ObjectMapper

private lateinit var mockMvc: MockMvc

private val isoDate = SimpleDateFormat("yyy-MM-dd'T'HH:mm:ssZ").apply {
timeZone = TimeZone.getTimeZone("UTC")
}

@BeforeAll
fun init() {
JsonProviderConfig().config()
mockMvc = MockMvcBuilders
.standaloneSetup(globalExceptionHandler, productionOrderController)
.setCustomArgumentResolvers(PageableHandlerMethodArgumentResolver())
.setMessageConverters(*requestMappingHandlerAdapter.messageConverters.toTypedArray())
.setCustomArgumentResolvers(PageableHandlerMethodArgumentResolver())
.build()
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
}

@AfterAll
fun after() {
Configuration.setDefaults(DefaultsImpl.INSTANCE)
}

// get tests
@Test
fun `should return 20 persisted production orders sorted by name ascending without pagination request parameters`()
: Unit = with(productionOrderTestDataCreator) {
val generatedProductionOrders = generateProductionOrders(25)
val mvcResult = mockMvc.perform(
get("/api/v03/production-orders"))
.andExpect(status().isOk)
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(header().string(X_TOTAL_COUNT, "25"))
.andExpect(header().string(
HttpHeaders.LINK,
"""</api/v03/production-orders?page=1&size=20>; rel="next",</api/v03/production-orders?page=1&size=20>; rel="last",</api/v03/production-orders?page=0&size=20>; rel="first""""))
.andExpect(jsonPath("$.length()").value(20))
.andReturn()

val orders: List<ProductionOrderResource> = mapper.readValue(mvcResult.response.contentAsByteArray,
object : TypeReference<List<ProductionOrderResource>>() {})

assertThat(orders).containsExactlyElementsOf(generatedProductionOrders.sortedBy { it.name }
.subList(0, 20).map { it.toResource() })
}

application_h2.properties:

spring.datasource.url=jdbc:h2:mem:xeticslean;MODE=MSSQLServer;TRACE_LEVEL_SYSTEM_OUT=0;mv_store=false;MVCC=TRUE;LOCK_TIMEOUT=30000
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driverClassName=org.h2.Driver
spring.liquibase.enabled=false
spring.jpa.properties.eclipselink.weaving=true
spring.jpa.properties.eclipselink.logging.level=SEVERE
spring.jpa.properties.eclipselink.ddl-generation=drop-and-create-tables
spring.jpa.properties.eclipselink.jdbc.batch-writing.size=500
spring.jpa.properties.eclipselink.jdbc.batch-writing=jdbc
spring.jpa.properties.eclipselink.cache.shared.default=false
spring.jpa.properties.eclipselink.target-database=org.eclipse.persistence.platform.database.H2Platform
spring.jpa.properties.eclipselink.persistence-context.flush-mode=commit

当使用本地mssql数据库而不是h2数据库时,所有测试都是绿色的。我正在寻找有关如何使其工作的线索,无论使用什么数据库。

最佳答案

H2 1.4.197 是一个旧的且不受支持的版本。

MV_STORE=FALSEMVCC=TRUE 的组合始终只是实验性的,并且存在许多错误。如果您想使用新的存储引擎,请从 URL 中删除这两个设置。如果您想使用旧存储引擎(对于内存数据库来说通常毫无意义,但您可能有一些自己的原因),请使用 MV_STORE=FALSEMVCC=FALSE 在此版本中。

MVCC 设置从那时起被删除,最近版本的 H2 不再有它。新引擎始终使用行级锁,旧引擎 (MV_STORE=FALSE) 始终使用表级锁。

关于java - JdbcSQLException 超过 40 次测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60372057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com