You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2020/09/14 11:43:58 UTC

[shardingsphere] branch master updated: Refactor ExpectedExceptions

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

menghaoran 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 c8143e6  Refactor ExpectedExceptions
     new b8b5f40  Merge pull request #7444 from terrymanu/dev
c8143e6 is described below

commit c8143e6667e332bcfeee457bf03ae198ea3c26bf
Author: terrymanu <te...@163.com>
AuthorDate: Mon Sep 14 19:39:41 2020 +0800

    Refactor ExpectedExceptions
---
 .../proxy/frontend/exception/ExpectedExceptions.java             | 2 +-
 .../proxy/frontend/exception/ExpectedExceptionsTest.java         | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
index 434e7e8..9055085 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
@@ -50,6 +50,6 @@ public final class ExpectedExceptions {
      * @return is expected exception or not
      */
     public static boolean isExpected(final Class<?> exceptionClass) {
-        return EXCEPTIONS.contains(exceptionClass);
+        return EXCEPTIONS.stream().anyMatch(each -> each.isAssignableFrom(exceptionClass));
     }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
index b2b896d..3d748a1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
@@ -20,10 +20,12 @@ package org.apache.shardingsphere.proxy.frontend.exception;
 import org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.proxy.backend.exception.BackendException;
+import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
 import org.apache.shardingsphere.proxy.backend.text.sctl.exception.ShardingCTLException;
 import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public final class ExpectedExceptionsTest {
@@ -35,5 +37,12 @@ public final class ExpectedExceptionsTest {
         assertTrue(ExpectedExceptions.isExpected(SQLParsingException.class));
         assertTrue(ExpectedExceptions.isExpected(ShardingCTLException.class));
         assertTrue(ExpectedExceptions.isExpected(BackendException.class));
+        assertTrue(ExpectedExceptions.isExpected(NoDatabaseSelectedException.class));
+    }
+    
+    @Test
+    public void assertIsNotExpected() {
+        assertFalse(ExpectedExceptions.isExpected(Exception.class));
+        assertFalse(ExpectedExceptions.isExpected(IllegalArgumentException.class));
     }
 }