You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/11/20 07:56:16 UTC
[shardingsphere] branch master updated: Add test cases for
DriverStateContext (#8235)
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 6571594 Add test cases for DriverStateContext (#8235)
6571594 is described below
commit 657159458c1059f1f13980d029d4b39869d762b3
Author: wenweibin <41...@users.noreply.github.com>
AuthorDate: Fri Nov 20 15:55:42 2020 +0800
Add test cases for DriverStateContext (#8235)
* Add test cases for DriverStateContext
* Add Apache License content in DriverStateContextTest
---
.../internal/state/DriverStateContextTest.java | 54 ++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
new file mode 100644
index 0000000..f01416e
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.governance.internal.state;
+
+import org.apache.shardingsphere.driver.governance.internal.circuit.connection.CircuitBreakerConnection;
+import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
+import org.apache.shardingsphere.infra.state.StateContext;
+import org.apache.shardingsphere.infra.state.StateEvent;
+import org.apache.shardingsphere.infra.state.StateType;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.Collections;
+
+public class DriverStateContextTest {
+
+ @Test
+ public void assertGetConnection() {
+ Connection actual1 = DriverStateContext.getConnection(
+ Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)), mock(MetaDataContexts.class), mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
+ assertThat(actual1, instanceOf(ShardingSphereConnection.class));
+ StateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, true));
+ Connection actual2 = DriverStateContext.getConnection(
+ Collections.emptyMap(), mock(MetaDataContexts.class), mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
+ assertThat(actual2, instanceOf(CircuitBreakerConnection.class));
+ StateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, false));
+ Connection actual3 = DriverStateContext.getConnection(
+ Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)), mock(MetaDataContexts.class), mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
+ assertThat(actual3, instanceOf(ShardingSphereConnection.class));
+ }
+}