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 fff2ac1432f Refactor MetricsAdviceBaseTest (#23608)
fff2ac1432f is described below

commit fff2ac1432faf29670609be5ab61135e9178be03
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jan 17 16:00:11 2023 +0800

    Refactor MetricsAdviceBaseTest (#23608)
---
 .../metrics/core/advice/MetricsAdviceBaseTest.java | 30 ----------------------
 .../core/advice/RouteResultCountAdviceTest.java    |  7 +++++
 .../core/advice/SQLParseCountAdviceTest.java       | 17 ++++++++++++
 .../core/advice/SQLRouteCountAdviceTest.java       |  9 +++++++
 .../proxy/CommitTransactionsCountAdviceTest.java   |  6 +++++
 .../proxy/CurrentConnectionsCountAdviceTest.java   |  6 +++++
 .../advice/proxy/ExecuteErrorsCountAdviceTest.java |  6 +++++
 .../proxy/ExecuteLatencyHistogramAdviceTest.java   |  6 +++++
 .../core/advice/proxy/RequestsCountAdviceTest.java |  6 +++++
 .../proxy/RollbackTransactionsCountAdviceTest.java |  6 +++++
 10 files changed, 69 insertions(+), 30 deletions(-)

diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
index da96fe3b8e9..1138102a841 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
@@ -18,9 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
 
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapperFactory;
-import org.junit.After;
 import org.junit.BeforeClass;
 
 public abstract class MetricsAdviceBaseTest {
@@ -29,32 +27,4 @@ public abstract class MetricsAdviceBaseTest {
     public static void setup() {
         MetricsWrapperRegistry.setMetricsFactory(new FixtureWrapperFactory());
     }
-    
-    @After
-    public void reset() {
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_insert_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_update_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_delete_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_select_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_ddl_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_dcl_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_dal_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_tcl_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rdl_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_ral_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rul_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_insert_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_update_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_delete_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_select_sql_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_data_sources_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_tables_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_execute_latency_millis")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_execute_errors_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_current_connections")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_requests_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_commit_transactions_total")).reset();
-        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_rollback_transactions_total")).reset();
-    }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
index 19f30e59ccc..0de4e3ec34c 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrappe
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteMapper;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -33,6 +34,12 @@ import static org.mockito.Mockito.mock;
 
 public final class RouteResultCountAdviceTest extends MetricsAdviceBaseTest {
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_data_sources_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_tables_total")).reset();
+    }
+    
     @Test
     public void assertCountRouteResult() {
         RouteContext routeContext = new RouteContext();
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
index f86a6e1d61a..fd87e7852be 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQ
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLCommitStatement;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -44,6 +45,22 @@ import static org.mockito.Mockito.mock;
 
 public final class SQLParseCountAdviceTest extends MetricsAdviceBaseTest {
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_insert_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_update_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_delete_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_select_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_ddl_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_dcl_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_dal_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_tcl_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rdl_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_ral_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("parsed_rul_total")).reset();
+    }
+    
     @Test
     public void assertParseInsertSQL() {
         assertParse("parsed_insert_sql_total", new MySQLInsertStatement());
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
index 7a3c285f8c6..4cade5177d3 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQ
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -39,6 +40,14 @@ public final class SQLRouteCountAdviceTest extends 
MetricsAdviceBaseTest {
     
     private final SQLRouteCountAdvice advice = new SQLRouteCountAdvice();
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_insert_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_update_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_delete_sql_total")).reset();
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("routed_select_sql_total")).reset();
+    }
+    
     @Test
     public void assertInsertRoute() {
         QueryContext queryContext = new QueryContext(new 
CommonSQLStatementContext<>(new MySQLInsertStatement()), "", 
Collections.emptyList());
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
index 968814ee427..f3383eed828 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -35,6 +36,11 @@ public final class CommitTransactionsCountAdviceTest extends 
MetricsAdviceBaseTe
     
     private final CommitTransactionsCountAdvice advice = new 
CommitTransactionsCountAdvice();
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_commit_transactions_total")).reset();
+    }
+    
     @Test
     public void assertMethod() {
         advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class), 
new Object[]{});
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
index b160e24779f..cff64cb8cea 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -34,6 +35,11 @@ public final class CurrentConnectionsCountAdviceTest extends 
MetricsAdviceBaseTe
     
     private final CurrentConnectionsCountAdvice advice = new 
CurrentConnectionsCountAdvice();
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_current_connections")).reset();
+    }
+    
     @Test
     public void assertCountCurrentConnections() {
         MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
index fae2516f214..a9f6556cd31 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -31,6 +32,11 @@ import static org.mockito.Mockito.mock;
 
 public final class ExecuteErrorsCountAdviceTest extends MetricsAdviceBaseTest {
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_execute_errors_total")).reset();
+    }
+    
     @Test
     public void assertCountExecuteErrors() {
         MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
index fe8c15b29af..9514639784b 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -31,6 +32,11 @@ import static org.mockito.Mockito.mock;
 
 public final class ExecuteLatencyHistogramAdviceTest extends 
MetricsAdviceBaseTest {
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_execute_latency_millis")).reset();
+    }
+    
     @Test
     public void assertExecuteLatencyHistogram() throws InterruptedException {
         ExecuteLatencyHistogramAdvice advice = new 
ExecuteLatencyHistogramAdvice();
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
index f95d6034110..0386f626d71 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -33,6 +34,11 @@ public final class RequestsCountAdviceTest extends 
MetricsAdviceBaseTest {
     
     private final RequestsCountAdvice advice = new RequestsCountAdvice();
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_requests_total")).reset();
+    }
+    
     @Test
     public void assertCountRequests() {
         MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
index e4ff4ea770b..ddeb513b4a4 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
+import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
@@ -33,6 +34,11 @@ public final class RollbackTransactionsCountAdviceTest 
extends MetricsAdviceBase
     
     private final RollbackTransactionsCountAdvice advice = new 
RollbackTransactionsCountAdvice();
     
+    @After
+    public void reset() {
+        ((FixtureWrapper) 
MetricsWrapperRegistry.get("proxy_rollback_transactions_total")).reset();
+    }
+    
     @Test
     public void assertMethod() {
         advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class), 
new Object[]{});

Reply via email to