You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/10/11 02:52:59 UTC

[shardingsphere] branch master updated: Add test case for RequiredSPIRegistry (#7736)

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 24ee8bc  Add test case for RequiredSPIRegistry (#7736)
24ee8bc is described below

commit 24ee8bcdacb5d6fd393ca581a8cc946ba10f27e5
Author: Serendipity <ja...@163.com>
AuthorDate: Sun Oct 11 10:52:47 2020 +0800

    Add test case for RequiredSPIRegistry (#7736)
    
    * Add test case for RequiredSPIRegistry
    
    * rename class
---
 .../spi/fixture/NoImplRequiredSPIFixture.java      | 24 ++++++++++
 .../infra/spi/fixture/RequiredSPIFixture.java      | 23 ++++++++++
 .../RequiredSPIFixtureDefaultFalseImpl.java        | 27 +++++++++++
 .../fixture/RequiredSPIFixtureDefaultTrueImpl.java | 27 +++++++++++
 .../infra/spi/fixture/RequiredSPIImpl.java         | 28 ++++++++++++
 .../spi/required/RequiredSPIRegistryTest.java      | 53 ++++++++++++++++++++++
 ...dingsphere.infra.spi.fixture.RequiredSPIFixture | 19 ++++++++
 ...e.shardingsphere.infra.spi.required.RequiredSPI | 18 ++++++++
 8 files changed, 219 insertions(+)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/NoImplRequiredSPIFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/NoImplRequiredSPIFixture.java
new file mode 100644
index 0000000..25585c4
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/NoImplRequiredSPIFixture.java
@@ -0,0 +1,24 @@
+/*
+ * 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.infra.spi.fixture;
+
+import org.apache.shardingsphere.infra.spi.required.RequiredSPI;
+
+public interface NoImplRequiredSPIFixture extends RequiredSPI {
+}
+
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixture.java
new file mode 100644
index 0000000..0f0ebd3
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixture.java
@@ -0,0 +1,23 @@
+/*
+ * 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.infra.spi.fixture;
+
+import org.apache.shardingsphere.infra.spi.required.RequiredSPI;
+
+public interface RequiredSPIFixture extends RequiredSPI {
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultFalseImpl.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultFalseImpl.java
new file mode 100644
index 0000000..8caab93
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultFalseImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.infra.spi.fixture;
+
+public final class RequiredSPIFixtureDefaultFalseImpl implements RequiredSPIFixture {
+    
+    @Override
+    public boolean isDefault() {
+        return false;
+    }
+}
+
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultTrueImpl.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultTrueImpl.java
new file mode 100644
index 0000000..9682933
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIFixtureDefaultTrueImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.infra.spi.fixture;
+
+public final class RequiredSPIFixtureDefaultTrueImpl implements RequiredSPIFixture {
+    
+    @Override
+    public boolean isDefault() {
+        return true;
+    }
+}
+
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIImpl.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIImpl.java
new file mode 100644
index 0000000..5865771
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/RequiredSPIImpl.java
@@ -0,0 +1,28 @@
+/*
+ * 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.infra.spi.fixture;
+
+import org.apache.shardingsphere.infra.spi.required.RequiredSPI;
+
+public final class RequiredSPIImpl implements RequiredSPI {
+    
+    @Override
+    public boolean isDefault() {
+        return false;
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistryTest.java
new file mode 100644
index 0000000..ebebbb6
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistryTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.infra.spi.required;
+
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
+import org.apache.shardingsphere.infra.spi.fixture.NoImplRequiredSPIFixture;
+import org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixture;
+import org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixtureDefaultFalseImpl;
+import org.apache.shardingsphere.infra.spi.fixture.RequiredSPIImpl;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public final class RequiredSPIRegistryTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(RequiredSPIFixture.class);
+        ShardingSphereServiceLoader.register(RequiredSPI.class);
+    }
+    
+    @Test(expected = ServiceProviderNotFoundException.class)
+    public void assertRegisteredServiceNotExisted() {
+        RequiredSPIRegistry.getRegisteredService(NoImplRequiredSPIFixture.class);
+    }
+    
+    @Test
+    public void assertRegisteredServiceOnlyOne() {
+        RequiredSPI actualRegisteredService = RequiredSPIRegistry.getRegisteredService(RequiredSPI.class);
+        assertTrue(actualRegisteredService instanceof RequiredSPIImpl);
+    }
+    
+    @Test
+    public void assertRegisteredServiceMoreThanOne() {
+        RequiredSPIFixture actualRegisteredService = RequiredSPIRegistry.getRegisteredService(RequiredSPIFixture.class);
+        assertTrue(actualRegisteredService instanceof RequiredSPIFixtureDefaultFalseImpl);
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixture b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixture
new file mode 100644
index 0000000..2757741
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixture
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixtureDefaultFalseImpl
+org.apache.shardingsphere.infra.spi.fixture.RequiredSPIFixtureDefaultTrueImpl
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.required.RequiredSPI b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.required.RequiredSPI
new file mode 100644
index 0000000..77c6308
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.required.RequiredSPI
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.spi.fixture.RequiredSPIImpl