You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/05/07 11:01:26 UTC
[shardingsphere] branch master updated: Refactor TypedSPIRegistryTest (#17426)
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 645bf1c3fbc Refactor TypedSPIRegistryTest (#17426)
645bf1c3fbc is described below
commit 645bf1c3fbc94822512261df45029c38346a4bdf
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat May 7 19:01:20 2022 +0800
Refactor TypedSPIRegistryTest (#17426)
* Rename AlgorithmFixture
* Rename AlgorithmFixture
* Use @SingletonSPI to replace StatelessTypedSPI
* Remove StatefulTypedSPI
* Remove StatefulTypedSPI
* Refactor TypedSPIRegistryTest
---
.../spi/ShardingSphereServiceLoaderTest.java | 24 +++++++++----------
.../spi/type/typed/TypedSPIRegistryTest.java | 28 ++++++++++------------
...ulTypedSPIFixture.java => TypedSPIFixture.java} | 4 ++--
...PIFixtureImpl.java => TypedSPIFixtureImpl.java} | 8 +++----
.../stateless/StatelessTypedSPIFixture.java | 25 -------------------
.../stateless/StatelessTypedSPIFixtureImpl.java | 26 --------------------
...gsphere.spi.type.typed.fixture.TypedSPIFixture} | 2 +-
...yped.fixture.stateless.StatelessTypedSPIFixture | 18 --------------
8 files changed, 31 insertions(+), 104 deletions(-)
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
index 9446d20b670..815d10995b9 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
@@ -21,7 +21,7 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.spi.exception.ServiceLoaderInstantiationException;
import org.apache.shardingsphere.spi.fixture.NonSingletonFixtureService;
import org.apache.shardingsphere.spi.fixture.SingletonFixtureService;
-import org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixture;
+import org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture;
import org.junit.Test;
import java.lang.reflect.Field;
@@ -46,10 +46,10 @@ public final class ShardingSphereServiceLoaderTest {
@Test
public void assertGetSingletonServiceInstanceWhenIsExist() {
- ShardingSphereServiceLoader.register(StatefulTypedSPIFixture.class);
- Collection<?> collection = ShardingSphereServiceLoader.getSingletonServiceInstances(StatefulTypedSPIFixture.class);
+ ShardingSphereServiceLoader.register(TypedSPIFixture.class);
+ Collection<?> collection = ShardingSphereServiceLoader.getSingletonServiceInstances(TypedSPIFixture.class);
assertThat(collection.size(), is(1));
- assertThat(collection.iterator().next(), is(ShardingSphereServiceLoader.getSingletonServiceInstances(StatefulTypedSPIFixture.class).iterator().next()));
+ assertThat(collection.iterator().next(), is(ShardingSphereServiceLoader.getSingletonServiceInstances(TypedSPIFixture.class).iterator().next()));
}
@Test
@@ -61,19 +61,19 @@ public final class ShardingSphereServiceLoaderTest {
@Test
public void assertNewServiceInstanceWhenIsExist() {
- ShardingSphereServiceLoader.register(StatefulTypedSPIFixture.class);
- Collection<?> collection = ShardingSphereServiceLoader.newServiceInstances(StatefulTypedSPIFixture.class);
+ ShardingSphereServiceLoader.register(TypedSPIFixture.class);
+ Collection<?> collection = ShardingSphereServiceLoader.newServiceInstances(TypedSPIFixture.class);
assertThat(collection.size(), is(1));
- assertThat(collection.iterator().next(), not(ShardingSphereServiceLoader.getSingletonServiceInstances(StatefulTypedSPIFixture.class).iterator().next()));
+ assertThat(collection.iterator().next(), not(ShardingSphereServiceLoader.getSingletonServiceInstances(TypedSPIFixture.class).iterator().next()));
}
@Test
public void assertRegisterTwice() {
- ShardingSphereServiceLoader.register(StatefulTypedSPIFixture.class);
- Collection<?> actualFirstRegister = ShardingSphereServiceLoader.newServiceInstances(StatefulTypedSPIFixture.class);
+ ShardingSphereServiceLoader.register(TypedSPIFixture.class);
+ Collection<?> actualFirstRegister = ShardingSphereServiceLoader.newServiceInstances(TypedSPIFixture.class);
assertThat(actualFirstRegister.size(), is(1));
- ShardingSphereServiceLoader.register(StatefulTypedSPIFixture.class);
- Collection<?> actualSecondRegister = ShardingSphereServiceLoader.newServiceInstances(StatefulTypedSPIFixture.class);
+ ShardingSphereServiceLoader.register(TypedSPIFixture.class);
+ Collection<?> actualSecondRegister = ShardingSphereServiceLoader.newServiceInstances(TypedSPIFixture.class);
assertThat(actualSecondRegister.size(), is(actualFirstRegister.size()));
}
@@ -83,7 +83,7 @@ public final class ShardingSphereServiceLoaderTest {
method.setAccessible(true);
Throwable targetException = null;
try {
- method.invoke(null, StatefulTypedSPIFixture.class);
+ method.invoke(null, TypedSPIFixture.class);
} catch (final InvocationTargetException ex) {
targetException = ex.getTargetException();
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
index fd3e770e236..316d972f33c 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
@@ -19,12 +19,10 @@ package org.apache.shardingsphere.spi.type.typed;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
-import org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixture;
-import org.apache.shardingsphere.spi.type.typed.fixture.stateless.StatelessTypedSPIFixture;
+import org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture;
import org.junit.Before;
import org.junit.Test;
-import java.util.Optional;
import java.util.Properties;
import static org.junit.Assert.assertNotNull;
@@ -34,29 +32,27 @@ public final class TypedSPIRegistryTest {
@Before
public void init() {
- ShardingSphereServiceLoader.register(StatelessTypedSPIFixture.class);
- ShardingSphereServiceLoader.register(StatefulTypedSPIFixture.class);
+ ShardingSphereServiceLoader.register(TypedSPIFixture.class);
}
@Test
- public void assertFindStatelessRegisteredService() {
- assertTrue(TypedSPIRegistry.findRegisteredService(StatelessTypedSPIFixture.class, "Stateless_Fixture").isPresent());
+ public void assertFindRegisteredService() {
+ assertTrue(TypedSPIRegistry.findRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE").isPresent());
}
@Test
public void assertGetStatelessRegisteredService() {
- assertNotNull(TypedSPIRegistry.getRegisteredService(StatelessTypedSPIFixture.class, "Stateless_Fixture"));
+ assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE"));
}
@Test
- public void assertFindStatefulRegisteredService() {
- Optional<StatefulTypedSPIFixture> actual = TypedSPIRegistry.findRegisteredService(StatefulTypedSPIFixture.class, "Stateful_Fixture", createProperties());
- assertTrue(actual.isPresent());
+ public void assertFindRegisteredServiceWithProperties() {
+ assertTrue(TypedSPIRegistry.findRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", createProperties()).isPresent());
}
@Test
- public void assertGetStatefulRegisteredService() {
- TypedSPIRegistry.getRegisteredService(StatefulTypedSPIFixture.class, "Stateful_Fixture", createProperties());
+ public void assertGetStatelessRegisteredServiceWithProperties() {
+ assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", createProperties()));
}
private Properties createProperties() {
@@ -68,16 +64,16 @@ public final class TypedSPIRegistryTest {
@Test
public void assertGetStatefulRegisteredServiceWithAlias() {
- assertNotNull(TypedSPIRegistry.getRegisteredService(StatefulTypedSPIFixture.class, "Stateful_Alias", new Properties()));
+ assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.ALIAS", new Properties()));
}
@Test(expected = ServiceProviderNotFoundException.class)
public void assertGetStatefulRegisteredServiceWhenTypeIsNotExist() {
- TypedSPIRegistry.getRegisteredService(StatefulTypedSPIFixture.class, "NOT_EXISTED", new Properties());
+ TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED", new Properties());
}
@Test(expected = ServiceProviderNotFoundException.class)
public void assertGetStatelessRegisteredServiceWhenTypeIsNotExist() {
- TypedSPIRegistry.getRegisteredService(StatelessTypedSPIFixture.class, "NOT_EXISTED");
+ TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED");
}
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixture.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixture.java
similarity index 86%
rename from shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixture.java
rename to shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixture.java
index 6a2d6acc230..9ea44bf7191 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixture.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixture.java
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.type.typed.fixture.stateful;
+package org.apache.shardingsphere.spi.type.typed.fixture;
import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
import org.apache.shardingsphere.spi.type.typed.TypedSPI;
-public interface StatefulTypedSPIFixture extends TypedSPI, SPIPostProcessor {
+public interface TypedSPIFixture extends TypedSPI, SPIPostProcessor {
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixtureImpl.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
similarity index 82%
rename from shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixtureImpl.java
rename to shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
index d3c8b8d75b0..c736f3829ee 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateful/StatefulTypedSPIFixtureImpl.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.type.typed.fixture.stateful;
+package org.apache.shardingsphere.spi.type.typed.fixture;
import lombok.Getter;
import lombok.Setter;
@@ -26,17 +26,17 @@ import java.util.Properties;
@Getter
@Setter
-public final class StatefulTypedSPIFixtureImpl implements StatefulTypedSPIFixture {
+public final class TypedSPIFixtureImpl implements TypedSPIFixture {
private Properties props = new Properties();
@Override
public String getType() {
- return "Stateful_Fixture";
+ return "TYPED.FIXTURE";
}
@Override
public Collection<String> getTypeAliases() {
- return Collections.singletonList("Stateful_Alias");
+ return Collections.singletonList("TYPED.ALIAS");
}
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixture.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixture.java
deleted file mode 100644
index 053a8d5df4f..00000000000
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixture.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.spi.type.typed.fixture.stateless;
-
-import org.apache.shardingsphere.spi.annotation.SingletonSPI;
-import org.apache.shardingsphere.spi.type.typed.TypedSPI;
-
-@SingletonSPI
-public interface StatelessTypedSPIFixture extends TypedSPI {
-}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixtureImpl.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixtureImpl.java
deleted file mode 100644
index 5241e7b1e1d..00000000000
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/stateless/StatelessTypedSPIFixtureImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.spi.type.typed.fixture.stateless;
-
-public final class StatelessTypedSPIFixtureImpl implements StatelessTypedSPIFixture {
-
- @Override
- public String getType() {
- return "Stateless_Fixture";
- }
-}
diff --git a/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixture b/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture
similarity index 90%
rename from shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixture
rename to shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture
index f7de82f9e17..0c746fb921e 100644
--- a/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixture
+++ b/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.spi.type.typed.fixture.stateful.StatefulTypedSPIFixtureImpl
+org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixtureImpl
diff --git a/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateless.StatelessTypedSPIFixture b/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateless.StatelessTypedSPIFixture
deleted file mode 100644
index 265275a75e9..00000000000
--- a/shardingsphere-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.spi.type.typed.fixture.stateless.StatelessTypedSPIFixture
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.spi.type.typed.fixture.stateless.StatelessTypedSPIFixtureImpl