Search in sources :

Example 1 with MockSavepoint

use of com.alibaba.druid.mock.MockSavepoint in project seata by seata.

the class ConnectionContextProxyTest method testGetAfterSavepoints.

@Test
@SuppressWarnings("unchecked")
public void testGetAfterSavepoints() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Savepoint sp1 = new MockSavepoint();
    Savepoint sp2 = new MockSavepoint();
    Savepoint sp3 = new MockSavepoint();
    connectionContext.appendSavepoint(sp1);
    connectionContext.appendSavepoint(sp2);
    connectionContext.appendSavepoint(sp3);
    Method m = ConnectionContext.class.getDeclaredMethod("getAfterSavepoints", Savepoint.class);
    m.setAccessible(true);
    List<Savepoint> invoke = (List<Savepoint>) m.invoke(connectionContext, new Object[] { null });
    Assertions.assertEquals(invoke.size(), 3);
    invoke = (List<Savepoint>) m.invoke(connectionContext, sp2);
    Assertions.assertEquals(invoke.size(), 2);
}
Also used : MockSavepoint(com.alibaba.druid.mock.MockSavepoint) MockSavepoint(com.alibaba.druid.mock.MockSavepoint) Savepoint(java.sql.Savepoint) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 2 with MockSavepoint

use of com.alibaba.druid.mock.MockSavepoint in project seata by seata.

the class ConnectionContextProxyTest method testRemoveSavepoint.

@Test
public void testRemoveSavepoint() {
    Savepoint sp1 = new MockSavepoint();
    connectionContext.appendSavepoint(sp1);
    connectionContext.appendUndoItem(new SQLUndoLog());
    connectionContext.appendLockKey("sp1-lock-key");
    Savepoint sp2 = new MockSavepoint();
    connectionContext.appendSavepoint(sp2);
    Savepoint sp3 = new MockSavepoint();
    connectionContext.appendSavepoint(sp3);
    connectionContext.appendLockKey("sp3-lock-key");
    connectionContext.appendUndoItem(new SQLUndoLog());
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
    Assertions.assertEquals(connectionContext.buildLockKeys(), "sp3-lock-key;sp1-lock-key");
    connectionContext.removeSavepoint(sp3);
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 1);
    Assertions.assertEquals(connectionContext.buildLockKeys(), "sp1-lock-key");
    connectionContext.removeSavepoint(null);
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 0);
    Assertions.assertNull(connectionContext.buildLockKeys());
}
Also used : MockSavepoint(com.alibaba.druid.mock.MockSavepoint) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) MockSavepoint(com.alibaba.druid.mock.MockSavepoint) Savepoint(java.sql.Savepoint) Test(org.junit.jupiter.api.Test)

Example 3 with MockSavepoint

use of com.alibaba.druid.mock.MockSavepoint in project seata by seata.

the class ConnectionContextProxyTest method testReleaseSavepoint.

@Test
public void testReleaseSavepoint() {
    Savepoint sp1 = new MockSavepoint();
    connectionContext.appendSavepoint(sp1);
    connectionContext.appendUndoItem(new SQLUndoLog());
    connectionContext.appendLockKey("sp1-lock-key");
    Savepoint sp2 = new MockSavepoint();
    connectionContext.appendSavepoint(sp2);
    Savepoint sp3 = new MockSavepoint();
    connectionContext.appendSavepoint(sp3);
    connectionContext.appendLockKey("sp3-lock-key");
    connectionContext.appendUndoItem(new SQLUndoLog());
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
    Assertions.assertEquals(connectionContext.buildLockKeys(), "sp3-lock-key;sp1-lock-key");
    connectionContext.releaseSavepoint(sp3);
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
    Assertions.assertEquals(connectionContext.buildLockKeys(), "sp3-lock-key;sp1-lock-key");
    connectionContext.releaseSavepoint(null);
    Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
    Assertions.assertEquals(connectionContext.buildLockKeys(), "sp3-lock-key;sp1-lock-key");
}
Also used : MockSavepoint(com.alibaba.druid.mock.MockSavepoint) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) MockSavepoint(com.alibaba.druid.mock.MockSavepoint) Savepoint(java.sql.Savepoint) Test(org.junit.jupiter.api.Test)

Aggregations

MockSavepoint (com.alibaba.druid.mock.MockSavepoint)3 Savepoint (java.sql.Savepoint)3 Test (org.junit.jupiter.api.Test)3 SQLUndoLog (io.seata.rm.datasource.undo.SQLUndoLog)2 Method (java.lang.reflect.Method)1 List (java.util.List)1