diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java index fc3dd9beb83c5..9c982e585eeca 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java @@ -21,9 +21,11 @@ import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; import org.junit.jupiter.api.Test; import java.util.Collections; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -38,7 +40,7 @@ class EncryptInsertSelectSupportedCheckerTest { @Test void assertIsCheck() { InsertStatementContext sqlStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(sqlStatementContext.getSqlStatement().getInsertSelect().isPresent()).thenReturn(true); + when(sqlStatementContext.getSqlStatement().getInsertSelect()).thenReturn(Optional.of(mock(SubquerySegment.class))); assertTrue(new EncryptInsertSelectSupportedChecker().isCheck(sqlStatementContext)); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java index 6bdb6214a914b..164ce91008ccb 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.encrypt.checker.sql.projection; import org.apache.shardingsphere.encrypt.rule.EncryptRule; +import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; @@ -76,8 +77,13 @@ void assertCheckWhenShorthandExpandContainsSubqueryTable() { @Test void assertCheckWhenCombineStatementContainsEncryptColumn() { + EncryptRule encryptRule = mock(EncryptRule.class, RETURNS_DEEP_STUBS); + when(encryptRule.findQueryEncryptor("foo_tbl", "foo_col_1")).thenReturn(Optional.of(mock(EncryptAlgorithm.class))); + when(encryptRule.findQueryEncryptor("foo_tbl", "foo_col_2")).thenReturn(Optional.of(mock(EncryptAlgorithm.class))); + when(encryptRule.findQueryEncryptor("bar_tbl", "bar_col_1")).thenReturn(Optional.of(mock(EncryptAlgorithm.class))); + when(encryptRule.findQueryEncryptor("bar_tbl", "bar_col_2")).thenReturn(Optional.of(mock(EncryptAlgorithm.class))); SelectStatementContext sqlStatementContext = mockSelectStatementContext(); - assertThrows(UnsupportedSQLOperationException.class, () -> new EncryptSelectProjectionSupportedChecker().check(mock(EncryptRule.class, RETURNS_DEEP_STUBS), null, null, sqlStatementContext)); + assertThrows(UnsupportedSQLOperationException.class, () -> new EncryptSelectProjectionSupportedChecker().check(encryptRule, null, null, sqlStatementContext)); } @Test diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java index 31489bebfc470..6841fe345d636 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java @@ -21,9 +21,11 @@ import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; import org.junit.jupiter.api.Test; import java.util.Collections; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -38,7 +40,7 @@ class EncryptWithClauseSupportedCheckerTest { @Test void assertIsCheck() { SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); - when(sqlStatementContext.getWith().isPresent()).thenReturn(true); + when(sqlStatementContext.getWith()).thenReturn(Optional.of(mock(WithSegment.class))); assertTrue(new EncryptWithClauseSupportedChecker().isCheck(sqlStatementContext)); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptAssignmentTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptAssignmentTokenGeneratorTest.java index cd67d972d2d62..2b4ec45b6f26f 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptAssignmentTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptAssignmentTokenGeneratorTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn; import org.apache.shardingsphere.encrypt.rule.table.EncryptTable; import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext; +import org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; @@ -57,7 +58,7 @@ class EncryptAssignmentTokenGeneratorTest { @BeforeEach void setup() { - tokenGenerator = new EncryptAssignmentTokenGenerator(mockEncryptRule(), null, null); + tokenGenerator = new EncryptAssignmentTokenGenerator(mockEncryptRule(), "testDataBaseName", new H2DatabaseType()); when(tablesContext.getSimpleTables().iterator().next().getTableName().getIdentifier().getValue()).thenReturn("table"); when(assignmentSegment.getColumns().get(0).getIdentifier().getValue()).thenReturn("columns"); when(setAssignmentSegment.getAssignments()).thenReturn(Collections.singleton(assignmentSegment)); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java index 5648193a7d5c0..d94989ff96b09 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java @@ -71,7 +71,7 @@ private EncryptRule mockEncryptRule() { EncryptColumn encryptColumn = mock(EncryptColumn.class, RETURNS_DEEP_STUBS); when(encryptColumn.getAssistedQuery()).thenReturn(Optional.empty()); when(encryptTable1.getEncryptColumn("mobile")).thenReturn(encryptColumn); - when(result.findEncryptTable("t_order").isPresent()).thenReturn(true); + when(result.findEncryptTable("t_order")).thenReturn(Optional.of(mock(EncryptTable.class))); when(result.getEncryptTable("t_order").isEncryptColumn("order_id")).thenReturn(true); return result; } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java index f4b34481b3558..a89ba108ec24d 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java @@ -58,7 +58,6 @@ void assertRetrieveWithColumnOwner() { when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("foo")); ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); - when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment)); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); @@ -81,7 +80,6 @@ void assertRetrieveWithoutColumnOwner() { when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS))); ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS); when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); - when(columnSegment.getOwner()).thenReturn(Optional.empty()); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java index 169ba0f807d39..5986228d8131a 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java @@ -232,7 +232,7 @@ void assertRangeDoShardingByDays() { "SQL Date values do not have a time component."); assertThat(createAlgorithm("yyyy-MM-dd", "2021-06-01", "2021-07-31", "yyyyMMdd", stepAmount, null) - .doSharding(availableTargetNames, shardingValueAsSqlDate).size(), + .doSharding(availableTargetNames, shardingValueAsSqlDate).size(), is(expectSize)); final RangeShardingValue> shardingValueAsString = createShardingValue( DateTimeFormatterFactory.getStandardFormatter().format(lower), @@ -252,8 +252,8 @@ void assertRangeDoShardingByDaysInLocalDate() { } Collection actualAsLocalDate = createAlgorithm("yyyy-MM-dd", "2021-06-01", "2021-07-31", "yyyyMMdd", stepAmount, null) - .doSharding(availableTargetNames, - createShardingValue(LocalDate.of(2021, 6, 15), LocalDate.of(2021, 7, 31))); + .doSharding(availableTargetNames, + createShardingValue(LocalDate.of(2021, 6, 15), LocalDate.of(2021, 7, 31))); assertThat(actualAsLocalDate.size(), is(24)); } @@ -283,7 +283,7 @@ void assertRangeDoShardingByYears() { } Collection actual = createAlgorithm("yyyy", "2000", "2022", "yyyy", 2, "Years") - .doSharding(availableTargetNames, createShardingValue(Year.of(2001), Year.of(2013))); + .doSharding(availableTargetNames, createShardingValue(Year.of(2001), Year.of(2013))); assertThat(actual.size(), is(7)); } @@ -297,8 +297,8 @@ void assertRangeDoShardingByYearsInYearMonth() { } Collection actualAsYearMonth = createAlgorithm("yyyy-MM", "2016-01", "2021-12", "yyyyMM", 2, "Years") - .doSharding(availableTargetNames, - createShardingValue(YearMonth.of(2016, 1), YearMonth.of(2020, 1))); + .doSharding(availableTargetNames, + createShardingValue(YearMonth.of(2016, 1), YearMonth.of(2020, 1))); assertThat(actualAsYearMonth.size(), is(3)); } @@ -329,7 +329,7 @@ private IntervalShardingAlgorithm createAlgorithm(final String datetimePattern, new Property("sharding-suffix-pattern", shardingSuffixPattern), new Property("datetime-interval-amount", Integer.toString(datetimeIntervalAmount))); if (null != datetimeIntervalUnit) { - props.put("datetime-interval-unit", datetimeIntervalUnit); + props.setProperty("datetime-interval-unit", datetimeIntervalUnit); } return (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java index 8668eaf5fd45b..d52128a9354fa 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java @@ -62,7 +62,9 @@ class ShardingDALResultMergerTest { @Test void assertMergeForShowDatabasesStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mockSQLStatementContext(new MySQLShowDatabasesStatement()); + SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS)); + when(sqlStatementContext.getSqlStatement()).thenReturn(new MySQLShowDatabasesStatement()); + when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType); assertThat(resultMerger.merge(queryResults, sqlStatementContext, mock(), mock()), instanceOf(LocalDataMergedResult.class)); } diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java index 5927e4a7e914b..3ce430c6546e1 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java @@ -20,7 +20,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -39,6 +38,7 @@ import org.mockito.quality.Strictness; import java.util.Collections; +import java.util.Optional; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; @@ -81,7 +81,7 @@ void setUp() { @Test void assertInsertStatementContext() { InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty()); when(statementContext.getInsertSelectContext()).thenReturn(null); QueryContext queryContext = mock(QueryContext.class, RETURNS_DEEP_STUBS); when(queryContext.getSqlStatementContext()).thenReturn(statementContext); @@ -95,7 +95,7 @@ void assertInsertStatementContext() { @Test void assertNotInsertStatementContext() { SelectStatementContext statementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty()); QueryContext queryContext = mock(QueryContext.class, RETURNS_DEEP_STUBS); when(queryContext.getSqlStatementContext()).thenReturn(statementContext); when(queryContext.getSql()).thenReturn("SELECT * FROM tbl WHERE id = ?"); diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java index 0bbb9ced5fcff..c657f36cdd461 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java @@ -20,7 +20,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.hint.HintValueContext; @@ -41,6 +40,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Map; +import java.util.Optional; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -113,7 +113,7 @@ void assertRewriteWithStandardParameterBuilderWhenNeedAggregateRewrite() { @Test void assertRewriteWithGroupedParameterBuilderForBroadcast() { InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.of("testDataBaseName")); when(statementContext.getInsertSelectContext()).thenReturn(null); when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1))); when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList()); @@ -135,7 +135,7 @@ void assertRewriteWithGroupedParameterBuilderForBroadcast() { @Test void assertRewriteWithGroupedParameterBuilderForRouteWithSameDataNode() { InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty()); when(statementContext.getInsertSelectContext()).thenReturn(null); when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1))); when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList()); @@ -159,7 +159,7 @@ void assertRewriteWithGroupedParameterBuilderForRouteWithSameDataNode() { @Test void assertRewriteWithGroupedParameterBuilderForRouteWithEmptyDataNode() { InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty()); when(statementContext.getInsertSelectContext()).thenReturn(null); when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1))); when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList()); @@ -182,7 +182,7 @@ void assertRewriteWithGroupedParameterBuilderForRouteWithEmptyDataNode() { @Test void assertRewriteWithGroupedParameterBuilderForRouteWithNotSameDataNode() { InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false); + when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty()); when(statementContext.getInsertSelectContext()).thenReturn(null); when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1))); when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList()); diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/keygen/GeneratedKeyInsertValueParameterRewriterTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/keygen/GeneratedKeyInsertValueParameterRewriterTest.java index afbd9e8eb7e1c..a18b5b2d1d2fa 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/keygen/GeneratedKeyInsertValueParameterRewriterTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/keygen/GeneratedKeyInsertValueParameterRewriterTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.rewrite.parameter.rewriter.keygen; +import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder; @@ -30,6 +31,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; @@ -55,12 +57,12 @@ void assertIsNeedRewrite() { assertFalse(paramRewriter.isNeedRewrite(selectStatementContext)); InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); assertFalse(paramRewriter.isNeedRewrite(insertStatementContext)); - when(insertStatementContext.getGeneratedKeyContext().isPresent()).thenReturn(Boolean.TRUE); + when(insertStatementContext.getGeneratedKeyContext()).thenReturn(Optional.of(mock(GeneratedKeyContext.class))); assertFalse(paramRewriter.isNeedRewrite(insertStatementContext)); when(insertStatementContext.getGeneratedKeyContext().get().isGenerated()).thenReturn(Boolean.TRUE); - when(insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues().isEmpty()).thenReturn(Boolean.TRUE); + when(insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues()).thenReturn(Collections.emptyList()); assertFalse(paramRewriter.isNeedRewrite(insertStatementContext)); - when(insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues().isEmpty()).thenReturn(Boolean.FALSE); + when(insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues()).thenReturn(Collections.singletonList(mock())); assertTrue(paramRewriter.isNeedRewrite(insertStatementContext)); } @@ -84,7 +86,7 @@ void assertRewriteWithGeneratedKeys() { private ParameterBuilder getParameterBuilder() { StandardParameterBuilder standardParamBuilder = mock(StandardParameterBuilder.class); - Map> addedIndexAndParams = new HashMap<>(); + Map> addedIndexAndParams = new HashMap<>(1); when(standardParamBuilder.getAddedIndexAndParameters()).thenReturn(addedIndexAndParams); doAnswer((Answer) invocation -> { int index = invocation.getArgument(0); @@ -98,7 +100,7 @@ private ParameterBuilder getParameterBuilder() { private InsertStatementContext getInsertStatementContext() { InsertStatementContext result = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(result.getGeneratedKeyContext().isPresent()).thenReturn(true); + when(result.getGeneratedKeyContext()).thenReturn(Optional.of(mock(GeneratedKeyContext.class))); when(result.getGeneratedKeyContext().get().getColumnName()).thenReturn("testColumnName"); when(result.getGeneratedKeyContext().get().getGeneratedValues()).thenReturn(Collections.singleton(TEST_GENERATED_VALUE)); when(result.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList("testGroupedParameter"))); diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/builder/DefaultTokenGeneratorBuilderTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/builder/DefaultTokenGeneratorBuilderTest.java index 4b6e10f558a24..df76a9a4e5b53 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/builder/DefaultTokenGeneratorBuilderTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/builder/DefaultTokenGeneratorBuilderTest.java @@ -27,6 +27,7 @@ import java.util.Collection; import java.util.Iterator; +import java.util.Optional; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -47,7 +48,7 @@ void assertGetSQLTokenGeneratorsWithShowTableStatus() { @Test void assertGetSQLTokenGeneratorsWithSelect() { SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); - when(sqlStatementContext.getTablesContext().getDatabaseName().isPresent()).thenReturn(true); + when(sqlStatementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.of("DatabaseName")); assertGetSQLTokenGenerators(sqlStatementContext); } @@ -55,7 +56,7 @@ void assertGetSQLTokenGeneratorsWithSelect() { void assertGetSQLTokenGeneratorsWithShowColumns() { ShowColumnsStatementContext sqlStatementContext = mock(ShowColumnsStatementContext.class, RETURNS_DEEP_STUBS); when(sqlStatementContext.getRemoveSegments().isEmpty()).thenReturn(false); - when(sqlStatementContext.getTablesContext().getDatabaseName().isPresent()).thenReturn(true); + when(sqlStatementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.of("DatabaseName")); assertGetSQLTokenGenerators(sqlStatementContext); } diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/keygen/generator/GeneratedKeyAssignmentTokenGeneratorTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/keygen/generator/GeneratedKeyAssignmentTokenGeneratorTest.java index 3b8f4b949286a..4f4aa12eb1f0f 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/keygen/generator/GeneratedKeyAssignmentTokenGeneratorTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/keygen/generator/GeneratedKeyAssignmentTokenGeneratorTest.java @@ -40,7 +40,7 @@ class GeneratedKeyAssignmentTokenGeneratorTest { @Test void assertIsGenerateSQLToken() { InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); - when(insertStatementContext.getSqlStatement().getSetAssignment().isPresent()).thenReturn(true); + when(insertStatementContext.getSqlStatement().getSetAssignment()).thenReturn(Optional.of(mock(SetAssignmentSegment.class))); assertTrue(new GeneratedKeyAssignmentTokenGenerator().isGenerateSQLToken(insertStatementContext)); } diff --git a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/index/PostgreSQLIndexSQLGeneratorTest.java b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/index/PostgreSQLIndexSQLGeneratorTest.java index de572aab2eee1..5afdc2efa9314 100644 --- a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/index/PostgreSQLIndexSQLGeneratorTest.java +++ b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/index/PostgreSQLIndexSQLGeneratorTest.java @@ -40,7 +40,7 @@ void assertGenerate() throws SQLException { ResultSet getNodesResultSet = mockGetNodesResultSet(); when(connection.createStatement().executeQuery( contains("SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name," + "\n" + "(SELECT (CASE WHEN count(i.inhrelid) > 0 THEN true ELSE false END)"))) - .thenReturn(getNodesResultSet); + .thenReturn(getNodesResultSet); ResultSet getPropertiesResultSet = mockGetPropertiesResultSet(); when(connection.createStatement().executeQuery(contains("SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, indisclustered"))).thenReturn(getPropertiesResultSet); Map context = new HashMap<>(5, 1F); diff --git a/kernel/data-pipeline/scenario/cdc/client/pom.xml b/kernel/data-pipeline/scenario/cdc/client/pom.xml index d7a876e88fa28..480a490904ea8 100644 --- a/kernel/data-pipeline/scenario/cdc/client/pom.xml +++ b/kernel/data-pipeline/scenario/cdc/client/pom.xml @@ -45,14 +45,17 @@ org.opengauss opengauss-jdbc + provided org.postgresql postgresql + provided com.mysql mysql-connector-j + provided diff --git a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java index 6e092cfd2bfbb..d616631491814 100644 --- a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java +++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java @@ -129,7 +129,6 @@ void assertBeforeExecuteSQLWhenNotReadCommittedIsolationLevel() throws SQLExcept @Test void assertBeforeExecuteSQLWhenGlobalClockTransactionExecutorAbsent() throws SQLException { when(rule.getConfiguration().isEnabled()).thenReturn(true); - when(rule.getGlobalClockProvider()).thenReturn(Optional.of(globalClockProvider)); transactionHook.beforeExecuteSQL(rule, databaseType, Collections.emptyList(), transactionContext, TransactionIsolationLevel.READ_COMMITTED); when(DatabaseTypedSPILoader.findService(GlobalClockTransactionExecutor.class, databaseType)).thenReturn(Optional.empty()); verify(globalClockTransactionExecutor, times(0)).sendSnapshotTimestamp(any(), anyLong()); diff --git a/kernel/transaction/type/xa/core/pom.xml b/kernel/transaction/type/xa/core/pom.xml index 391c5bc21428c..e1b70a29aab53 100644 --- a/kernel/transaction/type/xa/core/pom.xml +++ b/kernel/transaction/type/xa/core/pom.xml @@ -51,33 +51,45 @@ org.postgresql postgresql + provided + true com.mysql mysql-connector-j + provided + true com.oracle.database.jdbc ojdbc8 ${ojdbc8.version} - test + provided true com.microsoft.sqlserver mssql-jdbc + provided + true org.mariadb.jdbc mariadb-java-client + provided + true org.opengauss opengauss-jdbc + provided + true com.h2database h2 + provided + true diff --git a/pom.xml b/pom.xml index 47dfbde8720d5..78c4df21ba138 100644 --- a/pom.xml +++ b/pom.xml @@ -66,28 +66,31 @@ **/autogen/**/* - 32.1.2-jre - 3.39.0 - 2.22.0 + 33.4.0-jre + 3.48.4 + 2.36.0 1.3 - 3.15.0 - 1.16.0 + 3.17.0 + 1.17.2 3.6.1 + 1.27.1 + 2.11.0 + 1.13.0 2.9.3 - 2.14.2 - 2.4.0 + 2.14.5 + 3.0.0 - 4.10.1 - 2.2 - 2.10.1 - 2.16.1 + 4.13.2 + 2.3 + 2.11.0 + 2.18.2 2.9.0 - 2.4.10 - 2.4.9 - 9.3 - 4.0.22 - 2.3.31 + 2.5.1 + 2.5.1 + 9.7.1 + 4.0.24 + 2.3.34 1.15.4 8.0.0 @@ -99,17 +102,17 @@ 3.2.1.Final 2.2.0 - 4.1.112.Final - 1.78.1 + 4.1.117.Final + 1.80 - 5.7.0 + 5.7.1 3.9.2 - 0.12.0 + 0.15.0 0.7.7 - 4.5.1 + 4.5.11 - 1.65.1 - 3.21.12 + 1.69.1 + 4.29.3 4.12.0 3.0.4 @@ -119,87 +122,87 @@ 1.2 1.18.36 - 2.9.3 + 2.10.1 - 42.7.2 - 8.3.0 - 6.1.7.jre8-preview + 42.7.5 + 9.1.0 + 12.9.0.jre8-preview 2.2.224 - 3.1.0-og - 2.4.2 + 6.0.0-og + 2.7.12 0.6.3 4.0.1 1.6.0 3.3.6 - 0.288.1 + 0.290 5.0.6.java8 4.0.3 - 0.11.0 - 0.16.1 - 1.41.0 - 1.27.0-alpha - 1.9.10 + 0.16.0 + 1.1.0 + 1.46.0 + 1.29.0-alpha + 1.9.25 - 5.11.2 + 5.11.4 3.0 4.11.0 4.2.2 - 1.20.3 - 1.9.0 + 1.20.4 + 1.13.0 - 24.1.0 - 4.4.6 + 24.1.1 + 5.2.0 0.6.1 1.4.13 - 0.3.1 + 0.6.0 0.10.4 - 1.0.0 + 3.0.0 4.9.10 - 3.2.1 + 3.5.0 3.13.0 3.3.1 - 3.5.1 - 3.2.5 - 3.3.0 - 3.1.3 - 3.3.0 - 3.6.0 - 3.1.0 + 3.5.2 + 3.5.2 + 3.4.2 + 3.2.3 + 3.6.0 + 3.8.1 + 3.5.0 - 3.2.1 - 3.1.1 - 3.0.0 - 3.5.0 + 3.3.1 + 3.1.3 + 3.1.1 + 3.7.1 - 3.5.1 - 1.10 + 3.6.0 + 1.11 - 0.15 - 2.24.1 - 3.2.1 - 3.20.0 - 4.7.2.1 - 7.6.0 - 1.12.0 - 3.9.1.2184 + 0.16.1 + 2.44.2 + 3.6.0 + 3.26.0 + 4.8.6.6 + 7.6.9 + 1.13.0 + 5.0.0.4389 - 4.0.0-M13 - 3.5.0 + 3.12.1 + 3.8.0 3.5.0 - 3.3.0 - 2.0 - 2.4 - 0.8.8 - 10.0.3 + 3.6.0 + 2.1 + 3.2.1 + 0.8.12 + 12.0.0 @@ -511,12 +514,6 @@ pom import - - org.hamcrest - hamcrest - ${hamcrest.version} - test - org.mockito mockito-bom @@ -615,6 +612,8 @@ org.hamcrest hamcrest + ${hamcrest.version} + test org.mockito diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetComputeNodeStateExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetComputeNodeStateExecutorTest.java index af62131be69ee..77309499fd719 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetComputeNodeStateExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetComputeNodeStateExecutorTest.java @@ -19,10 +19,14 @@ import org.apache.shardingsphere.distsql.statement.ral.updatable.SetComputeNodeStateStatement; import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException; +import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.state.instance.InstanceState; +import org.apache.shardingsphere.infra.state.instance.InstanceStateContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.junit.jupiter.api.Test; +import java.util.Optional; + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -48,7 +52,9 @@ void assertExecuteUpdateWithCurrentUsingInstance() { void assertExecuteUpdateWithAlreadyDisableInstance() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getId()).thenReturn("currentInstance"); - when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID").isPresent()).thenReturn(true); + ComputeNodeInstance computeNodeInstance = mock(ComputeNodeInstance.class); + when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID")).thenReturn(Optional.of(computeNodeInstance)); + when(computeNodeInstance.getState()).thenReturn(mock(InstanceStateContext.class)); when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID").get().getState().getCurrentState()) .thenReturn(InstanceState.CIRCUIT_BREAK); assertThrows(UnsupportedSQLOperationException.class, () -> executor.executeUpdate(new SetComputeNodeStateStatement("DISABLE", "instanceID"), contextManager)); diff --git a/test/e2e/fixture/pom.xml b/test/e2e/fixture/pom.xml index 8e4dbfe64fe3e..3d07f7ea59159 100644 --- a/test/e2e/fixture/pom.xml +++ b/test/e2e/fixture/pom.xml @@ -92,11 +92,23 @@ org.jboss.narayana.jta jta ${narayana.version} + + + org.jboss.logging + jboss-logging + + org.jboss.narayana.jts narayana-jts-integration ${narayana.version} + + + org.jboss.logging + jboss-logging + + org.jboss diff --git a/test/e2e/operation/transaction/pom.xml b/test/e2e/operation/transaction/pom.xml index 518f26056ddfe..8f62645a2e6b1 100644 --- a/test/e2e/operation/transaction/pom.xml +++ b/test/e2e/operation/transaction/pom.xml @@ -101,11 +101,23 @@ org.jboss.narayana.jta jta ${narayana.version} + + + org.jboss.logging + jboss-logging + + org.jboss.narayana.jts narayana-jts-integration ${narayana.version} + + + org.jboss.logging + jboss-logging + + org.jboss diff --git a/test/it/binder/pom.xml b/test/it/binder/pom.xml index ad118b4367d1e..0eaa1f9dfb5d3 100644 --- a/test/it/binder/pom.xml +++ b/test/it/binder/pom.xml @@ -132,11 +132,6 @@ junit-jupiter-params compile - - org.hamcrest - hamcrest - compile - org.mockito mockito-core diff --git a/test/it/distsql/pom.xml b/test/it/distsql/pom.xml index fe2652cd333b9..258ebf7ef6b89 100644 --- a/test/it/distsql/pom.xml +++ b/test/it/distsql/pom.xml @@ -60,11 +60,6 @@ junit-jupiter-params compile - - org.hamcrest - hamcrest - compile - org.mockito mockito-core diff --git a/test/it/parser/pom.xml b/test/it/parser/pom.xml index beca0a2a1adf8..2f51f4f8c4f19 100644 --- a/test/it/parser/pom.xml +++ b/test/it/parser/pom.xml @@ -134,11 +134,6 @@ junit-jupiter-params compile - - org.hamcrest - hamcrest - compile - org.mockito mockito-core diff --git a/test/it/yaml/pom.xml b/test/it/yaml/pom.xml index 278274ad80c28..1d2f9fd7732dd 100644 --- a/test/it/yaml/pom.xml +++ b/test/it/yaml/pom.xml @@ -58,10 +58,5 @@ junit-jupiter-engine compile - - org.hamcrest - hamcrest - compile - diff --git a/test/native/pom.xml b/test/native/pom.xml index d8f443aebd7b5..9e1a33e3429f7 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -123,6 +123,10 @@ org.apache.commons commons-pool2 + + org.springframework + * + diff --git a/test/pom.xml b/test/pom.xml index 812fdf3805ba0..beb60831cad34 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -70,6 +70,30 @@ org.testcontainers testcontainers test + + + org.apache.commons + commons-compress + + + + + org.apache.commons + commons-compress + ${commons-compress.version} + test + + + org.apache.commons + commons-io + + + + + org.hamcrest + hamcrest + ${hamcrest.version} + compile diff --git a/test/util/pom.xml b/test/util/pom.xml index 603487ee406e7..711920e850c83 100644 --- a/test/util/pom.xml +++ b/test/util/pom.xml @@ -42,11 +42,6 @@ junit-jupiter-params compile - - org.hamcrest - hamcrest - compile - org.mockito mockito-core