Pace2Car commented on code in PR #25036:
URL: https://github.com/apache/shardingsphere/pull/25036#discussion_r1160473507
##########
kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java:
##########
@@ -43,6 +46,8 @@ public final class SQLMatchTrafficAlgorithm implements
SegmentTrafficAlgorithm {
public void init(final Properties props) {
Preconditions.checkArgument(props.containsKey(SQL_PROPS_KEY), "%s
cannot be null.", SQL_PROPS_KEY);
sql = getExactlySQL(props.getProperty(SQL_PROPS_KEY));
+
ShardingSpherePreconditions.checkState(Strings.isNullOrEmpty(String.valueOf(sql)),
+ () -> new
SegmentTrafficAlgorithmInitializationException(SQLMatchTrafficAlgorithm.class.getName(),
"SQL is not null or empty"));
Review Comment:
message `"sql must be not null or empty"` is better.
##########
kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java:
##########
@@ -37,6 +40,8 @@ public final class SQLRegexTrafficAlgorithm implements
SegmentTrafficAlgorithm {
public void init(final Properties props) {
Preconditions.checkArgument(props.containsKey(REGEX_PROPS_KEY), "%s
can not be null.", REGEX_PROPS_KEY);
Review Comment:
as same.
##########
kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java:
##########
@@ -43,6 +46,8 @@ public final class SQLMatchTrafficAlgorithm implements
SegmentTrafficAlgorithm {
public void init(final Properties props) {
Preconditions.checkArgument(props.containsKey(SQL_PROPS_KEY), "%s
cannot be null.", SQL_PROPS_KEY);
Review Comment:
Please use `ShardingSpherePreconditions` to replace `Preconditions`, Thank
you.
##########
kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java:
##########
@@ -59,4 +60,10 @@ void assertMatchWhenNotExistSQLMatch() {
assertFalse(sqlMatchAlgorithm.match(new
SegmentTrafficValue(sqlStatement, "UPDATE `t_order` SET `order_id` = ?;")));
assertFalse(sqlMatchAlgorithm.match(new
SegmentTrafficValue(sqlStatement, "UPDATE `t_order_item` SET `order_id` = ?
WHERE user_id = ?;")));
}
+
+ @Test
+ void assertThrowExceptionWhenWithIllegalInit() {
+ assertThrows(IllegalArgumentException.class, () -> sqlMatchAlgorithm =
(SQLMatchTrafficAlgorithm) TypedSPILoader.getService(TrafficAlgorithm.class,
"SQL_MATCH",
Review Comment:
Please resolve this, and why was the test case for Regex removed?
##########
kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/segment/SegmentTrafficAlgorithmInitializationException.java:
##########
@@ -0,0 +1,11 @@
+package org.apache.shardingsphere.traffic.exception.segment;
+
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.traffic.exception.TrafficException;
+
+public class SegmentTrafficAlgorithmInitializationException extends
TrafficException {
+
+ public SegmentTrafficAlgorithmInitializationException(final String
methodName, final String reason) {
+ super(XOpenSQLState.INVALID_PARAMETER_VALUE, 1, "Segmentation traffic
algorithm `%s` initialization failed, reason is: %s.", methodName, reason);
Review Comment:
use `XOpenSQLState.GENERAL_ERROR` and `98` as errorCode.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]