You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/06/20 08:12:44 UTC
[shardingsphere] branch master updated: Refactor AlterTrafficRuleHandlerTest (#18450)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 c34477960a3 Refactor AlterTrafficRuleHandlerTest (#18450)
c34477960a3 is described below
commit c34477960a3483704ad7825b153da9d2190fc9a9
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Jun 20 16:12:38 2022 +0800
Refactor AlterTrafficRuleHandlerTest (#18450)
---
.../updatable/AlterTrafficRuleHandlerTest.java | 50 +++++++++-------------
1 file changed, 21 insertions(+), 29 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandlerTest.java
index 6724f6c262a..a748b24ddc3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandlerTest.java
@@ -44,53 +44,45 @@ import static org.mockito.Mockito.when;
public final class AlterTrafficRuleHandlerTest extends ProxyContextRestorer {
@Test(expected = InvalidAlgorithmConfigurationException.class)
- public void assertCheckWithInvalidAlgorithmType() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- ShardingSphereRuleMetaData globalRuleMetaData = mock(ShardingSphereRuleMetaData.class);
- when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
- TrafficRule rule = mock(TrafficRule.class);
- when(rule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());
- when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(rule);
- ProxyContext.init(contextManager);
- TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment("rule_name_1", Arrays.asList("olap", "order_by"),
- new AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid", new Properties()));
+ public void assertExecuteWithInvalidAlgorithmType() throws SQLException {
+ mockContextManager();
+ TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
+ "rule_name_1", Arrays.asList("olap", "order_by"), new AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid", new Properties()));
AlterTrafficRuleHandler handler = new AlterTrafficRuleHandler();
handler.init(getSQLStatement(trafficRuleSegment), null);
handler.execute();
}
@Test(expected = RequiredRuleMissedException.class)
- public void assertCheckWithNotExistRuleName() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- ShardingSphereRuleMetaData globalRuleMetaData = mock(ShardingSphereRuleMetaData.class);
- when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
- TrafficRule rule = mock(TrafficRule.class);
- when(rule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());
- when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(rule);
- ProxyContext.init(contextManager);
- TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment("rule_name_3", Arrays.asList("olap", "order_by"),
- new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
+ public void assertExecuteWithNotExistRuleName() throws SQLException {
+ mockContextManager();
+ TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
+ "rule_name_3", Arrays.asList("olap", "order_by"), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
AlterTrafficRuleHandler handler = new AlterTrafficRuleHandler();
handler.init(getSQLStatement(trafficRuleSegment), null);
handler.execute();
}
@Test
- public void assertCheckSuccess() throws SQLException {
+ public void assertExecute() throws SQLException {
+ mockContextManager();
+ TrafficRuleSegment trafficRuleSegment1 = new TrafficRuleSegment(
+ "rule_name_1", Arrays.asList("olap", "order_by"), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
+ TrafficRuleSegment trafficRuleSegment2 = new TrafficRuleSegment("rule_name_2", Collections.emptyList(),
+ new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), null);
+ AlterTrafficRuleHandler handler = new AlterTrafficRuleHandler();
+ handler.init(getSQLStatement(trafficRuleSegment1, trafficRuleSegment2), null);
+ handler.execute();
+ }
+
+ private void mockContextManager() {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
ShardingSphereRuleMetaData globalRuleMetaData = mock(ShardingSphereRuleMetaData.class);
- when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
TrafficRule rule = mock(TrafficRule.class);
when(rule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());
when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(rule);
+ when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
ProxyContext.init(contextManager);
- TrafficRuleSegment trafficRuleSegment1 = new TrafficRuleSegment("rule_name_1", Arrays.asList("olap", "order_by"),
- new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
- TrafficRuleSegment trafficRuleSegment2 = new TrafficRuleSegment("rule_name_2", Collections.emptyList(),
- new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), null);
- AlterTrafficRuleHandler handler = new AlterTrafficRuleHandler();
- handler.init(getSQLStatement(trafficRuleSegment1, trafficRuleSegment2), null);
- handler.execute();
}
private TrafficRuleConfiguration createTrafficRuleConfiguration() {