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 89e429cbc15 Reset ScheduleContextFactory after test completed (#19723)
89e429cbc15 is described below

commit 89e429cbc155e41273adf7b0ba59e8e04e713ea1
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 31 21:39:03 2022 +0800

    Reset ScheduleContextFactory after test completed (#19723)
---
 .../route/DatabaseDiscoverySQLRouterTest.java            |  6 ++++++
 .../dbdiscovery/rule/DatabaseDiscoveryRuleTest.java      | 16 +++++++++++-----
 ...lgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java |  1 +
 .../rule/builder/DatabaseDiscoveryRuleBuilderTest.java   |  1 +
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
index 96d8d2754f5..57fffa9b802 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
@@ -40,6 +40,7 @@ import 
org.apache.shardingsphere.infra.route.context.RouteUnit;
 import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -87,6 +88,11 @@ public final class DatabaseDiscoverySQLRouterTest {
         sqlRouter = (DatabaseDiscoverySQLRouter) 
SQLRouterFactory.getInstances(Collections.singleton(rule)).get(rule);
     }
     
+    @After
+    public void tearDown() {
+        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
+    }
+    
     @Test
     public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
         LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", 
Collections.emptyList());
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index 90eb8a29e9a..bcb0ec27690 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -27,7 +27,8 @@ import 
org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import javax.sql.DataSource;
@@ -49,12 +50,17 @@ import static org.mockito.Mockito.when;
 public final class DatabaseDiscoveryRuleTest {
     
     private final Map<String, DataSource> dataSourceMap = 
Collections.singletonMap("primary_ds", new MockedDataSource());
-
-    @Before
-    public void init() {
+    
+    @BeforeClass
+    public static void setUp() {
         ScheduleContextFactory.getInstance().init("foo_id", new 
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), 
false));
     }
-
+    
+    @AfterClass
+    public static void tearDown() {
+        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
+    }
+    
     @Test
     public void assertFindDataSourceRule() {
         Optional<DatabaseDiscoveryDataSourceRule> actual = 
createRule().findDataSourceRule("replica_ds");
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
index ffbe725612e..18cbc7d5228 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
@@ -55,5 +55,6 @@ public final class 
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
         
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
         assertThat(builder.build(algorithmProvidedRuleConfig, "",
                 Collections.singletonMap("name", new MockedDataSource()), 
Collections.emptyList(), instanceContext), 
instanceOf(DatabaseDiscoveryRule.class));
+        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
index c76ab569fff..41d1f1123f8 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
@@ -55,5 +55,6 @@ public final class DatabaseDiscoveryRuleBuilderTest {
         
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
         assertThat(builder.build(config, "test_schema",
                 Collections.singletonMap("name", new MockedDataSource()), 
Collections.emptyList(), instanceContext), 
instanceOf(DatabaseDiscoveryRule.class));
+        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
     }
 }

Reply via email to