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);
}
Aggregations