Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java API测试&x2B;事务回滚_Java_Spring_Spring Boot_Integration Testing_Spring Transactions - Fatal编程技术网

Java API测试&x2B;事务回滚

Java API测试&x2B;事务回滚,java,spring,spring-boot,integration-testing,spring-transactions,Java,Spring,Spring Boot,Integration Testing,Spring Transactions,我有一个这样的测试: @Test @Transactional public void when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered() { //language=JSON String startProductionOrder = "{\n" + " \"productionOrder\"

我有一个这样的测试:

@Test
@Transactional
public void when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered() {
    //language=JSON
    String startProductionOrder = "{\n" +
            "  \"productionOrder\": \"1700281\",\n" +
            "  \"staffCodeSignature\": \"00000425\"\n" +
            "}";

    given()
            .body(startProductionOrder)
            .accept(ContentType.JSON)
            .contentType(ContentType.JSON)
            .when()
            .post(commandPath)
            .then().statusCode(201);


    ProductionOrder po = productionOrderRepo.findOneByCode("1700281");
    assertThat(po.getCode(), is("1700281"));
}
我的意图是使用restasured从头到尾测试restapi。正如您可以想象的那样,从控制器开始的每个命令都带有@Transactional注释。问题是测试不会自动回滚。调试日志显示以下内容(我删除了许多部分,因为它太长,无法发布):


这似乎是一个新的应用程序上下文(并使用了tread)。我怎样才能完成上述任务?这是在每次测试中使用@AfterTransaction并清理我的数据库的唯一方法吗?

@Transactional
仅在同一线程中工作,因此Spring提供的回滚将仅在事务启动的线程上持久化的对象上工作

您的rest-assured测试将执行集成测试,并将在另一个线程上命中您的Spring上下文。因此,尽管您的rest-assured测试能够看到测试设置中持久化的对象,但是Spring永远无法自动清理rest-assured测试中持久化的资源


解决这个问题的唯一方法是自己在测试中删除实体(使用Junit规则,或者清除测试设置中的任何状态)。

我一直在努力解决这个问题,并设法找到了解决方法。这个问题确实是由JUnit测试作为嵌入式servlet容器在不同的线程中运行这一事实引起的。这意味着两个事务和数据库连接被打开,彼此都不知道。修复方法是将JUnit测试中打开的事务传播到servlet容器(使用过滤器):

@Transactional
公共类MyTest{
私有静态最终字符串[]字段_name={“资源”、“同步”、“currentTransactionName”、“currentTransactionReadOnly”、“currentTransactionIsolationLevel”、“actualTransactionActive”};
私有静态最终字段[]字段=新字段[Field_NAMES.length];
私有静态最终对象[]字段值=新对象[字段名称.length];
@以前
public void copyTransactionThreadLocals(){

对于(int i=0;i通过这些集成测试,Spring正在重用其测试上下文,而旧事务可能会由于以前测试的状态而以奇怪的方式出现,并导致测试失败。如果您看到单独运行时通过的测试在一起运行时失败,则使用@DirtiesContext注释测试。这让Spring知道它应该讨论rd测试上下文,而不是重用它。

目前我使用@Sql with ExecutionPhase.AFTER_test_方法在每次测试后截断表。但是如果我尝试并行运行它们,这将不起作用。因此我认为事务回滚仍然有用(而且更快)。您找到解决方案了吗?没有……我想我会在截止日期后重新访问它
DEBUG 14120 --- [           main] tractDirtiesContextTestExecutionListener : Before test method: context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered@ProductionOrderStartLT, testExcep
DEBUG 14120 --- [           main] t.a.AnnotationTransactionAttributeSource : Adding transactional method 'com.demo.logbook.commandValidationLT.ProductionOrderStartLT.when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG 14120 --- [           main] t.c.t.TransactionalTestExecutionListener : Explicit transaction definition [PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''] found for test context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_
DEBUG 14120 --- [           main] t.c.t.TransactionalTestExecutionListener : Retrieved @TransactionConfiguration [null] for test class [com.demo.logbook.commandValidationLT.ProductionOrderStartLT].
DEBUG 14120 --- [           main] t.c.t.TransactionalTestExecutionListener : Using TransactionConfigurationAttributes [TransactionConfigurationAttributes@4a5fab78 transactionManagerName = '', defaultRollback = true] for test class [com.demo.logbook.commandValidationLT.ProductionOrderStartLT].
DEBUG 14120 --- [           main] c.DefaultCacheAwareContextLoaderDelegate : Retrieved ApplicationContext from cache with key [[WebMergedContextConfiguration@31206beb testClass = ProductionOrderStartLT, locations = '{}', classes = '{class com.demo.logbook.ElogbookApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.sp
DEBUG 14120 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@c677d7e size = 1, maxSize = 32, parentContextCount = 0, hitCount = 1, missCount = 1]
DEBUG 14120 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'transactionManager'
DEBUG 14120 --- [           main] t.c.t.TransactionalTestExecutionListener : No method-level @Rollback override: using default rollback [true] for test context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_Prod
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Creating new transaction with name [com.demo.logbook.commandValidationLT.ProductionOrderStartLT.when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@505a8582] for JPA transaction
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@465d1345]
 INFO 14120 --- [           main] o.s.t.c.transaction.TransactionContext   : Began transaction (1) for test context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered@ProductionOrderStartLT
DEBUG 14120 --- [           main] c.DefaultCacheAwareContextLoaderDelegate : Retrieved ApplicationContext from cache with key [[WebMergedContextConfiguration@31206beb testClass = ProductionOrderStartLT, locations = '{}', classes = '{class com.demo.logbook.ElogbookApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.sp
DEBUG 14120 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@c677d7e size = 1, maxSize = 32, parentContextCount = 0, hitCount = 2, missCount = 1]
DEBUG 14120 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.boot.test.mock.mockito.MockitoBeans'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing servlet 'dispatcherServlet'
 INFO 14120 --- [nio-9090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
 INFO 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'multipartResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@63880be9]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@560b484d]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@5c57255c]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'requestMappingHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'viewControllerHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'beanNameHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'resourceHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'defaultServletHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'faviconHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'welcomePageHandlerMapping'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'requestMappingHandlerAdapter'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'httpRequestHandlerAdapter'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'simpleControllerHandlerAdapter'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'errorAttributes'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'handlerExceptionResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@56aa150f]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'beanNameViewResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'mvcViewResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'defaultViewResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'viewResolver'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@2c40b216]
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
 INFO 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 19 ms
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Servlet 'dispatcherServlet' configured successfully
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to thread: org.apache.catalina.connector.RequestFacade@17b5f8f0
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/commands/production/production-orders]
DEBUG 14120 --- [nio-9090-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /commands/production/production-orders
DEBUG 14120 --- [nio-9090-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public void com.demo.logbook.commands.web.controllers.ProductionController.startProductionOrder(com.demo.logbook.commands.commands.productionOrder.StartProductionOrder)]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'productionController'
DEBUG 14120 --- [nio-9090-exec-1] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
DEBUG 14120 --- [nio-9090-exec-1] m.m.a.RequestResponseBodyMethodProcessor : Read [class com.demo.logbook.commands.commands.productionOrder.StartProductionOrder] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@ff21443]
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator'
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'transactionManager'
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@2aa65d86] for JPA transaction
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Creating new transaction with name [com.demo.logbook.commands.web.controllers.ProductionController.startProductionOrder]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '',-java.lang.RuntimeException
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@63fa0a64]
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.c.w.c.ProductionController         : Command received : StartProductionOrder{productionOrder='1700281'} SignedCommand{staffCodeSignature='00000425'}
 INFO 14120 --- [nio-9090-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select eventtype0_.id as id1_17_, eventtype0_.name as name2_17_, eventtype0_.type as type3_17_ from events.event_type eventtype0_ where eventtype0_.name=?
Hibernate: select aggregate0_.aggregate_id as aggregat1_15_, aggregate0_.name as name2_15_ from events.aggregate aggregate0_ where aggregate0_.name=?
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.event_store.services.EventStore    : Flushing event : Event
DEBUG 14120 --- [nio-9090-exec-1] stomAnnotationTransactionAttributeSource : Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'transactionManager'
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@2aa65d86] for JPA transaction
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Participating in existing transaction
Hibernate: select nextval ('hibernate_sequence')
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.event_store.services.EventStore    : Event flushed : Event{event_id=31, correlation_id=e5901e3d-9cbf-4c53-bb8c-1fb1006328f8, data='{"transaction_id":"0c4cb269-32fc-422d-93a8-28d506911861","staffCodeSignature":"00000425","productionOrderCode":"1700281"}', version=1, eventType=com.demo.logbook.event_store.persistance.entities.EventType@34ef5c1b, aggregate=Aggregate{a
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.c.w.c.ProductionController         : Publishing eventData : ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.c.w.c.ProductionController         : Command success : StartProductionOrder{productionOrder='1700281'} SignedCommand{staffCodeSignature='00000425'}
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'adminProjection'
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.a.projection.AdminProjection     : Event received in admin module: ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.a.s.AdminValidationService       : Validating event in admin module: ProductionOrderStarted
Hibernate: select count(production0_.product_order_id) as col_0_0_ from admin.production_order production0_ where production0_.code=?
Hibernate: select count(staff0_.reason_type_id) as col_0_0_ from admin.staff staff0_ where staff0_.code=?
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.a.s.AdminValidationService       : Event validation successful in admin module: ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.a.projection.AdminProjection     : Event processed successfully by admin module: ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'productionProjection'
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.p.ProductionProjection         : Event received in prod module: ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.s.ProductionValidationService  : Validating event in prod module: ProductionOrderStarted
Hibernate: select production0_.transaction_id as transact1_20_, production0_.last_action_timestamp as last_act2_20_, production0_.code as code3_20_, production0_.product_code as product_4_20_, production0_.product_name as product_5_20_, production0_.work_center_code as work_cen6_20_, production0_.work_center_name as work_cen7_20_ from prod.production_order production0_ where production0_.code=?
2017-01-20 13:50:10.399 DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.s.ProductionValidationService  : Event validation successful in prod module: ProductionOrderStarted
Hibernate: select production0_.product_order_id as product_1_5_, production0_.code as code2_5_, production0_.product_id as product_3_5_, production0_.work_center_id as work_cen4_5_ from admin.production_order production0_ where production0_.code=?
Hibernate: select product0_.product_id as product_1_3_0_, product0_.box_size as box_size2_3_0_, product0_.code as code3_3_0_, product0_.container_size as containe4_3_0_, product0_.container_type as containe5_3_0_, product0_.description as descript6_3_0_, product0_.markezini_capacity as markezin7_3_0_, product0_.partena_capacity as partena_8_3_0_, product0_.product_category_id as product_9_3_0_, productca
Hibernate: select workcenter0_.work_center_id as work_cen1_13_0_, workcenter0_.code as code2_13_0_, workcenter0_.is_active as is_activ3_13_0_, workcenter0_.name as name4_13_0_, workcenter0_.wing_id as wing_id5_13_0_, wing1_.wing_id as wing_id1_12_1_, wing1_.name as name2_12_1_ from admin.work_center workcenter0_ left outer join admin.wing wing1_ on workcenter0_.wing_id=wing1_.wing_id where workcenter0_.w
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.s.ProductionEventsService      : Flushing production order: ProductionOrder(super=TransactionalEntity(transaction_id=0c4cb269-32fc-422d-93a8-28d506911861, lastActionTimestamp=2017-01-20T13:50:10.425), code=1700281, workCenterCode=0032, workCenterName=SYFPAC A, productCode=0100100, productName=AMINOPHYLLINE 250MG PPAMP 10ML, reasonCodesList=null, inProcessContro
DEBUG 14120 --- [nio-9090-exec-1] stomAnnotationTransactionAttributeSource : Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'transactionManager'
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@2aa65d86] for JPA transaction
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Participating in existing transaction
Hibernate: select production0_.transaction_id as transact1_20_1_, production0_.last_action_timestamp as last_act2_20_1_, production0_.code as code3_20_1_, production0_.product_code as product_4_20_1_, production0_.product_name as product_5_20_1_, production0_.work_center_code as work_cen6_20_1_, production0_.work_center_name as work_cen7_20_1_, inprocessc1_.production_order_transaction_id as producti5_18
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.s.ProductionEventsService      : Flushed production order: ProductionOrder(super=TransactionalEntity(transaction_id=0c4cb269-32fc-422d-93a8-28d506911861, lastActionTimestamp=2017-01-20T13:50:10.425), code=1700281, workCenterCode=0032, workCenterName=SYFPAC A, productCode=0100100, productName=AMINOPHYLLINE 250MG PPAMP 10ML, reasonCodesList=null, inProcessControl
DEBUG 14120 --- [nio-9090-exec-1] c.d.l.q.p.p.ProductionProjection         : Event processed successfully by prod module: ProductionOrderStarted
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Initiating transaction commit
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@2aa65d86]
Hibernate: insert into events.event (aggregate_id, correlation_id, data, event_type_id, time_created, version, event_id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into prod.production_order (last_action_timestamp, code, product_code, product_name, work_center_code, work_center_name, transaction_id) values (?, ?, ?, ?, ?, ?, ?)
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.JpaTransactionManager        : Not closing pre-bound JPA EntityManager after transaction
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
DEBUG 14120 --- [nio-9090-exec-1] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
DEBUG 14120 --- [nio-9090-exec-1] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
DEBUG 14120 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request
DEBUG 14120 --- [nio-9090-exec-1] o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@17b5f8f0
Hibernate: select production0_.transaction_id as transact1_20_, production0_.last_action_timestamp as last_act2_20_, production0_.code as code3_20_, production0_.product_code as product_4_20_, production0_.product_name as product_5_20_, production0_.work_center_code as work_cen6_20_, production0_.work_center_name as work_cen7_20_ from prod.production_order production0_ where production0_.code=?
DEBUG 14120 --- [           main] c.DefaultCacheAwareContextLoaderDelegate : Retrieved ApplicationContext from cache with key [[WebMergedContextConfiguration@31206beb testClass = ProductionOrderStartLT, locations = '{}', classes = '{class com.demo.logbook.ElogbookApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.sp
DEBUG 14120 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@c677d7e size = 1, maxSize = 32, parentContextCount = 0, hitCount = 3, missCount = 1]
DEBUG 14120 --- [           main] c.DefaultCacheAwareContextLoaderDelegate : Retrieved ApplicationContext from cache with key [[WebMergedContextConfiguration@31206beb testClass = ProductionOrderStartLT, locations = '{}', classes = '{class com.demo.logbook.ElogbookApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.sp
DEBUG 14120 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@c677d7e size = 1, maxSize = 32, parentContextCount = 0, hitCount = 4, missCount = 1]
DEBUG 14120 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.boot.test.mock.mockito.MockitoBeans'
DEBUG 14120 --- [           main] c.DefaultCacheAwareContextLoaderDelegate : Retrieved ApplicationContext from cache with key [[WebMergedContextConfiguration@31206beb testClass = ProductionOrderStartLT, locations = '{}', classes = '{class com.demo.logbook.ElogbookApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.sp
DEBUG 14120 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@c677d7e size = 1, maxSize = 32, parentContextCount = 0, hitCount = 5, missCount = 1]
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Initiating transaction rollback
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Rolling back JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@505a8582]
DEBUG 14120 --- [           main] o.s.orm.jpa.JpaTransactionManager        : Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@505a8582] after transaction
DEBUG 14120 --- [           main] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
 INFO 14120 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered@ProductionOrderStart
DEBUG 14120 --- [           main] tractDirtiesContextTestExecutionListener : After test method: context [DefaultTestContext@1dd02175 testClass = ProductionOrderStartLT, testInstance = com.demo.logbook.commandValidationLT.ProductionOrderStartLT@25359ed8, testMethod = when_EnteredRegisteredProductionOrder_and_RegisteredStaffSignature_then_201_and_ProductionOrderRegistered@ProductionOrderStartLT, testExcept
@Transactional
public class MyTest {
    private static final String[] FIELD_NAMES = {"resources", "synchronizations", "currentTransactionName", "currentTransactionReadOnly", "currentTransactionIsolationLevel", "actualTransactionActive"};
    private static final Field[] FIELDS = new Field[FIELD_NAMES.length];
    private static final Object[] FIELD_VALUES = new Object[FIELD_NAMES.length];

    @Before
    public void copyTransactionThreadLocals() {
        for (int i=0; i<FIELD_NAMES.length; i++) {
            Field field = ReflectionUtils.findField(TransactionSynchronizationManager.class,FIELD_NAMES[i]);
            field.setAccessible(true);
            FIELD_VALUES[i] = ((ThreadLocal)ReflectionUtils.getField(field,null)).get();
            FIELDS[i] = field;
        }
    }

    @Configuration
    static class Config {
        @Bean
        public Filter transactionFilter() {
            return new OncePerRequestFilter() {
                @Override
                protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
                    for (int i=0; i<FIELD_NAMES.length; i++) {
                        ((ThreadLocal)ReflectionUtils.getField(FIELDS[i],null)).set(FIELD_VALUES[i]);
                    }
                    filterChain.doFilter(request,response);
                }
            };
        }
    }
}