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/08/08 06:59:56 UTC
[shardingsphere] branch master updated: Issue#6594 (#6677)
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 7fbd7eb Issue#6594 (#6677)
7fbd7eb is described below
commit 7fbd7ebfdda68a79c5be41c7516e6d87e0cc3694
Author: Serendipity <ja...@163.com>
AuthorDate: Sat Aug 8 14:59:47 2020 +0800
Issue#6594 (#6677)
* add test cases for infra.spi #6594
* add test case for OrderedSPIRegistry
* add test case for SingletonServiceLoader
* add test cases for infra.spi
* fix CI check
* add a new line in the end of META-INF/services/OderedSPIFixture
---
.../infra/spi/fixture/FixtureCustomInterface.java | 21 ++++++++
.../spi/fixture/FixtureCustomInterfaceImpl.java | 21 ++++++++
.../infra/spi/fixture/OrderedSPIFixture.java | 23 +++++++++
.../infra/spi/fixture/OrderedSPIFixtureImpl.java | 31 ++++++++++++
.../infra/spi/order/OrderedSPIRegistryTest.java | 57 ++++++++++++++++++++++
.../spi/singleton/SingletonServiceLoaderTest.java | 45 +++++++++++++++++
...rdingsphere.infra.spi.fixture.OrderedSPIFixture | 18 +++++++
7 files changed, 216 insertions(+)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterface.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterface.java
new file mode 100644
index 0000000..285399a
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterface.java
@@ -0,0 +1,21 @@
+/*
+ * 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 interface FixtureCustomInterface {
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterfaceImpl.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterfaceImpl.java
new file mode 100644
index 0000000..d1eacdc
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/FixtureCustomInterfaceImpl.java
@@ -0,0 +1,21 @@
+/*
+ * 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 FixtureCustomInterfaceImpl implements FixtureCustomInterface {
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixture.java
new file mode 100644
index 0000000..01675b5
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixture.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.order.OrderedSPI;
+
+public interface OrderedSPIFixture<T extends FixtureCustomInterface> extends OrderedSPI<T> {
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixtureImpl.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixtureImpl.java
new file mode 100644
index 0000000..97d44b9
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/fixture/OrderedSPIFixtureImpl.java
@@ -0,0 +1,31 @@
+/*
+ * 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 OrderedSPIFixtureImpl implements OrderedSPIFixture<FixtureCustomInterfaceImpl> {
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public Class<FixtureCustomInterfaceImpl> getTypeClass() {
+ return FixtureCustomInterfaceImpl.class;
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/order/OrderedSPIRegistryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/order/OrderedSPIRegistryTest.java
new file mode 100644
index 0000000..cc6b789
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/order/OrderedSPIRegistryTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.order;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.fixture.FixtureCustomInterface;
+import org.apache.shardingsphere.infra.spi.fixture.FixtureCustomInterfaceImpl;
+import org.apache.shardingsphere.infra.spi.fixture.OrderedSPIFixture;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class OrderedSPIRegistryTest {
+
+ @Before
+ public void init() {
+ ShardingSphereServiceLoader.register(OrderedSPIFixture.class);
+ }
+
+ @Test
+ public void assertGetRegisteredServicesByClass() {
+ Collection<FixtureCustomInterface> customInterfaceCollection = new LinkedList<>();
+ customInterfaceCollection.add(new FixtureCustomInterfaceImpl());
+ Collection<Class<?>> collection = customInterfaceCollection.stream().map(Object::getClass).collect(Collectors.toList());
+ Map<Class<?>, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServicesByClass(collection, OrderedSPIFixture.class);
+ assertThat(actual.size(), is(1));
+ }
+
+ @Test
+ public void assertGetRegisteredServices() {
+ Collection<FixtureCustomInterface> collection = new LinkedList<>();
+ collection.add(new FixtureCustomInterfaceImpl());
+ Map<FixtureCustomInterface, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServices(collection, OrderedSPIFixture.class);
+ assertThat(actual.size(), is(1));
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
new file mode 100644
index 0000000..6dcc350
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.singleton;
+
+import org.apache.shardingsphere.infra.spi.fixture.TypedSPIFixture;
+import org.junit.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+public final class SingletonServiceLoaderTest {
+
+ @Test
+ public void assertGetSingletonServiceLoader() {
+ SingletonServiceLoader<TypedSPIFixture> actualFirstServiceLoader = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class);
+ assertNotNull(actualFirstServiceLoader);
+ SingletonServiceLoader<TypedSPIFixture> actualSecondServiceLoader = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class);
+ assertNotNull(actualSecondServiceLoader);
+ assertThat(actualFirstServiceLoader, is(actualSecondServiceLoader));
+ }
+
+ @Test
+ public void assertNewServiceInstanceWhenIsNotExist() {
+ Optional<TypedSPIFixture> actual = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class).newServiceInstances();
+ assertThat(actual.isPresent(), is(true));
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.OrderedSPIFixture b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.OrderedSPIFixture
new file mode 100644
index 0000000..e6b45dd
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.spi.fixture.OrderedSPIFixture
@@ -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.OrderedSPIFixtureImpl