This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 0ee0ef8a9a2 Add props.exception package (#19762)
0ee0ef8a9a2 is described below
commit 0ee0ef8a9a209e7ae431ab395c747b3d539c2b8d
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 1 23:34:29 2022 +0800
Add props.exception package (#19762)
* Add props.exception package
* Add test case for TypedPropertiesException
* Add test case for TypedPropertiesException
* Add error code
---
.../infra/util/props/TypedProperties.java | 4 +++-
.../infra/util/props/TypedPropertyValue.java | 1 +
.../TypedPropertiesException.java} | 16 +++++++++++-----
.../TypedPropertyValueException.java | 4 +++-
.../infra/util/props/TypedPropertiesTest.java | 3 ++-
.../infra/util/props/TypedPropertyValueTest.java | 1 +
.../exception/TypedPropertiesExceptionTest.java} | 21 +++++++++++----------
.../TypedPropertyValueExceptionTest.java | 2 +-
.../distsql/ral/updatable/SetVariableHandler.java | 2 +-
9 files changed, 34 insertions(+), 20 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedProperties.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedProperties.java
index bf55460e926..7c4ceaed9c7 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedProperties.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedProperties.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.infra.util.props;
import lombok.Getter;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertiesException;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertyValueException;
import java.util.Collection;
import java.util.HashMap;
@@ -54,7 +56,7 @@ public abstract class TypedProperties<E extends Enum<?> &
TypedPropertyKey> {
result.put(each, value);
}
if (!errorMessages.isEmpty()) {
- throw new TypedPropertyException(errorMessages);
+ throw new TypedPropertiesException(errorMessages);
}
return result;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
index 8b4576d0ff4..f918e636e0c 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.util.props;
import lombok.Getter;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertyValueException;
/**
* Typed property value.
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
similarity index 62%
copy from
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
copy to
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
index dfb13aa0936..1b3bd3d997f 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
@@ -15,18 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.props;
+package org.apache.shardingsphere.infra.util.props.exception;
import java.util.Collection;
/**
- * Typed property exception.
+ * Typed properties exception.
*/
-public final class TypedPropertyException extends RuntimeException {
+public final class TypedPropertiesException extends RuntimeException {
private static final long serialVersionUID = -8301410307117564844L;
- public TypedPropertyException(final Collection<String> errorMessages) {
- super(String.join(System.lineSeparator(), errorMessages));
+ private static final int ERROR_CODE = 1;
+
+ public TypedPropertiesException(final Collection<String> errorMessages) {
+ super(createErrorMessage(errorMessages));
+ }
+
+ private static String createErrorMessage(final Collection<String>
errorMessages) {
+ return String.format("PROPS-%05d: %s", ERROR_CODE,
String.join(System.lineSeparator(), errorMessages));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueException.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
similarity index 90%
rename from
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueException.java
rename to
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
index 2c437a29cb1..3f8201c56a5 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueException.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.props;
+package org.apache.shardingsphere.infra.util.props.exception;
+
+import org.apache.shardingsphere.infra.util.props.TypedPropertyKey;
/**
* Typed property value exception.
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
index f65a2eecca7..1be50fd7b81 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.util.props;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertiesException;
import
org.apache.shardingsphere.infra.util.props.fixture.TypedPropertiesFixture;
import
org.apache.shardingsphere.infra.util.props.fixture.TypedPropertyKeyFixture;
import org.junit.Test;
@@ -66,7 +67,7 @@ public final class TypedPropertiesTest {
assertThat(actual.getValue(TypedPropertyKeyFixture.STRING_VALUE),
is("value"));
}
- @Test(expected = TypedPropertyException.class)
+ @Test(expected = TypedPropertiesException.class)
public void assertGetInvalidValue() {
Properties props = new Properties();
props.setProperty(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(),
"test");
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
index b45ff028459..3b7273f9a87 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.util.props;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertyValueException;
import
org.apache.shardingsphere.infra.util.props.fixture.TypedPropertyKeyFixture;
import org.junit.Test;
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesExceptionTest.java
similarity index 63%
rename from
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
rename to
shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesExceptionTest.java
index dfb13aa0936..3342233d5d9 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyException.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesExceptionTest.java
@@ -15,18 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.props;
+package org.apache.shardingsphere.infra.util.props.exception;
-import java.util.Collection;
+import org.junit.Test;
-/**
- * Typed property exception.
- */
-public final class TypedPropertyException extends RuntimeException {
-
- private static final long serialVersionUID = -8301410307117564844L;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class TypedPropertiesExceptionTest {
- public TypedPropertyException(final Collection<String> errorMessages) {
- super(String.join(System.lineSeparator(), errorMessages));
+ @Test
+ public void assertGetMessage() {
+ assertThat(new TypedPropertiesException(Arrays.asList("foo_msg",
"bar_msg")).getMessage(), is("PROPS-00001: foo_msg" + System.lineSeparator() +
"bar_msg"));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueExceptionTest.java
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueExceptionTest.java
similarity index 95%
rename from
shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueExceptionTest.java
rename to
shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueExceptionTest.java
index 340deb4d200..7e56324c7a8 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueExceptionTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueExceptionTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.util.props;
+package org.apache.shardingsphere.infra.util.props.exception;
import
org.apache.shardingsphere.infra.util.props.fixture.TypedPropertyKeyFixture;
import org.junit.Test;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableHandler.java
index 11d9306b447..1e9211ab744 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableHandler.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.SetVaria
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.util.props.TypedPropertyValue;
-import org.apache.shardingsphere.infra.util.props.TypedPropertyValueException;
+import
org.apache.shardingsphere.infra.util.props.exception.TypedPropertyValueException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;