use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class AbstractDMLBaseExecutorTest method testOnlySupportMysqlWhenUseMultiPk.
@Test
public void testOnlySupportMysqlWhenUseMultiPk() {
Mockito.when(connectionProxy.getContext()).thenReturn(new ConnectionContext());
PreparedStatementProxy statementProxy = Mockito.mock(PreparedStatementProxy.class);
Mockito.when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = Mockito.mock(StatementCallback.class);
SQLInsertRecognizer sqlInsertRecognizer = Mockito.mock(SQLInsertRecognizer.class);
TableMeta tableMeta = Mockito.mock(TableMeta.class);
executor = Mockito.spy(new OracleInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
Mockito.when(executor.getDbType()).thenReturn(JdbcConstants.ORACLE);
Mockito.doReturn(tableMeta).when(executor).getTableMeta();
Mockito.when(tableMeta.getPrimaryKeyOnlyName()).thenReturn(Arrays.asList("id", "userCode"));
Assertions.assertThrows(NotSupportYetException.class, () -> executor.executeAutoCommitFalse(null));
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class AbstractDMLBaseExecutorTest 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);
Connection targetConnection = Mockito.mock(Connection.class);
connectionProxy = Mockito.mock(ConnectionProxy.class);
Mockito.doThrow(new LockConflictException()).when(connectionProxy).commit();
Mockito.when(connectionProxy.getAutoCommit()).thenReturn(Boolean.TRUE);
Mockito.when(connectionProxy.getTargetConnection()).thenReturn(targetConnection);
Mockito.when(connectionProxy.getContext()).thenReturn(new ConnectionContext());
PreparedStatementProxy statementProxy = Mockito.mock(PreparedStatementProxy.class);
Mockito.when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = Mockito.mock(StatementCallback.class);
SQLInsertRecognizer sqlInsertRecognizer = Mockito.mock(SQLInsertRecognizer.class);
TableMeta tableMeta = Mockito.mock(TableMeta.class);
executor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
Mockito.doReturn(tableMeta).when(executor).getTableMeta();
TableRecords tableRecords = new TableRecords();
Mockito.doReturn(tableRecords).when(executor).beforeImage();
Mockito.doReturn(tableRecords).when(executor).afterImage(tableRecords);
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class BatchInsertExecutorTest method init.
@BeforeEach
public void init() {
ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.MYSQL);
statementProxy = mock(PreparedStatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = mock(StatementCallback.class);
sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
tableMeta = mock(TableMeta.class);
insertExecutor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
pkIndexMap = new HashMap() {
{
put(ID_COLUMN, pkIndex);
}
};
doReturn(pkIndexMap).when(insertExecutor).getPkIndex();
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class MySQLUndoLogManagerTest method init.
@BeforeEach
public void init() throws SQLException {
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
dataSourceProxy = new DataSourceProxy(dataSource);
connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
undoLogManager = new MySQLUndoLogManager();
tableMeta = new TableMeta();
tableMeta.setTableName("table_plain_executor_test");
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class OracleUndoInsertExecutorTest method upperCase.
public OracleUndoInsertExecutor upperCase() {
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, "1");
addField(row0, "AGE", 1, "1");
beforeRows.add(row0);
Row row1 = new Row();
addField(row1, "ID", 1, "1");
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, "1");
addField(row2, "AGE", 1, "1");
afterRows.add(row2);
Row row3 = new Row();
addField(row3, "ID", 1, "1");
addField(row3, "AGE", 1, "1");
afterRows.add(row3);
afterImage.setRows(afterRows);
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(SQLType.INSERT);
sqlUndoLog.setTableMeta(tableMeta);
sqlUndoLog.setTableName("TABLE_NAME");
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
return new OracleUndoInsertExecutor(sqlUndoLog);
}
Aggregations