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

zhangliang 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 ba5ee25264b add test for SwitchingResource (#18867)
ba5ee25264b is described below

commit ba5ee25264b2bd84180c102592e060071ecf92db
Author: csonezp <[email protected]>
AuthorDate: Tue Jul 5 20:56:52 2022 +0800

    add test for SwitchingResource (#18867)
---
 .../manager/switcher/SwitchingResourceTest.java    | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
new file mode 100644
index 00000000000..1f3e800569b
--- /dev/null
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.mode.manager.switcher;
+
+import 
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.times;
+
+public final class SwitchingResourceTest {
+    
+    @Test
+    public void assertCloseStaleDataSources() throws InterruptedException {
+        MockedDataSource dataSource = new MockedDataSource();
+        ShardingSphereResource shardingSphereResource = new 
ShardingSphereResource(Collections.singletonMap("foo_ds", dataSource));
+        ShardingSphereResource spyResource = spy(shardingSphereResource);
+        SwitchingResource switchingResource = new 
SwitchingResource(spyResource,
+                Collections.singletonMap("foo_ds", dataSource), 
Collections.singletonMap("foo_ds", dataSource));
+        switchingResource.closeStaleDataSources();
+        while (null == dataSource.getClosed() || !dataSource.getClosed()) {
+            Thread.sleep(10L);
+        }
+        assertTrue(dataSource.getClosed());
+        verify(spyResource, times(1)).close(dataSource);
+    }
+    
+}

Reply via email to