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 2022/05/09 11:39:10 UTC
[shardingsphere] branch master updated: Refactor OrderedSPIRegistryTest (#17490)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 8389633e3e3 Refactor OrderedSPIRegistryTest (#17490)
8389633e3e3 is described below
commit 8389633e3e396706bbd48744a216748a9f880b35
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon May 9 19:39:03 2022 +0800
Refactor OrderedSPIRegistryTest (#17490)
* Refactor H2Repository
* Refactor OrderedSPIRegistryTest
---
.../mode/repository/standalone/h2/H2Repository.java | 4 ++--
.../spi/type/ordered/OrderedSPIRegistry.java | 10 +---------
.../spi/type/ordered/OrderedSPIRegistryTest.java | 14 +++++++-------
.../spi/type/ordered/cache/OrderedServicesCacheTest.java | 16 ++++++++--------
.../ordered/fixture/OrderedInterfaceFixture.java} | 4 ++--
.../ordered/fixture/OrderedInterfaceFixtureImpl.java} | 4 ++--
.../spi/type/ordered/fixture/OrderedSPIFixture.java | 3 +--
.../spi/type/ordered/fixture/OrderedSPIFixtureImpl.java | 8 +++-----
8 files changed, 26 insertions(+), 37 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardin [...]
index 93740dd0b0a..325683277ee 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
@@ -64,11 +64,11 @@ public final class H2Repository implements StandalonePersistRepository {
jdbcUrl = Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.JDBC_URL))).orElse(DEFAULT_JDBC_URL);
user = Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.USER))).orElse(DEFAULT_USER);
password = Optional.ofNullable(Strings.emptyToNull(localRepositoryProps.getValue(H2RepositoryPropertyKey.PASSWORD))).orElse(DEFAULT_PASSWORD);
- init();
+ initTable();
}
@SneakyThrows
- private void init() {
+ private void initTable() {
connection = DriverManager.getConnection(jdbcUrl, user, password);
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE IF EXISTS REPOSITORY");
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
index 068461ede7f..37c6b0be347 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
@@ -102,15 +102,7 @@ public final class OrderedSPIRegistry {
return getRegisteredServices(spiClass, Comparator.naturalOrder());
}
- /**
- * Get registered services.
- *
- * @param spiClass class of ordered SPI
- * @param <T> type of ordered SPI class
- * @param comparator comparator
- * @return registered services
- */
- public static <T extends OrderedSPI<?>> Collection<T> getRegisteredServices(final Class<T> spiClass, final Comparator<Integer> comparator) {
+ private static <T extends OrderedSPI<?>> Collection<T> getRegisteredServices(final Class<T> spiClass, final Comparator<Integer> comparator) {
Map<Integer, T> result = new TreeMap<>(comparator);
for (T each : ShardingSphereServiceLoader.getServiceInstances(spiClass)) {
Preconditions.checkArgument(!result.containsKey(each.getOrder()), "Found same order `%s` with `%s` and `%s`", each.getOrder(), result.get(each.getOrder()), each);
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistryTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistryTest.java
index d6e80e55823..3673319f108 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistryTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistryTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.spi.type.ordered;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterface;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterfaceImpl;
+import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedInterfaceFixture;
+import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedInterfaceFixtureImpl;
import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedSPIFixture;
import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedSPIFixtureImpl;
import org.apache.shardingsphere.spi.type.ordered.cache.OrderedServicesCache;
@@ -52,23 +52,23 @@ public final class OrderedSPIRegistryTest {
@SuppressWarnings("rawtypes")
@Test
public void assertGetRegisteredServicesByClass() {
- Map<Class<?>, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServicesByClass(OrderedSPIFixture.class, Collections.singleton(FixtureCustomInterfaceImpl.class));
+ Map<Class<?>, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServicesByClass(OrderedSPIFixture.class, Collections.singleton(OrderedInterfaceFixtureImpl.class));
assertThat(actual.size(), is(1));
- assertThat(actual.get(FixtureCustomInterfaceImpl.class), instanceOf(OrderedSPIFixtureImpl.class));
+ assertThat(actual.get(OrderedInterfaceFixtureImpl.class), instanceOf(OrderedSPIFixtureImpl.class));
}
@SuppressWarnings("rawtypes")
@Test
public void assertGetRegisteredServices() {
- FixtureCustomInterfaceImpl key = new FixtureCustomInterfaceImpl();
- Map<FixtureCustomInterfaceImpl, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServices(OrderedSPIFixture.class, Collections.singleton(key));
+ OrderedInterfaceFixtureImpl key = new OrderedInterfaceFixtureImpl();
+ Map<OrderedInterfaceFixtureImpl, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServices(OrderedSPIFixture.class, Collections.singleton(key));
assertThat(actual.size(), is(1));
assertThat(actual.get(key), instanceOf(OrderedSPIFixtureImpl.class));
}
@Test
public void assertGetRegisteredServicesFromCache() {
- FixtureCustomInterface key = new FixtureCustomInterfaceImpl();
+ OrderedInterfaceFixture key = new OrderedInterfaceFixtureImpl();
assertThat(OrderedSPIRegistry.getRegisteredServices(OrderedSPIFixture.class, Collections.singleton(key)),
is(OrderedSPIRegistry.getRegisteredServices(OrderedSPIFixture.class, Collections.singleton(key))));
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/cache/OrderedServicesCacheTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/cache/OrderedServicesCacheTest.java
index f31254e8338..ef1e500bf5f 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/cache/OrderedServicesCacheTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/cache/OrderedServicesCacheTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.spi.type.ordered.cache;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterface;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterfaceImpl;
+import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedInterfaceFixture;
+import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedInterfaceFixtureImpl;
import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedSPIFixture;
import org.apache.shardingsphere.spi.type.ordered.fixture.OrderedSPIFixtureImpl;
import org.junit.After;
@@ -54,19 +54,19 @@ public final class OrderedServicesCacheTest {
@Test
public void assertFindCachedServices() {
- FixtureCustomInterface fixtureCustomInterface = new FixtureCustomInterfaceImpl();
- Collection<FixtureCustomInterface> customInterfaces = Collections.singleton(fixtureCustomInterface);
+ OrderedInterfaceFixture orderedInterfaceFixture = new OrderedInterfaceFixtureImpl();
+ Collection<OrderedInterfaceFixture> customInterfaces = Collections.singleton(orderedInterfaceFixture);
OrderedSPIFixture<?> cacheOrderedSPIFixture = new OrderedSPIFixtureImpl();
- Map<FixtureCustomInterface, OrderedSPIFixture> cachedOrderedServices = new LinkedHashMap<>(customInterfaces.size(), 1);
- cachedOrderedServices.put(fixtureCustomInterface, cacheOrderedSPIFixture);
+ Map<OrderedInterfaceFixture, OrderedSPIFixture<?>> cachedOrderedServices = new LinkedHashMap<>(customInterfaces.size(), 1);
+ cachedOrderedServices.put(orderedInterfaceFixture, cacheOrderedSPIFixture);
OrderedServicesCache.cacheServices(OrderedSPIFixture.class, customInterfaces, cachedOrderedServices);
Optional<Map<?, ?>> actual = OrderedServicesCache.findCachedServices(OrderedSPIFixture.class, customInterfaces);
assertTrue(actual.isPresent());
- assertThat(actual.get().get(fixtureCustomInterface), is(cacheOrderedSPIFixture));
+ assertThat(actual.get().get(orderedInterfaceFixture), is(cacheOrderedSPIFixture));
}
@Test
public void assertNotFindCachedServices() {
- assertFalse(OrderedServicesCache.findCachedServices(OrderedSPIFixture.class, Collections.singleton(new FixtureCustomInterfaceImpl())).isPresent());
+ assertFalse(OrderedServicesCache.findCachedServices(OrderedSPIFixture.class, Collections.singleton(new OrderedInterfaceFixtureImpl())).isPresent());
}
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterface.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixture.java
similarity index 88%
rename from shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterface.java
rename to shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixture.java
index 6118ab931e9..ce4774e1355 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterface.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.fixture;
+package org.apache.shardingsphere.spi.type.ordered.fixture;
-public interface FixtureCustomInterface {
+public interface OrderedInterfaceFixture {
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterfaceImpl.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixtureImpl.java
similarity index 84%
rename from shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterfaceImpl.java
rename to shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixtureImpl.java
index 5b9712af8d6..c856a526230 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/FixtureCustomInterfaceImpl.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedInterfaceFixtureImpl.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.fixture;
+package org.apache.shardingsphere.spi.type.ordered.fixture;
-public final class FixtureCustomInterfaceImpl implements FixtureCustomInterface {
+public final class OrderedInterfaceFixtureImpl implements OrderedInterfaceFixture {
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixture.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixture.java
index dade9356cde..c14ac67b0bc 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixture.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixture.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.spi.type.ordered.fixture;
import org.apache.shardingsphere.spi.annotation.SingletonSPI;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterface;
import org.apache.shardingsphere.spi.type.ordered.OrderedSPI;
@SingletonSPI
-public interface OrderedSPIFixture<T extends FixtureCustomInterface> extends OrderedSPI<T> {
+public interface OrderedSPIFixture<T extends OrderedInterfaceFixture> extends OrderedSPI<T> {
}
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixtureImpl.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixtureImpl.java
index 118d62273fd..4e84ae0cd94 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixtureImpl.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/ordered/fixture/OrderedSPIFixtureImpl.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.spi.type.ordered.fixture;
-import org.apache.shardingsphere.spi.fixture.FixtureCustomInterfaceImpl;
-
-public final class OrderedSPIFixtureImpl implements OrderedSPIFixture<FixtureCustomInterfaceImpl> {
+public final class OrderedSPIFixtureImpl implements OrderedSPIFixture<OrderedInterfaceFixtureImpl> {
@Override
public int getOrder() {
@@ -27,7 +25,7 @@ public final class OrderedSPIFixtureImpl implements OrderedSPIFixture<FixtureCus
}
@Override
- public Class<FixtureCustomInterfaceImpl> getTypeClass() {
- return FixtureCustomInterfaceImpl.class;
+ public Class<OrderedInterfaceFixtureImpl> getTypeClass() {
+ return OrderedInterfaceFixtureImpl.class;
}
}