You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/07/29 07:12:31 UTC
[shardingsphere] branch master updated: Remove IndependentRuleFixture (#19679)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 f273268ae32 Remove IndependentRuleFixture (#19679)
f273268ae32 is described below
commit f273268ae325af36bc5df3bf2d8ee0418bca2df6
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jul 29 15:12:21 2022 +0800
Remove IndependentRuleFixture (#19679)
* Remove IndependentRuleFixture
* Refactor MergeEngineTest
---
.../shardingsphere-infra-merge/pom.xml | 8 +++++
.../infra/merge/MergeEngineTest.java | 24 ++++-----------
.../merge/fixture/rule/IndependentRuleFixture.java | 36 ----------------------
.../memory/fixture/TestMemoryMergedResult.java | 7 ++---
4 files changed, 17 insertions(+), 58 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/pom.xml b/shardingsphere-infra/shardingsphere-infra-merge/pom.xml
index 2a41eb4b6f3..e9f5d8e707c 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/pom.xml
+++ b/shardingsphere-infra/shardingsphere-infra-merge/pom.xml
@@ -38,6 +38,14 @@
<artifactId>shardingsphere-infra-executor</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-linq4j</artifactId>
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java
index 6c1a69778ee..d0a305e65ce 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java
@@ -19,15 +19,12 @@ package org.apache.shardingsphere.infra.merge;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.fixture.rule.DecoratorRuleFixture;
-import org.apache.shardingsphere.infra.merge.fixture.rule.IndependentRuleFixture;
import org.apache.shardingsphere.infra.merge.fixture.rule.MergerRuleFixture;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.junit.Before;
+import org.apache.shardingsphere.test.fixture.rule.MockedRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -53,41 +50,32 @@ public final class MergeEngineTest {
@Mock
private QueryResult queryResult;
- @Mock
- private SQLStatementContext<?> sqlStatementContext;
-
- @Before
- public void setUp() {
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- when(database.getResource().getDatabaseType()).thenReturn(mock(DatabaseType.class));
- }
-
@Test
public void assertMergeWithIndependentRule() throws SQLException {
- when(database.getRuleMetaData().getRules()).thenReturn(Collections.singleton(new IndependentRuleFixture()));
+ when(database.getRuleMetaData().getRules()).thenReturn(Collections.singleton(new MockedRule()));
when(queryResult.getValue(1, String.class)).thenReturn("test");
- MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), sqlStatementContext);
+ MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class));
assertThat(actual.getValue(1, String.class), is("test"));
}
@Test
public void assertMergeWithMergerRuleOnly() throws SQLException {
when(database.getRuleMetaData().getRules()).thenReturn(Collections.singleton(new MergerRuleFixture()));
- MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), sqlStatementContext);
+ MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class));
assertThat(actual.getValue(1, String.class), is("merged_value"));
}
@Test
public void assertMergeWithDecoratorRuleOnly() throws SQLException {
when(database.getRuleMetaData().getRules()).thenReturn(Collections.singleton(new DecoratorRuleFixture()));
- MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), sqlStatementContext);
+ MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class));
assertThat(actual.getValue(1, String.class), is("decorated_value"));
}
@Test
public void assertMergeWithMergerRuleAndDecoratorRuleTogether() throws SQLException {
when(database.getRuleMetaData().getRules()).thenReturn(Arrays.asList(new MergerRuleFixture(), new DecoratorRuleFixture()));
- MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), sqlStatementContext);
+ MergedResult actual = new MergeEngine(database, new ConfigurationProperties(new Properties())).merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class));
assertThat(actual.getValue(1, String.class), is("decorated_merged_value"));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/IndependentRuleFixture.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/IndependentRuleFixture.java
deleted file mode 100644
index d4891f2a874..00000000000
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/IndependentRuleFixture.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.shardingsphere.infra.merge.fixture.rule;
-
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import static org.mockito.Mockito.mock;
-
-public final class IndependentRuleFixture implements ShardingSphereRule {
-
- @Override
- public RuleConfiguration getConfiguration() {
- return mock(RuleConfiguration.class);
- }
-
- @Override
- public String getType() {
- return IndependentRuleFixture.class.getSimpleName();
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/fixture/TestMemoryMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/fixture/TestMemoryMergedResult.java
index ed040f4608e..1f10f82068b 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/fixture/TestMemoryMergedResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/fixture/TestMemoryMergedResult.java
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.infra.merge.result.impl.memory.fixture;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
-import org.apache.shardingsphere.infra.merge.fixture.rule.IndependentRuleFixture;
import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult;
import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.test.fixture.rule.MockedRule;
import java.sql.SQLException;
import java.util.Collections;
@@ -32,7 +32,7 @@ import java.util.List;
import static org.mockito.Mockito.mock;
@Getter
-public final class TestMemoryMergedResult extends MemoryMergedResult<IndependentRuleFixture> {
+public final class TestMemoryMergedResult extends MemoryMergedResult<MockedRule> {
private MemoryQueryResultRow memoryQueryResultRow;
@@ -41,8 +41,7 @@ public final class TestMemoryMergedResult extends MemoryMergedResult<Independent
}
@Override
- protected List<MemoryQueryResultRow> init(final IndependentRuleFixture rule, final ShardingSphereSchema schema,
- final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) {
+ protected List<MemoryQueryResultRow> init(final MockedRule rule, final ShardingSphereSchema schema, final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) {
memoryQueryResultRow = mock(MemoryQueryResultRow.class);
return Collections.singletonList(memoryQueryResultRow);
}