This is an automated email from the ASF dual-hosted git repository.

panjuan 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 f9d2f8ecd19 Remove useless ShardingSphereUsers (#17879)
f9d2f8ecd19 is described below

commit f9d2f8ecd19d23b70666867285b2c4ac6cfa5b0c
Author: Liang Zhang <[email protected]>
AuthorDate: Mon May 23 18:06:59 2022 +0800

    Remove useless ShardingSphereUsers (#17879)
    
    * Move CachedDatabaseMetaData to jdbc module
    
    * Remove useless ShardingSphereUsers
---
 .../infra/metadata/user/ShardingSphereUsers.java   | 44 ----------------------
 .../metadata/user/ShardingSphereUsersTest.java     | 44 ----------------------
 .../swapper/YamlProxyConfigurationSwapperTest.java | 18 ++++-----
 3 files changed, 7 insertions(+), 99 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsers.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsers.java
deleted file mode 100644
index 32f96d09d01..00000000000
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsers.java
+++ /dev/null
@@ -1,44 +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.infra.metadata.user;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * ShardingSphere users.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ShardingSphereUsers {
-    
-    private final Collection<ShardingSphereUser> users;
-    
-    /**
-     * Find user.
-     *
-     * @param grantee grantee
-     * @return found user
-     */
-    public Optional<ShardingSphereUser> findUser(final Grantee grantee) {
-        return users.stream().filter(each -> 
each.getGrantee().equals(grantee)).findFirst();
-    }
-}
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
deleted file mode 100644
index a3fb54626c1..00000000000
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
+++ /dev/null
@@ -1,44 +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.infra.metadata.user;
-
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShardingSphereUsersTest {
-    
-    @Test
-    public void assertFindUser() {
-        ShardingSphereUser shardingSphereUser = mock(ShardingSphereUser.class);
-        Grantee testGrantee = mock(Grantee.class);
-        when(shardingSphereUser.getGrantee()).thenReturn(testGrantee);
-        ShardingSphereUsers actual = new 
ShardingSphereUsers(Collections.singleton(shardingSphereUser));
-        assertTrue(actual.findUser(testGrantee).isPresent());
-        assertThat(actual.findUser(testGrantee).get(), is(shardingSphereUser));
-        Grantee notExistGrantee = mock(Grantee.class);
-        assertFalse(actual.findUser(notExistGrantee).isPresent());
-    }
-}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
index 767cb8a2127..692e45794bc 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
@@ -22,9 +22,6 @@ import 
org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
 import org.apache.shardingsphere.proxy.backend.config.ProxyConfiguration;
 import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
 import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration;
@@ -34,7 +31,6 @@ import org.junit.Test;
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
@@ -51,7 +47,7 @@ public final class YamlProxyConfigurationSwapperTest {
         ProxyConfiguration actual = new 
YamlProxyConfigurationSwapper().swap(yamlProxyConfig);
         assertSchemaDataSources(actual);
         assertSchemaRules(actual);
-        assertAuthority(actual);
+        assertAuthorityRuleConfiguration(actual);
         assertProxyConfigurationProps(actual);
     }
     
@@ -93,15 +89,15 @@ public final class YamlProxyConfigurationSwapperTest {
         assertThat(loadBalancer.getType(), is("ROUND_ROBIN"));
     }
     
-    private void assertAuthority(final ProxyConfiguration proxyConfig) {
-        Optional<ShardingSphereUser> actual = new 
ShardingSphereUsers(findUsers(proxyConfig.getGlobalConfiguration().getRules())).findUser(new
 Grantee("root", ""));
+    private void assertAuthorityRuleConfiguration(final ProxyConfiguration 
proxyConfig) {
+        Optional<AuthorityRuleConfiguration> actual = 
findAuthorityRuleConfiguration(proxyConfig.getGlobalConfiguration().getRules());
         assertTrue(actual.isPresent());
-        assertThat(actual.get().getPassword(), is("123"));
+        assertThat(actual.get().getUsers().size(), is(1));
+        assertThat(actual.get().getUsers().iterator().next().getPassword(), 
is("123"));
     }
     
-    private Collection<ShardingSphereUser> findUsers(final 
Collection<RuleConfiguration> globalRuleConfigs) {
-        return globalRuleConfigs.stream().filter(each -> each instanceof 
AuthorityRuleConfiguration).findFirst()
-                .map(each -> ((AuthorityRuleConfiguration) 
each).getUsers()).orElse(Collections.emptyList());
+    private Optional<AuthorityRuleConfiguration> 
findAuthorityRuleConfiguration(final Collection<RuleConfiguration> 
globalRuleConfigs) {
+        return globalRuleConfigs.stream().filter(each -> each instanceof 
AuthorityRuleConfiguration).findFirst().map(each -> 
((AuthorityRuleConfiguration) each));
     }
     
     private void assertProxyConfigurationProps(final ProxyConfiguration 
proxyConfig) {

Reply via email to