use of io.seata.rm.BaseDataSourceResource in project seata by seata.
the class ConnectionProxyXATest method testXABranchRollback.
@Test
public void testXABranchRollback() throws Throwable {
Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.getAutoCommit()).thenReturn(true);
XAResource xaResource = Mockito.mock(XAResource.class);
XAConnection xaConnection = Mockito.mock(XAConnection.class);
Mockito.when(xaConnection.getXAResource()).thenReturn(xaResource);
BaseDataSourceResource<ConnectionProxyXA> baseDataSourceResource = Mockito.mock(BaseDataSourceResource.class);
String xid = "xxx";
ResourceManager resourceManager = Mockito.mock(ResourceManager.class);
Mockito.doNothing().when(resourceManager).registerResource(any(Resource.class));
DefaultResourceManager.get();
DefaultResourceManager.mockResourceManager(BranchType.XA, resourceManager);
ConnectionProxyXA connectionProxyXA = new ConnectionProxyXA(connection, xaConnection, baseDataSourceResource, xid);
connectionProxyXA.init();
connectionProxyXA.setAutoCommit(false);
// Assert setAutoCommit = false was NEVER invoked on the wrapped connection
Mockito.verify(connection, times(0)).setAutoCommit(false);
// Assert XA start was invoked
Mockito.verify(xaResource).start(any(Xid.class), any(Integer.class));
connectionProxyXA.rollback();
Mockito.verify(xaResource).end(any(Xid.class), any(Integer.class));
// Not prepared
Mockito.verify(xaResource, times(0)).prepare(any(Xid.class));
}
use of io.seata.rm.BaseDataSourceResource in project seata by seata.
the class ConnectionProxyXATest method testXABranchCommit.
@Test
public void testXABranchCommit() throws Throwable {
Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.getAutoCommit()).thenReturn(true);
XAResource xaResource = Mockito.mock(XAResource.class);
XAConnection xaConnection = Mockito.mock(XAConnection.class);
Mockito.when(xaConnection.getXAResource()).thenReturn(xaResource);
BaseDataSourceResource<ConnectionProxyXA> baseDataSourceResource = Mockito.mock(BaseDataSourceResource.class);
String xid = "xxx";
ResourceManager resourceManager = Mockito.mock(ResourceManager.class);
Mockito.doNothing().when(resourceManager).registerResource(any(Resource.class));
DefaultResourceManager.get();
DefaultResourceManager.mockResourceManager(BranchType.XA, resourceManager);
ConnectionProxyXA connectionProxyXA = new ConnectionProxyXA(connection, xaConnection, baseDataSourceResource, xid);
connectionProxyXA.init();
connectionProxyXA.setAutoCommit(false);
// Assert setAutoCommit = false was NEVER invoked on the wrapped connection
Mockito.verify(connection, times(0)).setAutoCommit(false);
// Assert XA start was invoked
Mockito.verify(xaResource).start(any(Xid.class), any(Integer.class));
connectionProxyXA.commit();
Mockito.verify(xaResource).end(any(Xid.class), any(Integer.class));
Mockito.verify(xaResource).prepare(any(Xid.class));
}
Aggregations