You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/10/11 01:39:16 UTC

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3218: improved coverage for package of proxy

KomachiSion commented on a change in pull request #3218: improved coverage for package of proxy
URL: https://github.com/apache/incubator-shardingsphere/pull/3218#discussion_r333798223
 
 

 ##########
 File path: sharding-proxy/sharding-proxy-backend/src/test/java/org/apache/shardingsphere/shardingproxy/backend/communication/jdbc/execute/callback/ProxyJDBCExecutePrepareCallbackTest.java
 ##########
 @@ -0,0 +1,74 @@
+/*
+ * 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.shardingproxy.backend.communication.jdbc.execute.callback;
+
+import org.apache.shardingsphere.core.constant.ConnectionMode;
+import org.apache.shardingsphere.core.execute.StatementExecuteUnit;
+import org.apache.shardingsphere.core.route.RouteUnit;
+import org.apache.shardingsphere.core.route.SQLUnit;
+import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.wrapper.JDBCExecutorWrapper;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ProxyJDBCExecutePrepareCallbackTest {
+    
+    @Test
+    public void assertGetConnections() throws SQLException {
+        BackendConnection backendConnection = mock(BackendConnection.class);
+        List<Connection> connections = Collections.emptyList();
+        when(backendConnection.getConnections((ConnectionMode) any(), anyString(), anyInt())).thenReturn(connections);
+        ProxyJDBCExecutePrepareCallback proxyJDBCExecutePrepareCallback = new ProxyJDBCExecutePrepareCallback(backendConnection, mock(JDBCExecutorWrapper.class), false);
+        assertThat(proxyJDBCExecutePrepareCallback.getConnections(null, null, 1), is(connections));
+    }
+    
+    @Test
+    public void assertCreateStatementExecuteUnitWhenNotMemoryStrictly() throws SQLException {
+        JDBCExecutorWrapper jdbcExecutorWrapper = mock(JDBCExecutorWrapper.class);
+        when(jdbcExecutorWrapper.createStatement((Connection) any(), (SQLUnit) any(), anyBoolean())).thenReturn(mock(Statement.class));
+        ProxyJDBCExecutePrepareCallback proxyJDBCExecutePrepareCallback = new ProxyJDBCExecutePrepareCallback(mock(BackendConnection.class), jdbcExecutorWrapper, false);
+        RouteUnit routeUnit = mock(RouteUnit.class);
+        when(routeUnit.getSqlUnit()).thenReturn(mock(SQLUnit.class));
+        assertThat(proxyJDBCExecutePrepareCallback.createStatementExecuteUnit(null, routeUnit, ConnectionMode.CONNECTION_STRICTLY), instanceOf(StatementExecuteUnit.class));
+    }
+    
+    @Test
+    public void assertCreateStatementExecuteUnitWhenMemoryStrictly() throws SQLException {
+        JDBCExecutorWrapper jdbcExecutorWrapper = mock(JDBCExecutorWrapper.class);
+        when(jdbcExecutorWrapper.createStatement((Connection) any(), (SQLUnit) any(), anyBoolean())).thenReturn(mock(Statement.class));
+        ProxyJDBCExecutePrepareCallback proxyJDBCExecutePrepareCallback = new ProxyJDBCExecutePrepareCallback(mock(BackendConnection.class), jdbcExecutorWrapper, false);
+        RouteUnit routeUnit = mock(RouteUnit.class);
+        when(routeUnit.getSqlUnit()).thenReturn(mock(SQLUnit.class));
+        assertThat(proxyJDBCExecutePrepareCallback.createStatementExecuteUnit(null, routeUnit, ConnectionMode.MEMORY_STRICTLY), instanceOf(StatementExecuteUnit.class));
+    }
+}
 
 Review comment:
   Files should be end with a empty line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services