Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add AT transaction mode tests to support database data types (Oracle) #4411

Merged
merged 102 commits into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
dd38eae
通用分页计算
doubleDimple Jan 3, 2022
1d2bce2
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
7dde6f4
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
6c2d330
redis query globalsession third commit
doubleDimple Jan 10, 2022
9c41301
redis query globalsession third commit
doubleDimple Jan 10, 2022
a772160
redis query globalsession third commit
doubleDimple Jan 10, 2022
806f812
Merge branch 'develop' into develop
doubleDimple Jan 11, 2022
edac1e4
redis query globalsession five commit
doubleDimple Jan 11, 2022
143cf18
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 11, 2022
ff833d1
add test case code
Jan 13, 2022
85b66ec
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
1429677
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
c6970e6
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
75e2b68
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
02fa91b
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
3c2c268
add test case code
doubleDimple Jan 14, 2022
ce9886a
add redis mode query globalLock code submit
doubleDimple Jan 14, 2022
0572e16
add globalSessionService test code
doubleDimple Jan 14, 2022
dbb4376
Merge branch 'seata:develop' into develop
doubleDimple Jan 14, 2022
dcceeff
add author
doubleDimple Jan 14, 2022
19bf5a6
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 14, 2022
db243ec
qery redis globalSession and globalLock optimize
doubleDimple Jan 15, 2022
5c68d2c
add author
doubleDimple Jan 17, 2022
bc04c40
update test case
doubleDimple Jan 17, 2022
2b7edb3
Merge branch 'seata:develop' into develop
doubleDimple Jan 17, 2022
db0326c
code format
doubleDimple Jan 17, 2022
ee798d4
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 22, 2022
348a0a2
update changes.md
doubleDimple Jan 22, 2022
c4993fc
optimize
doubleDimple Jan 22, 2022
4328c07
Merge branch 'develop' into develop
doubleDimple Jan 23, 2022
bf62829
Merge branch 'develop' into develop
funky-eyes Jan 24, 2022
6c87f34
optimize
doubleDimple Jan 25, 2022
1c7b8f7
Merge branch 'seata:develop' into develop
doubleDimple Jan 25, 2022
82580c7
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 26, 2022
e6f8194
global lock 查询增加参数resourceId,pk,tableName
doubleDimple Jan 26, 2022
8e3fa32
Merge branch 'seata:develop' into develop
doubleDimple Jan 26, 2022
f663515
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 7, 2022
4899fa8
optimize
doubleDimple Feb 7, 2022
3d9b17c
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 8, 2022
4baba76
close piplied
doubleDimple Feb 8, 2022
7bba2bb
Merge branch 'develop' into develop
doubleDimple Feb 9, 2022
575c879
add rowLockkey test
doubleDimple Feb 10, 2022
e917094
add rowLockkey test
doubleDimple Feb 10, 2022
ac85f0e
optimize query globalSession condition judge
doubleDimple Feb 13, 2022
d6ee786
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 16, 2022
0dbad8b
Resolve code conflicts
doubleDimple Feb 16, 2022
08a0347
Merge branch 'develop' into develop
doubleDimple Feb 17, 2022
8ecea26
Merge branch 'develop' into develop
doubleDimple Feb 22, 2022
20e9318
optimize error prompt
doubleDimple Feb 22, 2022
770bb77
optimize error prompt
doubleDimple Feb 22, 2022
3811a43
optimize code empty line
doubleDimple Feb 23, 2022
5dd5f4d
Merge branch 'develop' into develop
doubleDimple Feb 23, 2022
bf319cc
Merge branch 'develop' into develop
doubleDimple Feb 24, 2022
5dac2cc
update redis local connection
doubleDimple Feb 24, 2022
4a1b065
first commit AT mode support dataBase dataType for oracle
doubleDimple Feb 27, 2022
f3a6cd1
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Feb 27, 2022
78bb580
update oracle at mode dataBase dataType test
doubleDimple Feb 27, 2022
6a7078a
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Feb 27, 2022
6710606
test get oracleDatasource
doubleDimple Feb 28, 2022
b87ef9a
add @Disable annoation
doubleDimple Feb 28, 2022
93537b5
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Feb 28, 2022
666add2
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Feb 28, 2022
be921ac
update maven dependency
doubleDimple Feb 28, 2022
cec696f
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Feb 28, 2022
ff3177f
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Mar 6, 2022
56daa87
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Mar 6, 2022
833e74f
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Mar 7, 2022
de625da
test at mode oracle test dataType
doubleDimple Mar 13, 2022
cadbb02
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Mar 13, 2022
dc97bf4
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Mar 13, 2022
bb75fbf
test at mode oracle test dataType NUMBER VARCHAR
doubleDimple Mar 13, 2022
b9c1d10
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Mar 13, 2022
5879bb1
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Mar 14, 2022
d4ce0ff
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 1, 2022
dc3552c
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 2, 2022
28f82e8
Merge branch 'develop' of github.com:seata/seata into support_dataTyp…
doubleDimple Apr 8, 2022
f613463
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Apr 8, 2022
0c39c79
test oracle data type
doubleDimple Apr 9, 2022
63b1b7c
remove oracle maven dependency
doubleDimple Apr 9, 2022
4300ada
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 9, 2022
4fd6025
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 9, 2022
069a732
optimize
doubleDimple Apr 10, 2022
5ed3747
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Apr 10, 2022
f8e9eca
optimize
doubleDimple Apr 11, 2022
1f5faa4
optimize
doubleDimple Apr 11, 2022
2ba7280
remove surplus Disabled annotation
doubleDimple Apr 11, 2022
d7a6903
optimize
doubleDimple Apr 11, 2022
9eec500
optimize
doubleDimple Apr 12, 2022
4b7539c
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 18, 2022
1b3f3a9
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 18, 2022
13fd4c9
test postGreSql dataType char support
doubleDimple Apr 19, 2022
57bae27
Merge remote-tracking branch 'origin/support_dataTypeTest_oracle_4364…
doubleDimple Apr 19, 2022
f2635c5
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 23, 2022
f2b3e47
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Apr 30, 2022
06a00b4
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple May 9, 2022
0349bee
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple May 17, 2022
5a994e4
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Jun 1, 2022
dd98b24
Merge branch 'develop' into support_dataTypeTest_oracle_4364
doubleDimple Jun 7, 2022
2154ba6
optimize
doubleDimple Jun 7, 2022
c7132ba
optimize
doubleDimple Jun 7, 2022
7eeff22
optimize
doubleDimple Jun 7, 2022
e641575
Merge branch 'develop' into support_dataTypeTest_oracle_4364
slievrly Nov 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file.
250 changes: 250 additions & 0 deletions test/src/test/java/io/seata/at/ATModeSupportDataBaseDataTypeTest.java
@@ -0,0 +1,250 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.at;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import io.seata.common.exception.NotSupportYetException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
import io.seata.rm.DefaultResourceManager;
import io.seata.rm.datasource.DataCompareUtils;
import io.seata.rm.datasource.DataSourceManager;
import io.seata.rm.datasource.DataSourceProxy;
import io.seata.rm.datasource.sql.struct.TableMeta;
import io.seata.rm.datasource.sql.struct.TableMetaCacheFactory;
import io.seata.rm.datasource.sql.struct.TableRecords;
import static io.seata.at.DruidDataSourceUtils.ORACLE;
import static io.seata.at.DruidDataSourceUtils.POSTGRESQL;
import static io.seata.at.DruidDataSourceUtils.createNewDruidDataSource;
import static io.seata.at.oracle.OracleSqlConstant.BINARY_TABLE_NAME;
import static io.seata.at.oracle.OracleSqlConstant.BINARY_TYPE;
import static io.seata.at.oracle.OracleSqlConstant.DATE_TABLE_NAME;
import static io.seata.at.oracle.OracleSqlConstant.DATE_TYPE;
import static io.seata.at.oracle.OracleSqlConstant.NUMBER_TABLE_NAME;
import static io.seata.at.oracle.OracleSqlConstant.NUMBER_TYPE;
import static io.seata.at.oracle.OracleSqlConstant.STRING_TABLE_NAME;
import static io.seata.at.oracle.OracleSqlConstant.STRING_TYPE;
import static io.seata.at.oracle.OracleSqlConstant.TEST_BINARY_TYPE_INSERT_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_BINARY_TYPE_UPDATE_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_DATE_TYPE_INSERT_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_DATE_TYPE_UPDATE_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_NUMBER_TYPE_INSERT_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_NUMBER_TYPE_UPDATE_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_RECORD_ID;
import static io.seata.at.oracle.OracleSqlConstant.TEST_STRING_TYPE_INSERT_SQL;
import static io.seata.at.oracle.OracleSqlConstant.TEST_STRING_TYPE_UPDATE_SQL;

