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 2020/01/08 03:03:21 UTC

[GitHub] [incubator-shardingsphere] ssxlulu opened a new pull request #3894: Use spi for datasources check

ssxlulu opened a new pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894
 
 
   Fixes #3849.
   
   Changes proposed in this pull request:
   - Use spi for datasources check

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on issue #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on issue #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#issuecomment-571946032
 
 
   /run ci

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364062911
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/execute/executor/checker/Checker.java
 ##########
 @@ -0,0 +1,37 @@
+/*
+ * 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.shardingscaling.core.execute.executor.checker;
+
+/**
+ * Checker.
+ *
+ * @author ssxlulu
+ */
+public interface Checker {
 
 Review comment:
   I think `DatasourceChecker` is more readable.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364063757
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/test/java/org/apache/shardingsphere/shardingscaling/core/web/HttpServerHandlerTest.java
 ##########
 @@ -66,31 +66,31 @@ public void setUp() {
 
     @Test
     public void channelReadStartFailed() {
 
 Review comment:
   Sorry, I forgot review that unit test method name should start with `assert`
   For example this test method should change to `assertChannelReadStartFailed()`;

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364063540
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/test/java/org/apache/shardingsphere/shardingscaling/core/web/HttpServerHandlerTest.java
 ##########
 @@ -66,31 +66,31 @@ public void setUp() {
 
     @Test
     public void channelReadStartFailed() {
-        ByteBuf byteBuf = Unpooled.copiedBuffer(GSON.toJson(scalingConfiguration), CharsetUtil.UTF_8);
-        fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/shardingscaling/job/start", byteBuf);
-        httpServerHandler.channelRead0(channelHandlerContext, fullHttpRequest);
-        ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(FullHttpResponse.class);
-        verify(channelHandlerContext).writeAndFlush(argumentCaptor.capture());
-        FullHttpResponse fullHttpResponse = (FullHttpResponse) argumentCaptor.getValue();
-        assertTrue(fullHttpResponse.content().toString(CharsetUtil.UTF_8).contains("Datasources check failed!"));
+//        ByteBuf byteBuf = Unpooled.copiedBuffer(GSON.toJson(scalingConfiguration), CharsetUtil.UTF_8);
+//        fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/shardingscaling/job/start", byteBuf);
+//        httpServerHandler.channelRead0(channelHandlerContext, fullHttpRequest);
+//        ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(FullHttpResponse.class);
+//        verify(channelHandlerContext).writeAndFlush(argumentCaptor.capture());
+//        FullHttpResponse fullHttpResponse = (FullHttpResponse) argumentCaptor.getValue();
+//        assertTrue(fullHttpResponse.content().toString(CharsetUtil.UTF_8).contains("Datasources check failed!"));
 
 Review comment:
   Why comment unit test?
   If there are some reason have to ignore unit test, please use @Ignore annotation with description.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364062781
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/execute/executor/checker/AbstractChecker.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.shardingscaling.core.execute.executor.checker;
+
+import com.zaxxer.hikari.HikariDataSource;
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.apache.shardingsphere.shardingscaling.core.exception.DatasourceCheckFailedException;
+import org.apache.shardingsphere.shardingscaling.core.util.DataSourceFactory;
+
+import java.sql.SQLException;
+
+/**
+ * generic checker implement.
+ *
+ * @author ssxlulu
+ */
+public abstract class AbstractChecker implements Checker {
+
+    @Getter(AccessLevel.PROTECTED)
+    private final DataSourceFactory dataSourceFactory;
+
+    public AbstractChecker(final DataSourceFactory dataSourceFactory) {
+        this.dataSourceFactory = dataSourceFactory;
+    }
+
+    @Override
+    public final void checkConnection() {
+        try {
+            for (HikariDataSource hikariDataSource : dataSourceFactory.getCachedDataSources().values()) {
+                hikariDataSource.getConnection();
+            }
 
 Review comment:
   Why not take the datasources as the input parameter, but get the datasource from the dataSourceFactory?

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364063540
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/test/java/org/apache/shardingsphere/shardingscaling/core/web/HttpServerHandlerTest.java
 ##########
 @@ -66,31 +66,31 @@ public void setUp() {
 
     @Test
     public void channelReadStartFailed() {
-        ByteBuf byteBuf = Unpooled.copiedBuffer(GSON.toJson(scalingConfiguration), CharsetUtil.UTF_8);
-        fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/shardingscaling/job/start", byteBuf);
-        httpServerHandler.channelRead0(channelHandlerContext, fullHttpRequest);
-        ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(FullHttpResponse.class);
-        verify(channelHandlerContext).writeAndFlush(argumentCaptor.capture());
-        FullHttpResponse fullHttpResponse = (FullHttpResponse) argumentCaptor.getValue();
-        assertTrue(fullHttpResponse.content().toString(CharsetUtil.UTF_8).contains("Datasources check failed!"));
+//        ByteBuf byteBuf = Unpooled.copiedBuffer(GSON.toJson(scalingConfiguration), CharsetUtil.UTF_8);
+//        fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/shardingscaling/job/start", byteBuf);
+//        httpServerHandler.channelRead0(channelHandlerContext, fullHttpRequest);
+//        ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(FullHttpResponse.class);
+//        verify(channelHandlerContext).writeAndFlush(argumentCaptor.capture());
+//        FullHttpResponse fullHttpResponse = (FullHttpResponse) argumentCaptor.getValue();
+//        assertTrue(fullHttpResponse.content().toString(CharsetUtil.UTF_8).contains("Datasources check failed!"));
 
 Review comment:
   Why comment unit test?
   If there are some reason have to ignore unit test, please use `@Ignore` annotation with description.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on issue #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on issue #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#issuecomment-571875746
 
 
   /run ci

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion merged pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion merged pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894
 
 
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on issue #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on issue #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#issuecomment-572335911
 
 
   /run ci

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3894: Use spi for datasources check

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3894: Use spi for datasources check
URL: https://github.com/apache/incubator-shardingsphere/pull/3894#discussion_r364062781
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/execute/executor/checker/AbstractChecker.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.shardingscaling.core.execute.executor.checker;
+
+import com.zaxxer.hikari.HikariDataSource;
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.apache.shardingsphere.shardingscaling.core.exception.DatasourceCheckFailedException;
+import org.apache.shardingsphere.shardingscaling.core.util.DataSourceFactory;
+
+import java.sql.SQLException;
+
+/**
+ * generic checker implement.
+ *
+ * @author ssxlulu
+ */
+public abstract class AbstractChecker implements Checker {
+
+    @Getter(AccessLevel.PROTECTED)
+    private final DataSourceFactory dataSourceFactory;
+
+    public AbstractChecker(final DataSourceFactory dataSourceFactory) {
+        this.dataSourceFactory = dataSourceFactory;
+    }
+
+    @Override
+    public final void checkConnection() {
+        try {
+            for (HikariDataSource hikariDataSource : dataSourceFactory.getCachedDataSources().values()) {
+                hikariDataSource.getConnection();
+            }
 
 Review comment:
   Why not input datasources?
   

----------------------------------------------------------------
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


With regards,
Apache Git Services