You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/03/08 10:54:02 UTC

[shardingsphere] branch master updated: Add test for cluster state (#24504)

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 d156252e57c Add test for cluster state (#24504)
d156252e57c is described below

commit d156252e57c1d8bfbed398486faea1b734a8fb40
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Wed Mar 8 18:53:48 2023 +0800

    Add test for cluster state (#24504)
---
 .../backend/state/impl/ReadOnlyProxyStateTest.java | 39 ++++++++++++++++++++++
 .../state/impl/UnavailableProxyStateTest.java      | 39 ++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
new file mode 100644
index 00000000000..de9f1020e91
--- /dev/null
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.proxy.backend.state.impl;
+
+import org.apache.shardingsphere.proxy.backend.exception.ReadOnlyException;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+
+public final class ReadOnlyProxyStateTest {
+    
+    @Test
+    public void assertExecuteWithUnsupportedSQL() {
+        assertThrows(ReadOnlyException.class, () -> new ReadOnlyProxyState().check(mock(InsertStatement.class)));
+    }
+    
+    @Test
+    public void executeWithSupportedSQL() {
+        new ReadOnlyProxyState().check(mock(SelectStatement.class));
+    }
+}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
new file mode 100644
index 00000000000..fbf47acee59
--- /dev/null
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.proxy.backend.state.impl;
+
+import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ImportMetaDataStatement;
+import org.apache.shardingsphere.proxy.backend.exception.UnavailableException;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
+import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+
+public final class UnavailableProxyStateTest {
+    
+    @Test
+    public void assertExecuteWithUnsupportedSQL() {
+        assertThrows(UnavailableException.class, () -> new UnavailableProxyState().check(mock(DMLStatement.class)));
+    }
+    
+    @Test
+    public void executeWithSupportedSQL() {
+        new UnavailableProxyState().check(mock(ImportMetaDataStatement.class));
+    }
+}