/**
* add AT transaction mode tests to support database data types (Oracle)
*
* author doubleDimple
*/
@Disabled
public class ATModeSupportDataBaseDataTypeTest {

private static final Logger LOGGER = LoggerFactory.getLogger(ATModeSupportDataBaseDataTypeTest.class);

private static final long TEST_ID = 923123123123123132L;
private static final String MOCK_XID = "127.0.0.1:8091:" + TEST_ID;
private static final long MOCK_BRANCH_ID = TEST_ID + 1;

@Test
public void doSqlTest() throws Throwable {
doHandlerTest(ORACLE);
}

public void doHandlerTest(int sqlType) throws Throwable {
doType(sqlType, NUMBER_TYPE, false);
doType(sqlType, STRING_TYPE, false);
doType(sqlType, DATE_TYPE, false);
doType(sqlType, BINARY_TYPE, false);
}

public void doType(int sqlType, int type, boolean globalCommit) throws Throwable {
final SqlClass sqlClass = dogetType(sqlType, type);
LOGGER.info("current type is:[{}]", type);
testTypeSql(sqlType, globalCommit, sqlClass.getInsertSql(), sqlClass.getTableName(), sqlClass.getUpdateSql());
}

@Test
public void testTypeSql(int sqlType, boolean globalCommit, String insertSql, String tableName, String updateSql)
throws Throwable {
doExecute(sqlType, insertSql);
doTestOracleTypePhase(sqlType, globalCommit, tableName, updateSql);
}

private void doExecute(int sqlType, String prepareSql) throws Throwable {
DruidDataSource oracleDruidDataSource = createNewDruidDataSource(sqlType);
Connection helperConn = oracleDruidDataSource.getConnection();
Statement helperStat = helperConn.createStatement();
helperStat.execute(prepareSql);
helperStat.close();
helperConn.close();
LOGGER.info("insert sql success sql:[{}]", prepareSql);
}

private void doTestOracleTypePhase(int sqlType, boolean globalCommit, String tableName, String updateSql)
throws Throwable {
// init DataSource: helper
DruidDataSource helperDS = createNewDruidDataSource(sqlType);

Connection helperConn = null;
Statement helperStat = null;
ResultSet helperRes = null;

initRM();

DataSourceProxy dataSourceProxy = new DataSourceProxy(createNewDruidDataSource(sqlType));
LOGGER.info("the dataSourceProxy is:[{}]", dataSourceProxy);
RootContext.bind(MOCK_XID);
Connection testConn = dataSourceProxy.getConnection();
LOGGER.info("the testConn is:[{}]", testConn);
Statement testStat = testConn.createStatement();
LOGGER.info("the testStat is:[{}]", testStat);

// get before image
helperConn = helperDS.getConnection();
helperStat = helperConn.createStatement();
helperRes = helperStat.executeQuery("select * from " + tableName + " where id = " + TEST_RECORD_ID);
LOGGER.info("the helperRes is:[{}]", helperRes);
TableMeta tableMeta = TableMetaCacheFactory.getTableMetaCache(io.seata.sqlparser.util.JdbcConstants.ORACLE)
.getTableMeta(dataSourceProxy.getPlainConnection(), tableName, dataSourceProxy.getResourceId());
TableRecords beforeImage = TableRecords.buildRecords(tableMeta, helperRes);

// if not throw exception update record
Assertions.assertDoesNotThrow(() -> testStat.execute(updateSql));

// close
testStat.close();
testConn.close();
RootContext.unbind();

if (globalCommit) {
Assertions
.assertDoesNotThrow(() -> DefaultResourceManager.get().branchCommit(dataSourceProxy.getBranchType(),
MOCK_XID, MOCK_BRANCH_ID, dataSourceProxy.getResourceId(), null));
} else {
DefaultResourceManager.get().branchRollback(dataSourceProxy.getBranchType(), MOCK_XID, MOCK_BRANCH_ID,
dataSourceProxy.getResourceId(), null);
helperConn = helperDS.getConnection();
helperStat = helperConn.createStatement();
helperRes = helperStat.executeQuery("select * from " + tableName + " where id = " + TEST_RECORD_ID);
TableRecords currentImage = TableRecords.buildRecords(tableMeta, helperRes);
LOGGER.info("the currentImage Rows is:[{}]", currentImage.getRows());
Assertions.assertTrue(DataCompareUtils.isRecordsEquals(beforeImage, currentImage).getResult());
helperRes.close();
helperStat.close();
helperConn.close();
}
}

private void initRM() {
// init RM
DefaultResourceManager.get();
// mock the RM of AT
DefaultResourceManager.mockResourceManager(BranchType.AT, new DataSourceManager() {
@Override
public Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid,
String applicationData, String lockKeys) throws TransactionException {
return MOCK_BRANCH_ID;
}

@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status,
String applicationData) throws TransactionException {}
});

}

