我有一个测试功能,应该执行以下任务
问题在于,在我的测试中,数据尚未提交到db,就像卡在某个transactional
步骤中一样,在执行第二个查询之前,如何确定提交数据。
这是我测试功能的一部分,@Rollback(false)
仅用于开发阶段。
@Test
@Rollback(false)
....
reportJobManager.saveOutput(savedDef, pipeline, results, null)
reportJobManager.retryRetention(savedDef, listOf(csvDeliverbale))
saveOutput函数。示例代码
@Transactional
fun saveOutput() {
if (deliverable.type.name == "DATA_RETENTION_RESULT") {
finishedPipeline.postProcessors.forEach {
//it(definition, dbDeliverable)
val dbRetention = ReportRetention(
deliverable = dbDeliverable,
definition = definition,
retryCount = 1L
)
val retentionUploadSaved = retentionRepository.save(dbRetention)
if (retentionUploadSaved.id == null) {
throw IllegalStateException("Retention upload was not saved!")
}
}
}
}
retryRetention
功能代码
fun retryRetention(definition: ReportDefinition, listOfDeliverables: List<Deliverable>) {
retentionRepository.findAll().forEach {
if (it.state.name == "NOT_UPLOADED" && it.retryCount!!.toInt() < 5) {
if (it.deliverable?.success == true) {
it.state = RetentionUploadStatus.UPLOADED
println("RetentionUploadStatus->UPLOADED")
} else {
val schemaService = SchemaServiceImpl()
val schemas = schemaService.initializeSchemas(definition, emptyMap())
val parameters = definition.parameterPolicy.policy(schemas.parametersSchema)
val delivery = deliveryPolicyService.policy<Deliverable>(ValidDeliveryPolicy.RETENTION_ONLY, schemas.deliverySchema)
val deliveryFunction = delivery.createDeliveryStep()
deliveryFunction(parameters, listOfDeliverables)
it.retryCount = it.retryCount!!.plus(1L)
}
retentionRepository.save(it)
}
}
}
答案 0 :(得分:1)
如果您有带有saveOutput()
批注的方法@Transactional
,则需要在调用@Transactional
的所有其他方法之上添加saveOutput()
,以使事务实际提交。 / p>