You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/06/20 16:23:25 UTC

[shardingsphere] branch master updated: Refactor DropTrafficRuleHandlerTest (#18467)

This is an automated email from the ASF dual-hosted git repository.

totalo 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 500fa90b97f Refactor DropTrafficRuleHandlerTest (#18467)
500fa90b97f is described below

commit 500fa90b97f12ee7b86e229beee4448df649b99b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Jun 21 00:23:20 2022 +0800

    Refactor DropTrafficRuleHandlerTest (#18467)
---
 .../updatable/DropTrafficRuleHandlerTest.java      | 35 ++++++++++------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandlerTest.java
index f25bb0d69eb..249225d020c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandlerTest.java
@@ -46,17 +46,15 @@ public final class DropTrafficRuleHandlerTest extends ProxyContextRestorer {
     
     @Test(expected = RequiredRuleMissedException.class)
     public void assertExecuteWithNotExistRule() throws SQLException {
-        ContextManager contextManager = mockContextManager();
-        ProxyContext.init(contextManager);
+        mockContextManager();
         DropTrafficRuleHandler handler = new DropTrafficRuleHandler();
         handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name"), false), null);
         handler.execute();
     }
     
     @Test
-    public void assertExecute() throws SQLException {
+    public void assertExecuteWithIfExists() throws SQLException {
         ContextManager contextManager = mockContextManager();
-        ProxyContext.init(contextManager);
         DropTrafficRuleHandler handler = new DropTrafficRuleHandler();
         handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name_1"), false), null);
         handler.execute();
@@ -70,32 +68,30 @@ public final class DropTrafficRuleHandlerTest extends ProxyContextRestorer {
     }
     
     @Test
-    public void assertExecuteWithIfExists() throws SQLException {
+    public void assertExecuteWithNotExistRuleAndIfExists() throws SQLException {
         ContextManager contextManager = mockContextManager();
-        ProxyContext.init(contextManager);
         DropTrafficRuleHandler handler = new DropTrafficRuleHandler();
-        handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name_1"), false), null);
+        handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name_3"), true), null);
         handler.execute();
         TrafficRuleConfiguration updatedConfig = contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
-        assertThat(updatedConfig.getTrafficStrategies().size(), is(1));
-        assertThat(updatedConfig.getLoadBalancers().size(), is(1));
-        assertThat(updatedConfig.getTrafficAlgorithms().size(), is(1));
-        assertThat(new ArrayList<>(updatedConfig.getTrafficStrategies()).get(0).getName(), is("rule_name_2"));
-        assertNotNull(updatedConfig.getTrafficAlgorithms().get("algorithm_2"));
-        assertNotNull(updatedConfig.getLoadBalancers().get("load_balancer_2"));
+        assertThat(updatedConfig.getTrafficStrategies().size(), is(2));
+        assertThat(updatedConfig.getLoadBalancers().size(), is(2));
+        assertThat(updatedConfig.getTrafficAlgorithms().size(), is(2));
     }
     
     @Test
-    public void assertExecuteWithNotExistRuleAndIfExists() throws SQLException {
+    public void assertExecute() throws SQLException {
         ContextManager contextManager = mockContextManager();
-        ProxyContext.init(contextManager);
         DropTrafficRuleHandler handler = new DropTrafficRuleHandler();
-        handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name_3"), true), null);
+        handler.init(new DropTrafficRuleStatement(Collections.singleton("rule_name_1"), false), null);
         handler.execute();
         TrafficRuleConfiguration updatedConfig = contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
-        assertThat(updatedConfig.getTrafficStrategies().size(), is(2));
-        assertThat(updatedConfig.getLoadBalancers().size(), is(2));
-        assertThat(updatedConfig.getTrafficAlgorithms().size(), is(2));
+        assertThat(updatedConfig.getTrafficStrategies().size(), is(1));
+        assertThat(updatedConfig.getLoadBalancers().size(), is(1));
+        assertThat(updatedConfig.getTrafficAlgorithms().size(), is(1));
+        assertThat(new ArrayList<>(updatedConfig.getTrafficStrategies()).get(0).getName(), is("rule_name_2"));
+        assertNotNull(updatedConfig.getTrafficAlgorithms().get("algorithm_2"));
+        assertNotNull(updatedConfig.getLoadBalancers().get("load_balancer_2"));
     }
     
     private ContextManager mockContextManager() {
@@ -105,6 +101,7 @@ public final class DropTrafficRuleHandlerTest extends ProxyContextRestorer {
         TrafficRule rule = mock(TrafficRule.class);
         when(rule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());
         when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(rule);
+        ProxyContext.init(result);
         return result;
     }