private static class SqlClass {

private String tableName = "";
private String updateSql = "";
private String insertSql = "";

public SqlClass() {}

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getUpdateSql() {
return updateSql;
}

public void setUpdateSql(String updateSql) {
this.updateSql = updateSql;
}

public String getInsertSql() {
return insertSql;
}

public void setInsertSql(String insertSql) {
this.insertSql = insertSql;
}
}

private SqlClass dogetType(int sqlType, int type) {
SqlClass sqlClass = new SqlClass();
switch (sqlType) {
case ORACLE:
switch (type) {
case 1:
sqlClass.setInsertSql(TEST_NUMBER_TYPE_INSERT_SQL);
sqlClass.setTableName(NUMBER_TABLE_NAME);
sqlClass.setUpdateSql(TEST_NUMBER_TYPE_UPDATE_SQL);
break;
case 2:
sqlClass.setInsertSql(TEST_STRING_TYPE_INSERT_SQL);
sqlClass.setTableName(STRING_TABLE_NAME);
sqlClass.setUpdateSql(TEST_STRING_TYPE_UPDATE_SQL);
break;
case 3:
sqlClass.setInsertSql(TEST_DATE_TYPE_INSERT_SQL);
sqlClass.setTableName(DATE_TABLE_NAME);
sqlClass.setTableName(TEST_DATE_TYPE_UPDATE_SQL);
break;
case 4:
sqlClass.setInsertSql(TEST_BINARY_TYPE_INSERT_SQL);
sqlClass.setTableName(BINARY_TABLE_NAME);
sqlClass.setTableName(TEST_BINARY_TYPE_UPDATE_SQL);
default:
}
break;
case POSTGRESQL:

break;
default:
throw new NotSupportYetException("not support");
}
return sqlClass;
}
}
90 changes: 90 additions & 0 deletions test/src/test/java/io/seata/at/DruidDataSourceUtils.java
@@ -0,0 +1,90 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.at;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.util.JdbcUtils;
import io.seata.common.exception.NotSupportYetException;
import io.seata.sqlparser.util.JdbcConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;

