use of io.seata.rm.datasource.undo.SQLUndoLog 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");
}
use of io.seata.rm.datasource.undo.SQLUndoLog in project seata by seata.
the class ConnectionContextProxyTest method testAppendUndoItem.
@Test
public void testAppendUndoItem() {
SQLUndoLog sqlUndoLog = new SQLUndoLog();
connectionContext.appendUndoItem(sqlUndoLog);
SQLUndoLog sqlUndoLog1 = new SQLUndoLog();
connectionContext.appendUndoItem(sqlUndoLog1);
Assertions.assertTrue(connectionContext.hasUndoLog());
Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
Assertions.assertSame(connectionContext.getUndoItems().get(0), sqlUndoLog);
Assertions.assertSame(connectionContext.getUndoItems().get(1), sqlUndoLog1);
}
use of io.seata.rm.datasource.undo.SQLUndoLog in project seata by seata.
the class ConnectionProxyTest method testLockRetryPolicyRollbackOnConflict.
@Test
public void testLockRetryPolicyRollbackOnConflict() throws Exception {
boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
branchRollbackFlagField.set(null, true);
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, null);
connectionProxy.bind(TEST_XID);
connectionProxy.appendUndoLog(new SQLUndoLog());
connectionProxy.appendLockKey(lockKey);
Assertions.assertThrows(LockConflictException.class, connectionProxy::commit);
branchRollbackFlagField.set(null, oldBranchRollbackFlag);
}
use of io.seata.rm.datasource.undo.SQLUndoLog in project seata by seata.
the class BaseTransactionalExecutor method buildUndoItem.
/**
* build a SQLUndoLog
*
* @param beforeImage the before image
* @param afterImage the after image
* @return sql undo log
*/
protected SQLUndoLog buildUndoItem(TableRecords beforeImage, TableRecords afterImage) {
SQLType sqlType = sqlRecognizer.getSQLType();
String tableName = sqlRecognizer.getTableName();
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(sqlType);
sqlUndoLog.setTableName(tableName);
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
return sqlUndoLog;
}
use of io.seata.rm.datasource.undo.SQLUndoLog in project seata by seata.
the class MySQLUndoDeleteExecutorTest method init.
@BeforeAll
public static void init() {
TableMeta tableMeta = Mockito.mock(TableMeta.class);
Mockito.when(tableMeta.getPrimaryKeyOnlyName()).thenReturn(Arrays.asList(new String[] { "id" }));
Mockito.when(tableMeta.getTableName()).thenReturn("table_name");
TableRecords beforeImage = new TableRecords();
beforeImage.setTableName("table_name");
beforeImage.setTableMeta(tableMeta);
List<Row> beforeRows = new ArrayList<>();
Row row0 = new Row();
addField(row0, "id", 1, "12345");
addField(row0, "age", 1, "1");
beforeRows.add(row0);
Row row1 = new Row();
addField(row1, "id", 1, "12346");
addField(row1, "age", 1, "1");
beforeRows.add(row1);
beforeImage.setRows(beforeRows);
TableRecords afterImage = new TableRecords();
afterImage.setTableName("table_name");
afterImage.setTableMeta(tableMeta);
List<Row> afterRows = new ArrayList<>();
Row row2 = new Row();
addField(row2, "id", 1, "12345");
addField(row2, "age", 1, "2");
afterRows.add(row2);
Row row3 = new Row();
addField(row3, "id", 1, "12346");
addField(row3, "age", 1, "2");
afterRows.add(row3);
afterImage.setRows(afterRows);
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(SQLType.UPDATE);
sqlUndoLog.setTableMeta(tableMeta);
sqlUndoLog.setTableName("table_name");
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
executor = new MySQLUndoDeleteExecutor(sqlUndoLog);
}
Aggregations