This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 73e0b53d95b Add unit tests for CircuitBreakerStatement and
CircuitBreakerPreparedStatement (#37263)
73e0b53d95b is described below
commit 73e0b53d95b5ad622b4dea1512a0dfa71380c3ff
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Dec 3 00:50:47 2025 +0800
Add unit tests for CircuitBreakerStatement and
CircuitBreakerPreparedStatement (#37263)
---
.../CircuitBreakerPreparedStatementTest.java | 336 +++++++++++++++++++++
.../statement/CircuitBreakerStatementTest.java | 244 +++++++++++++++
2 files changed, 580 insertions(+)
diff --git
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerPreparedStatementTest.java
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerPreparedStatementTest.java
new file mode 100644
index 00000000000..14e79d602ea
--- /dev/null
+++
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerPreparedStatementTest.java
@@ -0,0 +1,336 @@
+/*
+ * 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.driver.state.circuit.statement;
+
+import
org.apache.shardingsphere.driver.state.circuit.connection.CircuitBreakerConnection;
+import
org.apache.shardingsphere.driver.state.circuit.resultset.CircuitBreakerResultSet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.ResultSet;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+@SuppressWarnings("resource")
+class CircuitBreakerPreparedStatementTest {
+
+ @Test
+ void assertSetNullWithSqlType() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setNull(1, 0));
+ }
+
+ @Test
+ void assertSetNullWithSqlTypeAndName() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setNull(1, 0, "t"));
+ }
+
+ @Test
+ void assertSetBoolean() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBoolean(1, true));
+ }
+
+ @Test
+ void assertSetByte() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setByte(1, (byte) 1));
+ }
+
+ @Test
+ void assertSetShort() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setShort(1, (short) 1));
+ }
+
+ @Test
+ void assertSetInt() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setInt(1, 1));
+ }
+
+ @Test
+ void assertSetLong() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setLong(1, 1L));
+ }
+
+ @Test
+ void assertSetFloat() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setFloat(1, 1F));
+ }
+
+ @Test
+ void assertSetDouble() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setDouble(1, 1D));
+ }
+
+ @Test
+ void assertSetBigDecimal() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBigDecimal(1, BigDecimal.ONE));
+ }
+
+ @Test
+ void assertSetString() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setString(1, "x"));
+ }
+
+ @Test
+ void assertSetBytes() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBytes(1, new byte[]{1}));
+ }
+
+ @Test
+ void assertSetDate() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setDate(1, new Date(1L)));
+ }
+
+ @Test
+ void assertSetDateWithCalendar() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setDate(1, new Date(1L),
Calendar.getInstance()));
+ }
+
+ @Test
+ void assertSetTime() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setTime(1, new Time(1L)));
+ }
+
+ @Test
+ void assertSetTimeWithCalendar() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setTime(1, new Time(1L),
Calendar.getInstance()));
+ }
+
+ @Test
+ void assertSetTimestamp() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setTimestamp(1, new Timestamp(1L)));
+ }
+
+ @Test
+ void assertSetTimestampWithCalendar() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setTimestamp(1, new Timestamp(1L),
Calendar.getInstance()));
+ }
+
+ @Test
+ void assertSetAsciiStreamWithLength() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setAsciiStream(1, new
ByteArrayInputStream(new byte[0]), 0));
+ }
+
+ @Test
+ void assertSetAsciiStream() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setAsciiStream(1, new
ByteArrayInputStream(new byte[0])));
+ }
+
+ @Test
+ void assertSetAsciiStreamWithLong() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setAsciiStream(1, new
ByteArrayInputStream(new byte[0]), 0L));
+ }
+
+ @Test
+ void assertSetUnicodeStream() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setUnicodeStream(1, new
ByteArrayInputStream(new byte[0]), 0));
+ }
+
+ @Test
+ void assertSetBinaryStreamWithLength() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBinaryStream(1, new
ByteArrayInputStream(new byte[0]), 0));
+ }
+
+ @Test
+ void assertSetBinaryStreamWithLong() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBinaryStream(1, new
ByteArrayInputStream(new byte[0]), 0L));
+ }
+
+ @Test
+ void assertSetBinaryStream() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBinaryStream(1, new
ByteArrayInputStream(new byte[0])));
+ }
+
+ @Test
+ void assertClearParameters() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().clearParameters());
+ }
+
+ @Test
+ void assertSetObject() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setObject(1, new Object()));
+ }
+
+ @Test
+ void assertSetObjectWithTargetSqlType() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setObject(1, new Object(), 0));
+ }
+
+ @Test
+ void assertSetObjectWithScale() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setObject(1, new Object(), 0, 0));
+ }
+
+ @Test
+ void assertExecute() {
+ assertThat(new CircuitBreakerPreparedStatement().execute(), is(false));
+ }
+
+ @Test
+ void assertClearBatch() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().clearBatch());
+ }
+
+ @Test
+ void assertAddBatch() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().addBatch());
+ }
+
+ @Test
+ void assertSetCharacterStreamWithLength() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setCharacterStream(1, new StringReader(""),
0));
+ }
+
+ @Test
+ void assertSetCharacterStreamWithLong() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setCharacterStream(1, new StringReader(""),
0L));
+ }
+
+ @Test
+ void assertSetCharacterStream() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setCharacterStream(1, new StringReader("")));
+ }
+
+ @Test
+ void assertSetBlob() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBlob(1, (Blob) null));
+ }
+
+ @Test
+ void assertSetBlobWithLength() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBlob(1, new ByteArrayInputStream(new
byte[0]), 0L));
+ }
+
+ @Test
+ void assertSetBlobWithStream() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setBlob(1, new ByteArrayInputStream(new
byte[0])));
+ }
+
+ @Test
+ void assertSetClob() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setClob(1, (Clob) null));
+ }
+
+ @Test
+ void assertSetClobWithLength() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setClob(1, new StringReader(""), 0L));
+ }
+
+ @Test
+ void assertSetClobWithReader() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setClob(1, new StringReader("")));
+ }
+
+ @Test
+ void assertSetArray() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setArray(1, null));
+ }
+
+ @Test
+ void assertSetURL() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setURL(1, new URL("http://localhost")));
+ }
+
+ @Test
+ void assertGetParameterMetaData() {
+ Assertions.assertNull(new
CircuitBreakerPreparedStatement().getParameterMetaData());
+ }
+
+ @Test
+ void assertSetSQLXML() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().setSQLXML(1, null));
+ }
+
+ @Test
+ void assertExecuteBatch() {
+ assertThat(new CircuitBreakerPreparedStatement().executeBatch(),
is(new int[]{-1}));
+ }
+
+ @Test
+ void assertGetConnection() {
+ assertThat(new CircuitBreakerPreparedStatement().getConnection(),
instanceOf(CircuitBreakerConnection.class));
+ }
+
+ @Test
+ void assertGetGeneratedKeys() {
+ assertThat(new CircuitBreakerPreparedStatement().getGeneratedKeys(),
instanceOf(CircuitBreakerResultSet.class));
+ }
+
+ @Test
+ void assertGetResultSetHoldability() {
+ assertThat(new
CircuitBreakerPreparedStatement().getResultSetHoldability(), is(0));
+ }
+
+ @Test
+ void assertGetResultSet() {
+ assertThat(new CircuitBreakerPreparedStatement().getResultSet(),
instanceOf(CircuitBreakerResultSet.class));
+ }
+
+ @Test
+ void assertGetResultSetConcurrency() {
+ Assertions.assertEquals(ResultSet.CONCUR_READ_ONLY, new
CircuitBreakerPreparedStatement().getResultSetConcurrency());
+ }
+
+ @Test
+ void assertGetResultSetType() {
+ Assertions.assertEquals(ResultSet.TYPE_FORWARD_ONLY, new
CircuitBreakerPreparedStatement().getResultSetType());
+ }
+
+ @Test
+ void assertIsAccumulate() {
+ assertThat(new CircuitBreakerPreparedStatement().isAccumulate(),
is(false));
+ }
+
+ @Test
+ void assertGetRoutedStatements() {
+ assertThat(new
CircuitBreakerPreparedStatement().getRoutedStatements(),
is(Collections.emptyList()));
+ }
+
+ @Test
+ void assertGetStatementManager() {
+ assertThat(new
CircuitBreakerPreparedStatement().getStatementManager(), is(nullValue()));
+ }
+
+ @Test
+ void assertExecuteQuery() {
+ assertThat(new CircuitBreakerPreparedStatement().executeQuery(),
instanceOf(CircuitBreakerResultSet.class));
+ }
+
+ @Test
+ void assertExecuteUpdate() {
+ assertThat(new CircuitBreakerPreparedStatement().executeUpdate(),
is(-1));
+ }
+
+ @Test
+ void assertCloseExecutor() {
+ assertDoesNotThrow(() -> new
CircuitBreakerPreparedStatement().closeExecutor());
+ }
+}
diff --git
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerStatementTest.java
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerStatementTest.java
new file mode 100644
index 00000000000..1345c9b389c
--- /dev/null
+++
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/circuit/statement/CircuitBreakerStatementTest.java
@@ -0,0 +1,244 @@
+/*
+ * 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.driver.state.circuit.statement;
+
+import
org.apache.shardingsphere.driver.state.circuit.connection.CircuitBreakerConnection;
+import org.junit.jupiter.api.Test;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+@SuppressWarnings("resource")
+class CircuitBreakerStatementTest {
+
+ @Test
+ void assertGetMaxFieldSize() {
+ assertThat(new CircuitBreakerStatement().getMaxFieldSize(), is(0));
+ }
+
+ @Test
+ void assertSetMaxFieldSize() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setMaxFieldSize(1));
+ }
+
+ @Test
+ void assertGetMaxRows() {
+ assertThat(new CircuitBreakerStatement().getMaxRows(), is(0));
+ }
+
+ @Test
+ void assertSetMaxRows() {
+ assertDoesNotThrow(() -> new CircuitBreakerStatement().setMaxRows(1));
+ }
+
+ @Test
+ void assertSetEscapeProcessing() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setEscapeProcessing(true));
+ }
+
+ @Test
+ void assertGetQueryTimeout() {
+ assertThat(new CircuitBreakerStatement().getQueryTimeout(), is(0));
+ }
+
+ @Test
+ void assertSetQueryTimeout() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setQueryTimeout(1));
+ }
+
+ @Test
+ void assertCancel() {
+ assertDoesNotThrow(() -> new CircuitBreakerStatement().cancel());
+ }
+
+ @Test
+ void assertGetWarnings() {
+ assertThat(new CircuitBreakerStatement().getWarnings(),
is(nullValue()));
+ }
+
+ @Test
+ void assertClearWarnings() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().clearWarnings());
+ }
+
+ @Test
+ void assertSetCursorName() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setCursorName("c"));
+ }
+
+ @Test
+ void assertGetResultSet() {
+ assertThat(new CircuitBreakerStatement().getResultSet(),
is(nullValue()));
+ }
+
+ @Test
+ void assertGetUpdateCount() {
+ assertThat(new CircuitBreakerStatement().getUpdateCount(), is(0));
+ }
+
+ @Test
+ void assertSetFetchSize() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setFetchSize(10));
+ }
+
+ @Test
+ void assertGetFetchSize() {
+ assertThat(new CircuitBreakerStatement().getFetchSize(), is(0));
+ }
+
+ @Test
+ void assertGetFetchDirection() {
+ assertThat(new CircuitBreakerStatement().getFetchDirection(),
is(ResultSet.FETCH_FORWARD));
+ }
+
+ @Test
+ void assertSetFetchDirection() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setFetchDirection(ResultSet.FETCH_FORWARD));
+ }
+
+ @Test
+ void assertGetResultSetConcurrency() {
+ assertThat(new CircuitBreakerStatement().getResultSetConcurrency(),
is(ResultSet.CONCUR_READ_ONLY));
+ }
+
+ @Test
+ void assertGetResultSetType() {
+ assertThat(new CircuitBreakerStatement().getResultSetType(),
is(ResultSet.TYPE_FORWARD_ONLY));
+ }
+
+ @Test
+ void assertAddBatch() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().addBatch("sql"));
+ }
+
+ @Test
+ void assertClearBatch() {
+ assertDoesNotThrow(() -> new CircuitBreakerStatement().clearBatch());
+ }
+
+ @Test
+ void assertExecuteBatch() {
+ assertThat(new CircuitBreakerStatement().executeBatch(), is(new
int[0]));
+ }
+
+ @Test
+ void assertGetConnection() {
+ assertThat(new CircuitBreakerStatement().getConnection(),
instanceOf(CircuitBreakerConnection.class));
+ }
+
+ @Test
+ void assertGetMoreResultsWithoutParam() {
+ assertThat(new CircuitBreakerStatement().getMoreResults(), is(false));
+ }
+
+ @Test
+ void assertGetMoreResultsWithParam() {
+ assertThat(new
CircuitBreakerStatement().getMoreResults(Statement.CLOSE_CURRENT_RESULT),
is(false));
+ }
+
+ @Test
+ void assertGetGeneratedKeys() {
+ assertThat(new CircuitBreakerStatement().getGeneratedKeys(),
is(nullValue()));
+ }
+
+ @Test
+ void assertExecuteQuery() {
+ assertThat(new CircuitBreakerStatement().executeQuery("sql"),
is(nullValue()));
+ }
+
+ @Test
+ void assertExecuteUpdate() {
+ assertThat(new CircuitBreakerStatement().executeUpdate("sql"), is(0));
+ }
+
+ @Test
+ void assertExecuteUpdateWithAutoGeneratedKeys() {
+ assertThat(new CircuitBreakerStatement().executeUpdate("sql",
Statement.NO_GENERATED_KEYS), is(0));
+ }
+
+ @Test
+ void assertExecuteUpdateWithColumnIndexes() {
+ assertThat(new CircuitBreakerStatement().executeUpdate("sql", new
int[]{0}), is(0));
+ }
+
+ @Test
+ void assertExecuteUpdateWithColumnNames() {
+ assertThat(new CircuitBreakerStatement().executeUpdate("sql", new
String[]{""}), is(0));
+ }
+
+ @Test
+ void assertExecute() {
+ assertThat(new CircuitBreakerStatement().execute("sql"), is(false));
+ }
+
+ @Test
+ void assertExecuteWithAutoGeneratedKeys() {
+ assertThat(new CircuitBreakerStatement().execute("sql",
Statement.NO_GENERATED_KEYS), is(false));
+ }
+
+ @Test
+ void assertExecuteWithColumnIndexes() {
+ assertThat(new CircuitBreakerStatement().execute("sql", new int[]{0}),
is(false));
+ }
+
+ @Test
+ void assertExecuteWithColumnNames() {
+ assertThat(new CircuitBreakerStatement().execute("sql", new
String[]{""}), is(false));
+ }
+
+ @Test
+ void assertGetResultSetHoldability() {
+ assertThat(new CircuitBreakerStatement().getResultSetHoldability(),
is(0));
+ }
+
+ @Test
+ void assertIsClosed() {
+ assertThat(new CircuitBreakerStatement().isClosed(), is(false));
+ }
+
+ @Test
+ void assertSetPoolable() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().setPoolable(true));
+ }
+
+ @Test
+ void assertIsPoolable() {
+ assertThat(new CircuitBreakerStatement().isPoolable(), is(false));
+ }
+
+ @Test
+ void assertCloseOnCompletion() {
+ assertDoesNotThrow(() -> new
CircuitBreakerStatement().closeOnCompletion());
+ }
+
+ @Test
+ void assertIsCloseOnCompletion() {
+ assertThat(new CircuitBreakerStatement().isCloseOnCompletion(),
is(false));
+ }
+
+ @Test
+ void assertClose() {
+ assertDoesNotThrow(() -> new CircuitBreakerStatement().close());
+ }
+}