Search in sources :

Example 1 with MySQLInsertExecutor

use of io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor 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);
}
Also used : Connection(java.sql.Connection) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) TableRecords(io.seata.rm.datasource.sql.struct.TableRecords) Field(java.lang.reflect.Field) MySQLInsertExecutor(io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor) ConnectionContext(io.seata.rm.datasource.ConnectionContext) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MySQLInsertExecutor

use of io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor 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();
}
Also used : MySQLInsertExecutor(io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with MySQLInsertExecutor

use of io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor in project seata by seata.

the class MySQLInsertExecutorTest method init.

@BeforeEach
public void init() throws SQLException {
    ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
    when(connectionProxy.getDbType()).thenReturn(JdbcConstants.MYSQL);
    DataSourceProxy dataSourceProxy = new DataSourceProxy(new MockDataSource());
    when(connectionProxy.getDataSourceProxy()).thenReturn(dataSourceProxy);
    statementProxy = mock(PreparedStatementProxy.class);
    when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
    when(statementProxy.getTargetStatement()).thenReturn(statementProxy);
    MockResultSet resultSet = new MockResultSet(statementProxy);
    resultSet.mockResultSet(Arrays.asList("Variable_name", "Value"), new Object[][] { { "auto_increment_increment", "1" } });
    when(statementProxy.getTargetStatement().executeQuery("SHOW VARIABLES LIKE 'auto_increment_increment'")).thenReturn(resultSet);
    StatementCallback statementCallback = mock(StatementCallback.class);
    sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
    tableMeta = mock(TableMeta.class);
    insertExecutor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
    pkIndexMap = new HashMap<String, Integer>() {

        {
            put(ID_COLUMN, pkIndex);
        }
    };
}
Also used : DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) MySQLInsertExecutor(io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor) MockDataSource(io.seata.rm.datasource.mock.MockDataSource) MockResultSet(io.seata.rm.datasource.mock.MockResultSet) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) Mockito.anyString(org.mockito.Mockito.anyString) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)3 PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)3 MySQLInsertExecutor (io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor)3 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)3 SQLInsertRecognizer (io.seata.sqlparser.SQLInsertRecognizer)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ConnectionContext (io.seata.rm.datasource.ConnectionContext)1 DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)1 MockDataSource (io.seata.rm.datasource.mock.MockDataSource)1 MockResultSet (io.seata.rm.datasource.mock.MockResultSet)1 TableRecords (io.seata.rm.datasource.sql.struct.TableRecords)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 Mockito.anyString (org.mockito.Mockito.anyString)1