Is it impossible to automatically roll back data through Spring-test for unit testing of dubbo services

I now want to test a method in a dubbo service through a unit test, but this method modifies the data in the database every time, and the unit test cannot be repeated.

so I want to use Spring-test for automatic rollback of unit tests. In my Spring+MyBatis+MySQL environment, unit tests can be rolled back successfully.

however, when I changed the method of modifying the database to a dubbo service, the unit test could not automatically roll back the data.

my own thinking goes like this:

  • when the unit test is executed, the unit test obviously takes a long time to start the dubbo service, indicating that each time the unit test is executed, a dubbo service is re-registered with the ZooKeeper.
  • if you want to automatically roll back data through Spring-test, it must still be within the control scope of Spring , while the dubbo service has fallen outside the control scope of Spring , which is equivalent to calling a remote service in the code, and how the remote service modifies the database cannot be rolled back.

if so, is there any other way to unit test the methods in the dubbo service?

with related code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/spring-context.xml" })
@Transactional
public class ApplyFacadeTest extends AbstractTransactionalJUnit4SpringContextTests {

    @Autowired
    private ApplyFacade applyFacade; // dubbo
    
    @Test
    @Rollback(true)
    public void testRevokeApply() {
        RevokeApplyReqDTO reqDTO = new RevokeApplyReqDTO();
        reqDTO.setApplyId(289L);
        reqDTO.setUserId(2059L);
        // dubbo
        System.out.println(applyFacade.revokeApply(reqDTO, context));
        System.out.println();
    }   
}

in the configuration file of spring, I set up a bean:

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="hc_suite_masterDataSource" />
</bean>

because the database uses the configuration of the master-slave library, dataSource configures the master library.

Mar.03,2021
Menu