Search in sources :

Example 1 with DefaultResourceManager

use of io.seata.rm.DefaultResourceManager in project seata by seata.

the class ConnectionProxyTest method initBeforeEach.

@BeforeEach
public void initBeforeEach() throws Exception {
    branchRollbackFlagField = ConnectionProxy.LockRetryPolicy.class.getDeclaredField("LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT");
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(branchRollbackFlagField, branchRollbackFlagField.getModifiers() & ~Modifier.FINAL);
    branchRollbackFlagField.setAccessible(true);
    boolean branchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
    Assertions.assertTrue(branchRollbackFlag);
    dataSourceProxy = Mockito.mock(DataSourceProxy.class);
    Mockito.when(dataSourceProxy.getResourceId()).thenReturn(TEST_RESOURCE_ID);
    ResourceManager rm = Mockito.mock(ResourceManager.class);
    Mockito.when(rm.branchRegister(BranchType.AT, dataSourceProxy.getResourceId(), null, TEST_XID, null, lockKey)).thenThrow(new TransactionException(TransactionExceptionCode.LockKeyConflict));
    DefaultResourceManager defaultResourceManager = DefaultResourceManager.get();
    Assertions.assertNotNull(defaultResourceManager);
    DefaultResourceManager.mockResourceManager(BranchType.AT, rm);
}
Also used : Field(java.lang.reflect.Field) TransactionException(io.seata.core.exception.TransactionException) DefaultResourceManager(io.seata.rm.DefaultResourceManager) DefaultResourceManager(io.seata.rm.DefaultResourceManager) ResourceManager(io.seata.core.model.ResourceManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TransactionException (io.seata.core.exception.TransactionException)1 ResourceManager (io.seata.core.model.ResourceManager)1 DefaultResourceManager (io.seata.rm.DefaultResourceManager)1 Field (java.lang.reflect.Field)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1