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 2021/03/26 06:00:29 UTC
[shardingsphere] branch master updated: Add test cases for
OrderedServicesCache #9789 (#9791)
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 <40...@users.noreply.github.com>
AuthorDate: Fri Mar 26 13:59:58 2021 +0800
Add test cases for OrderedServicesCache #9789 (#9791)
Co-authored-by: wordkuailei <wo...@163.com>
---
.../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));
+ }
+ }
+
+}