This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new fa2c4037579 Refactor OracleXAConnectionWrapperTest (#33767)
fa2c4037579 is described below
commit fa2c4037579159cbf7839bc2a5d1285fd696cff1
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Nov 22 22:50:14 2024 +0800
Refactor OracleXAConnectionWrapperTest (#33767)
* Refactor OracleXAConnectionWrapperTest
* Refactor OracleXAConnectionWrapperTest
---
.../dialect/OracleXAConnectionWrapperTest.java | 43 ++++++++++------------
.../statement/type/MySQLDALStatementVisitor.java | 8 ++--
2 files changed, 24 insertions(+), 27 deletions(-)
diff --git
a/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
b/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
index b2963ce08f1..66df5b6787c 100644
---
a/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
+++
b/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
@@ -17,50 +17,47 @@
package org.apache.shardingsphere.transaction.xa.jta.connection.dialect;
-import oracle.jdbc.internal.OracleConnection;
-import org.junit.jupiter.api.BeforeEach;
+import com.zaxxer.hikari.HikariDataSource;
+import oracle.jdbc.xa.client.OracleXAConnection;
+import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.transaction.xa.fixture.DataSourceUtils;
+import
org.apache.shardingsphere.transaction.xa.jta.connection.XAConnectionWrapper;
+import
org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XADataSourceDefinition;
+import
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourceSwapper;
import org.junit.jupiter.api.Test;
+import org.postgresql.core.BaseConnection;
+import javax.sql.DataSource;
import javax.sql.XAConnection;
import javax.sql.XADataSource;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class OracleXAConnectionWrapperTest {
- private OracleXAConnectionWrapper xaConnectionWrapper;
-
- @BeforeEach
- void setUp() {
- xaConnectionWrapper = new OracleXAConnectionWrapper();
- xaConnectionWrapper.init(new Properties());
- }
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
@Test
void assertWrap() throws SQLException {
- XADataSource xaDataSource = mock(XADataSource.class);
- Connection connection = mockConnection();
- XAConnection actual = xaConnectionWrapper.wrap(xaDataSource,
connection);
- assertThat(actual, instanceOf(XAConnection.class));
+ XAConnection actual =
DatabaseTypedSPILoader.getService(XAConnectionWrapper.class,
databaseType).wrap(createXADataSource(), mockConnection());
+ assertThat(actual, instanceOf(OracleXAConnection.class));
}
- @Test
- void assertGetDatabaseType() {
- assertThat(xaConnectionWrapper.getDatabaseType(), is("Oracle"));
+ private XADataSource createXADataSource() {
+ DataSource dataSource = DataSourceUtils.build(HikariDataSource.class,
databaseType, "foo_ds");
+ return new
DataSourceSwapper(DatabaseTypedSPILoader.getService(XADataSourceDefinition.class,
databaseType)).swap(dataSource);
}
private Connection mockConnection() throws SQLException {
- Connection mockConnection = mock(Connection.class);
- when(mockConnection.unwrap(OracleConnection.class))
- .thenReturn(mock(OracleConnection.class, RETURNS_DEEP_STUBS));
- return mockConnection;
+ Connection result = mock(Connection.class);
+
when(result.unwrap(BaseConnection.class)).thenReturn(mock(BaseConnection.class));
+ return result;
}
}
diff --git
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
index afd7f05e52d..9a4bbce0533 100644
---
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
+++
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDALStatementVisitor.java
@@ -930,14 +930,14 @@ public final class MySQLDALStatementVisitor extends
MySQLStatementVisitor implem
if (null != ctx.optionValueNoOptionType()) {
return getVariableAssignSegment(ctx.optionValueNoOptionType());
}
- VariableSegment variable = new
VariableSegment(ctx.internalVariableName().start.getStartIndex(),
ctx.internalVariableName().stop.getStopIndex(),
ctx.internalVariableName().getText());
- variable.setScope(ctx.optionType().getText());
+ VariableSegment variable = new VariableSegment(
+ ctx.internalVariableName().start.getStartIndex(),
ctx.internalVariableName().stop.getStopIndex(),
ctx.internalVariableName().getText(), ctx.optionType().getText());
return new VariableAssignSegment(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
}
private VariableAssignSegment getVariableAssignSegment(final
OptionValueListContext ctx) {
- VariableSegment variable = new
VariableSegment(ctx.internalVariableName().start.getStartIndex(),
ctx.internalVariableName().stop.getStopIndex(),
ctx.internalVariableName().getText());
- variable.setScope(ctx.optionType().getText());
+ VariableSegment variable = new VariableSegment(
+ ctx.internalVariableName().start.getStartIndex(),
ctx.internalVariableName().stop.getStopIndex(),
ctx.internalVariableName().getText(), ctx.optionType().getText());
return new VariableAssignSegment(ctx.start.getStartIndex(),
ctx.setExprOrDefault().stop.getStopIndex(), variable,
ctx.setExprOrDefault().getText());
}