/**
* author doubleDimple
*/
public class DruidDataSourceUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(DruidDataSourceUtils.class);

public static final int ORACLE = 1;
public static final int POSTGRESQL = 2;

/**
* oracle: test1: url:jdbc:oracle:thin:@localhost:49161:xe name:system password:oracle
*
* test2: jdbc:oracle:thin:@localhost:1521:helowin name:system password:helowin
*/
public static final String ORACLE_JDBC_URL = "jdbc:oracle:thin:@localhost:49161:xe";
public static final String ORACLE_USERNAME = "system";
public static final String ORACLE_PASSWORD = "oracle";
public static final String ORACLE_DRIVER_CLASSNAME = JdbcUtils.ORACLE_DRIVER;

/**
* PostgreSQL:
*
*/
public static final String POSTGRESQL_JDBC_URL = "";
public static final String POSTGRESQL_USERNAME = "";
public static final String POSTGRESQL_PASSWORD = "";
public static final String POSTGRESQL_DRIVER_CLASSNAME = JdbcUtils.POSTGRESQL_DRIVER;

public static DruidDataSource createNewDruidDataSource(int type) throws Throwable {
DruidDataSource druidDataSource = new DruidDataSource();
switch (type) {
case ORACLE:
initDruidDataSourceOracle(druidDataSource);
break;
case POSTGRESQL:
initDruidDataSourcePostGreSql(druidDataSource);
break;
default:
throw new NotSupportYetException("unknow datasource");
}
return druidDataSource;
}

private static void initDruidDataSourcePostGreSql(DruidDataSource druidDataSource) throws SQLException {
druidDataSource.setDbType(JdbcConstants.POSTGRESQL);
druidDataSource.setUrl(POSTGRESQL_JDBC_URL);
druidDataSource.setUsername(POSTGRESQL_USERNAME);
druidDataSource.setPassword(POSTGRESQL_PASSWORD);
druidDataSource.setDriverClassName(POSTGRESQL_DRIVER_CLASSNAME);
druidDataSource.init();
LOGGER.info("datasource init success");
}

private static void initDruidDataSourceOracle(DruidDataSource druidDataSource) throws Throwable {
druidDataSource.setDbType(JdbcConstants.ORACLE);
druidDataSource.setUrl(ORACLE_JDBC_URL);
druidDataSource.setUsername(ORACLE_USERNAME);
druidDataSource.setPassword(ORACLE_PASSWORD);
druidDataSource.setDriverClassName(ORACLE_DRIVER_CLASSNAME);
druidDataSource.init();
LOGGER.info("datasource init success");
}

}