You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/03/30 15:36:53 UTC

[GitHub] [shardingsphere] zhujunxxxxx opened a new pull request #9884: Add testcase for MySQLPrivilageLoader & fix it little bug

zhujunxxxxx opened a new pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884


   Fixes #9852.
   
   Changes proposed in this pull request:
   - add testcase for MySQLPrivilageLoader
   - fix MySQLPrivilageLoader load problem
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-io commented on pull request #9884: Add testcase for MySQLPrivilageLoader & fix it little bug

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884#issuecomment-810396258


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=h1) Report
   > Merging [#9884](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=desc) (b036296) into [master](https://codecov.io/gh/apache/shardingsphere/commit/eb263e578be644ca58bc2e8f2918ae4bd8188330?el=desc) (eb263e5) will **increase** coverage by `0.52%`.
   > The diff coverage is `100.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/9884/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so)](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #9884      +/-   ##
   ============================================
   + Coverage     67.75%   68.27%   +0.52%     
   - Complexity      678      679       +1     
   ============================================
     Files          1675     1675              
     Lines         28137    28138       +1     
     Branches       4991     4991              
   ============================================
   + Hits          19065    19212     +147     
   + Misses         7657     7499     -158     
   - Partials       1415     1427      +12     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...h/builder/loader/dialect/MySQLPrivilegeLoader.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9hdXRoL2J1aWxkZXIvbG9hZGVyL2RpYWxlY3QvTXlTUUxQcml2aWxlZ2VMb2FkZXIuamF2YQ==) | `78.81% <100.00%> (+78.81%)` | `1.00 <0.00> (+1.00)` | |
   | [...ing/core/job/task/incremental/IncrementalTask.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9qb2IvdGFzay9pbmNyZW1lbnRhbC9JbmNyZW1lbnRhbFRhc2suamF2YQ==) | `75.00% <0.00%> (+2.08%)` | `0.00% <0.00%> (ø%)` | |
   | [...scaling/core/job/task/inventory/InventoryTask.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9qb2IvdGFzay9pbnZlbnRvcnkvSW52ZW50b3J5VGFzay5qYXZh) | `75.55% <0.00%> (+6.66%)` | `0.00% <0.00%> (ø%)` | |
   | [...re/scaling/core/executor/engine/ExecuteEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9leGVjdXRvci9lbmdpbmUvRXhlY3V0ZUVuZ2luZS5qYXZh) | `100.00% <0.00%> (+11.11%)` | `0.00% <0.00%> (ø%)` | |
   | [...sphere/scaling/core/job/schedule/JobScheduler.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9qb2Ivc2NoZWR1bGUvSm9iU2NoZWR1bGVyLmphdmE=) | `51.85% <0.00%> (+29.62%)` | `0.00% <0.00%> (ø%)` | |
   | [...a/metadata/auth/model/privilege/PrivilegeType.java](https://codecov.io/gh/apache/shardingsphere/pull/9884/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9hdXRoL21vZGVsL3ByaXZpbGVnZS9Qcml2aWxlZ2VUeXBlLmphdmE=) | `100.00% <0.00%> (+100.00%)` | `0.00% <0.00%> (ø%)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=footer). Last update [eb263e5...b036296](https://codecov.io/gh/apache/shardingsphere/pull/9884?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero commented on a change in pull request #9884: Add testcase for MySQLPrivilageLoader & fix bug

Posted by GitBox <gi...@apache.org>.
tristaZero commented on a change in pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884#discussion_r605686107



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/auth/builder/loader/dialect/MySQLPrivilegeLoader.java
##########
@@ -52,6 +52,7 @@
     @Override
     public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
         Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
+        users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));

Review comment:
       Does that means this user has no privileges in databases, right?

##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/auth/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.auth.builder.loader.dialect;
+
+import org.apache.shardingsphere.infra.metadata.auth.builder.loader.PrivilegeLoader;
+import org.apache.shardingsphere.infra.metadata.auth.model.privilege.PrivilegeType;
+import org.apache.shardingsphere.infra.metadata.auth.model.privilege.ShardingSpherePrivilege;
+import org.apache.shardingsphere.infra.metadata.auth.model.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.sql.DataSource;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MySQLPrivilegeLoaderTest {

Review comment:
       Hi Please define it as a final class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] zhujunxxxxx commented on a change in pull request #9884: Add testcase for MySQLPrivilageLoader & fix bug

Posted by GitBox <gi...@apache.org>.
zhujunxxxxx commented on a change in pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884#discussion_r605729559



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/auth/builder/loader/dialect/MySQLPrivilegeLoader.java
##########
@@ -52,6 +52,7 @@
     @Override
     public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
         Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
+        users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));

Review comment:
       @tristaZero  It simply initializes an empty container to hold the data. I discovered this problem through test cases




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] zhujunxxxxx commented on a change in pull request #9884: Add testcase for MySQLPrivilageLoader & fix bug

Posted by GitBox <gi...@apache.org>.
zhujunxxxxx commented on a change in pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884#discussion_r605728218



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/auth/builder/loader/dialect/MySQLPrivilegeLoader.java
##########
@@ -52,6 +52,7 @@
     @Override
     public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
         Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
+        users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));

Review comment:
       ```
   private void fillGlobalPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
           Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
           if (user.isPresent()) {
               privileges.get(user.get()).getAdministrativePrivilege().getPrivileges().addAll(loadAdministrativePrivileges(resultSet));
               privileges.get(user.get()).getDatabasePrivilege().getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
           }
       }
   ```
   We analyzed this code will find in `getShardingSphereUser` method, if parameter `privileges` is empty it will returns empty, so `user.isPresent()` always false. `fillGlobalPrivilege` can't add any elements to `privileges`.The same problem in `fillSchemaPrivilege` and `fillTablePrivilege`.  but the parameter `privileges` is empty at first.
   
   so I add the below code in the first to avoid this problem.
   ```
   users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));
   ```
   @tristaZero Can you help me see if this is right?
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero merged pull request #9884: Add testcase for MySQLPrivilageLoader & fix bug

Posted by GitBox <gi...@apache.org>.
tristaZero merged pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org