This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 c4af6cadb5d Refactor ShardingSphereServiceLoaderTest (#22712)
c4af6cadb5d is described below
commit c4af6cadb5d9479dbb353d5506d8a5dec68f0204
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Dec 7 14:16:32 2022 +0800
Refactor ShardingSphereServiceLoaderTest (#22712)
* Add test cases for GenericSQLException
* Add ShardingSphereExternalExceptionTest
* Refactor TypedPropertiesTest
* Fix checkstyle
* Refactor ShardingSphereServiceLoaderTest
* Fix compile error
---
.../util/spi/type/ordered/cache/OrderedServicesCache.java | 12 ++++++------
.../infra/util/spi/ShardingSphereServiceLoaderTest.java | 13 +++++--------
.../util/spi/fixture/{ => impl}/MultitonSPIFixtureImpl.java | 4 +++-
.../spi/fixture/{ => impl}/SingletonSPIFixtureImpl.java | 4 +++-
.../infra/util/spi/type/ordered/OrderedSPIRegistryTest.java | 2 +-
.../spi/type/ordered/cache/OrderedServicesCacheTest.java | 2 +-
...shardingsphere.infra.util.spi.fixture.MultitonSPIFixture | 2 +-
...hardingsphere.infra.util.spi.fixture.SingletonSPIFixture | 2 +-
8 files changed, 21 insertions(+), 20 deletions(-)
diff --git
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCache.java
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCache.java
index e6af621cff7..6f92d05985d 100644
---
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCache.java
+++
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCache.java
@@ -29,12 +29,12 @@ import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Ordered services cached.
+ * Ordered services cache.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class OrderedServicesCache {
- private static volatile SoftReference<Map<Key, Map<?, ?>>> softCache = new
SoftReference<>(new ConcurrentHashMap<>(128));
+ private static volatile SoftReference<Map<Key, Map<?, ?>>> cache = new
SoftReference<>(new ConcurrentHashMap<>(128));
/**
* Find cached services.
@@ -44,7 +44,7 @@ public final class OrderedServicesCache {
* @return cached services
*/
public static Optional<Map<?, ?>> findCachedServices(final Class<?>
spiClass, final Collection<?> types) {
- return Optional.ofNullable(softCache.get()).map(optional ->
optional.get(new Key(spiClass, types)));
+ return Optional.ofNullable(cache.get()).map(optional ->
optional.get(new Key(spiClass, types)));
}
/**
@@ -55,13 +55,13 @@ public final class OrderedServicesCache {
* @param services services to be cached
*/
public static void cacheServices(final Class<?> spiClass, final
Collection<?> types, final Map<?, ?> services) {
- Map<Key, Map<?, ?>> cache = softCache.get();
+ Map<Key, Map<?, ?>> cache = OrderedServicesCache.cache.get();
if (null == cache) {
synchronized (OrderedServicesCache.class) {
- cache = softCache.get();
+ cache = OrderedServicesCache.cache.get();
if (null == cache) {
cache = new ConcurrentHashMap<>(128);
- softCache = new SoftReference<>(cache);
+ OrderedServicesCache.cache = new SoftReference<>(cache);
}
}
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
index 67f5cfeeddd..fbae5a90ef1 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
@@ -19,9 +19,9 @@ package org.apache.shardingsphere.infra.util.spi;
import org.apache.shardingsphere.infra.util.spi.fixture.EmptySPIFixture;
import org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture;
-import org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixtureImpl;
import org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture;
-import
org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixtureImpl;
+import
org.apache.shardingsphere.infra.util.spi.fixture.impl.MultitonSPIFixtureImpl;
+import
org.apache.shardingsphere.infra.util.spi.fixture.impl.SingletonSPIFixtureImpl;
import org.junit.Test;
import java.util.Collection;
@@ -34,12 +34,6 @@ import static org.junit.Assert.assertTrue;
public final class ShardingSphereServiceLoaderTest {
- static {
- ShardingSphereServiceLoader.register(EmptySPIFixture.class);
- ShardingSphereServiceLoader.register(SingletonSPIFixture.class);
- ShardingSphereServiceLoader.register(MultitonSPIFixture.class);
- }
-
@Test
public void assertGetServiceInstancesWithUnregisteredSPI() {
assertTrue(ShardingSphereServiceLoader.getServiceInstances(Object.class).isEmpty());
@@ -47,11 +41,13 @@ public final class ShardingSphereServiceLoaderTest {
@Test
public void assertGetServiceInstancesWithEmptyInstances() {
+ ShardingSphereServiceLoader.register(EmptySPIFixture.class);
assertTrue(ShardingSphereServiceLoader.getServiceInstances(EmptySPIFixture.class).isEmpty());
}
@Test
public void assertGetServiceInstancesWithSingletonSPI() {
+ ShardingSphereServiceLoader.register(SingletonSPIFixture.class);
Collection<SingletonSPIFixture> actual =
ShardingSphereServiceLoader.getServiceInstances(SingletonSPIFixture.class);
assertThat(actual.size(), is(1));
SingletonSPIFixture actualInstance = actual.iterator().next();
@@ -61,6 +57,7 @@ public final class ShardingSphereServiceLoaderTest {
@Test
public void assertGetServiceInstancesWithMultitonSPI() {
+ ShardingSphereServiceLoader.register(MultitonSPIFixture.class);
Collection<MultitonSPIFixture> actual =
ShardingSphereServiceLoader.getServiceInstances(MultitonSPIFixture.class);
assertThat(actual.size(), is(1));
MultitonSPIFixture actualInstance = actual.iterator().next();
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/MultitonSPIFixtureImpl.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/MultitonSPIFixtureImpl.java
similarity index 86%
rename from
infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/MultitonSPIFixtureImpl.java
rename to
infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/MultitonSPIFixtureImpl.java
index a197f6b7b31..f919d46353b 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/MultitonSPIFixtureImpl.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/MultitonSPIFixtureImpl.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.spi.fixture;
+package org.apache.shardingsphere.infra.util.spi.fixture.impl;
+
+import org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture;
public final class MultitonSPIFixtureImpl implements MultitonSPIFixture {
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/SingletonSPIFixtureImpl.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/SingletonSPIFixtureImpl.java
similarity index 86%
rename from
infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/SingletonSPIFixtureImpl.java
rename to
infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/SingletonSPIFixtureImpl.java
index fa906ed8030..85192618799 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/SingletonSPIFixtureImpl.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/fixture/impl/SingletonSPIFixtureImpl.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.spi.fixture;
+package org.apache.shardingsphere.infra.util.spi.fixture.impl;
+
+import org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture;
public final class SingletonSPIFixtureImpl implements SingletonSPIFixture {
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/OrderedSPIRegistryTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/OrderedSPIRegistryTest.java
index ed03ed6f6b8..751359f1266 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/OrderedSPIRegistryTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/OrderedSPIRegistryTest.java
@@ -44,7 +44,7 @@ public final class OrderedSPIRegistryTest {
@After
public void cleanCache() throws NoSuchFieldException,
IllegalAccessException {
- Field field = OrderedServicesCache.class.getDeclaredField("softCache");
+ Field field = OrderedServicesCache.class.getDeclaredField("cache");
field.setAccessible(true);
field.set(null, new SoftReference<>(new ConcurrentHashMap<>()));
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCacheTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCacheTest.java
index c1d5a83a661..4a31546e4be 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCacheTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/ordered/cache/OrderedServicesCacheTest.java
@@ -47,7 +47,7 @@ public final class OrderedServicesCacheTest {
@After
public void cleanCache() throws NoSuchFieldException,
IllegalAccessException {
- Field field = OrderedServicesCache.class.getDeclaredField("softCache");
+ Field field = OrderedServicesCache.class.getDeclaredField("cache");
field.setAccessible(true);
field.set(null, new SoftReference<>(new ConcurrentHashMap<>()));
}
diff --git
a/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture
b/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture
index 5a361359a58..6654c6bcdf5 100644
---
a/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture
+++
b/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixture
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.util.spi.fixture.MultitonSPIFixtureImpl
+org.apache.shardingsphere.infra.util.spi.fixture.impl.MultitonSPIFixtureImpl
diff --git
a/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture
b/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture
index 68c3aa9e6b3..fe6cb31e885 100644
---
a/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture
+++
b/infra/util/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixture
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.util.spi.fixture.SingletonSPIFixtureImpl
+org.apache.shardingsphere.infra.util.spi.fixture.impl.SingletonSPIFixtureImpl