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 fdd8c5b Add test cases for OrderedServicesCache #9789 (#9791)
fdd8c5b is described below
commit fdd8c5bd22bdbe5d0bb7522e32c6e3d2ed190820
Author: wordKuaiLei <[email protected]>
AuthorDate: Fri Mar 26 13:59:58 2021 +0800
Add test cases for OrderedServicesCache #9789 (#9791)
Co-authored-by: wordkuailei <[email protected]>
---
.../ordered/cache/OrderedServicesCacheTest.java | 60 ++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/cache/OrderedServicesCacheTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/cache/OrderedServicesCacheTest.java
new file mode 100755
index 0000000..0299411
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/cache/OrderedServicesCacheTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.ordered.cache;
+
+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 java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class OrderedServicesCacheTest {
+
+ @Before
+ public void init() {
+ ShardingSphereServiceLoader.register(OrderedSPIFixture.class);
+ }
+
+ @Test
+ public void assertFindCachedServices() {
+ Collection<FixtureCustomInterface> types = new LinkedList<>();
+ types.add(new FixtureCustomInterfaceImpl());
+ Collection<OrderedSPIFixture> registeredServices =
ShardingSphereServiceLoader.getSingletonServiceInstances(OrderedSPIFixture.class);
+ Map<FixtureCustomInterface, OrderedSPIFixture> services = new
LinkedHashMap<>(registeredServices.size(), 1);
+ for (OrderedSPIFixture each : registeredServices) {
+ types.stream().filter(type -> each.getTypeClass() ==
type.getClass()).forEach(type -> services.put(type, each));
+ }
+ OrderedServicesCache.cacheServices(types, OrderedSPIFixture.class,
services);
+ Optional<CachedOrderedServices> cachedServices =
OrderedServicesCache.findCachedServices(types, OrderedSPIFixture.class);
+ if (cachedServices.isPresent()) {
+ assertThat(cachedServices.get().getTypes().size(), is(1));
+ assertThat(cachedServices.get().getServices().size(), is(1));
+ }
+ }
+
+}