ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [40/50] [abbrv] ignite git commit: IGNITE-5275: Implemented SqlConnectorConfiguration. Deprecated OdbcConfiguration. This closes #2080.
Date Tue, 06 Jun 2017 08:59:58 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/sql/SqlConnectorConfigurationValidationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/sql/SqlConnectorConfigurationValidationSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/sql/SqlConnectorConfigurationValidationSelfTest.java
new file mode 100644
index 0000000..dedc5fd
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/sql/SqlConnectorConfigurationValidationSelfTest.java
@@ -0,0 +1,245 @@
+/*
+ * 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.ignite.internal.processors.sql;
+
+import junit.framework.TestCase;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConnectorConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ODBC configuration validation tests.
+ */
+public class SqlConnectorConfigurationValidationSelfTest extends GridCommonAbstractTest {
+    /** Node index generator. */
+    private static final AtomicInteger NODE_IDX_GEN = new AtomicInteger();
+
+    /** Cache name. */
+    private static final String CACHE_NAME = "CACHE";
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        Class.forName("org.apache.ignite.IgniteJdbcThinDriver");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Test host.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDefault() throws Exception {
+        check(new SqlConnectorConfiguration(), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+    }
+
+    /**
+     * Test host.
+     *
+     * @throws Exception If failed.
+     */
+    public void testHost() throws Exception {
+        check(new SqlConnectorConfiguration().setHost("126.0.0.1"), false);
+
+        check(new SqlConnectorConfiguration().setHost("127.0.0.1"), true);
+        assertJdbc("127.0.0.1", SqlConnectorConfiguration.DFLT_PORT);
+
+        check(new SqlConnectorConfiguration().setHost("0.0.0.0"), true);
+        assertJdbc("0.0.0.0", SqlConnectorConfiguration.DFLT_PORT + 1);
+
+    }
+
+    /**
+     * Test port.
+     *
+     * @throws Exception If failed.
+     */
+    public void testPort() throws Exception {
+        check(new SqlConnectorConfiguration().setPort(-1), false);
+        check(new SqlConnectorConfiguration().setPort(0), false);
+        check(new SqlConnectorConfiguration().setPort(512), false);
+        check(new SqlConnectorConfiguration().setPort(65536), false);
+
+        check(new SqlConnectorConfiguration().setPort(SqlConnectorConfiguration.DFLT_PORT),
true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+
+        check(new SqlConnectorConfiguration().setPort(SqlConnectorConfiguration.DFLT_PORT
+ 200), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT + 200);
+    }
+
+
+    /**
+     * Test port.
+     *
+     * @throws Exception If failed.
+     */
+    public void testPortRange() throws Exception {
+        check(new SqlConnectorConfiguration().setPortRange(-1), false);
+
+        check(new SqlConnectorConfiguration().setPortRange(0), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+
+        check(new SqlConnectorConfiguration().setPortRange(10), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT + 1);
+    }
+
+    /**
+     * Test socket buffers.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSocketBuffers() throws Exception {
+        check(new SqlConnectorConfiguration().setSocketSendBufferSize(-4 * 1024), false);
+        check(new SqlConnectorConfiguration().setSocketReceiveBufferSize(-4 * 1024), false);
+
+        check(new SqlConnectorConfiguration().setSocketSendBufferSize(4 * 1024), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+
+        check(new SqlConnectorConfiguration().setSocketReceiveBufferSize(4 * 1024), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT + 1);
+    }
+
+    /**
+     * Test max open cursors per connection.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMaxOpenCusrorsPerConnection() throws Exception {
+        check(new SqlConnectorConfiguration().setMaxOpenCursorsPerConnection(-1), false);
+
+        check(new SqlConnectorConfiguration().setMaxOpenCursorsPerConnection(0), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+
+        check(new SqlConnectorConfiguration().setMaxOpenCursorsPerConnection(100), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT + 1);
+    }
+
+    /**
+     * Test thread pool size.
+     *
+     * @throws Exception If failed.
+     */
+    public void testThreadPoolSize() throws Exception {
+        check(new SqlConnectorConfiguration().setThreadPoolSize(0), false);
+        check(new SqlConnectorConfiguration().setThreadPoolSize(-1), false);
+
+        check(new SqlConnectorConfiguration().setThreadPoolSize(4), true);
+        assertJdbc(null, SqlConnectorConfiguration.DFLT_PORT);
+    }
+
+    /**
+     * Perform check.
+     *
+     * @param sqlCfg SQL configuration.
+     * @param success Success flag. * @throws Exception If failed.
+     */
+    @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "unchecked"})
+    private void check(SqlConnectorConfiguration sqlCfg, boolean success) throws Exception
{
+        final IgniteConfiguration cfg = super.getConfiguration();
+
+        cfg.setIgniteInstanceName(SqlConnectorConfigurationValidationSelfTest.class.getName()
+ "-" +
+            NODE_IDX_GEN.incrementAndGet());
+
+        cfg.setLocalHost("127.0.0.1");
+        cfg.setSqlConnectorConfiguration(sqlCfg);
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
+        spi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        cfg.setDiscoverySpi(spi);
+
+        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME)
+            .setIndexedTypes(SqlConnectorKey.class, SqlConnectorValue.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        if (success)
+            startGrid(cfg.getIgniteInstanceName(), cfg);
+        else {
+            GridTestUtils.assertThrows(log, new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    startGrid(cfg.getIgniteInstanceName(), cfg);
+
+                    return null;
+                }
+            }, IgniteException.class, null);
+        }
+    }
+
+    /**
+     * Make sure that JDBC connection is possible at the given host and port.
+     *
+     * @param host Host.
+     * @param port Port.
+     * @throws Exception If failed.
+     */
+    private void assertJdbc(@Nullable String host, int port) throws Exception {
+        if (host == null)
+            host = "127.0.0.1";
+
+        String connStr = "jdbc:ignite:thin://" + host + ":" + port;
+
+        try (Connection conn = DriverManager.getConnection(connStr)) {
+            conn.setSchema(CACHE_NAME);
+
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery("SELECT 1");
+
+                assertTrue(rs.next());
+
+                TestCase.assertEquals(1, rs.getInt(1));
+            }
+        }
+    }
+
+    /**
+     * Key class.
+     */
+    private static class SqlConnectorKey {
+        @QuerySqlField
+        public int key;
+    }
+
+    /**
+     * Value class.
+     */
+    private static class SqlConnectorValue {
+        @QuerySqlField
+        public int val;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index fb6a86b..0d18517 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -122,6 +122,7 @@ import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest
 import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
 import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryDistributedJoinsTest;
 import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest;
+import org.apache.ignite.internal.processors.sql.SqlConnectorConfigurationValidationSelfTest;
 import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest;
 import org.apache.ignite.testframework.IgniteTestSuite;
 
@@ -136,6 +137,8 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
     public static TestSuite suite() throws Exception {
         IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite");
 
+        suite.addTestSuite(SqlConnectorConfigurationValidationSelfTest.class);
+
         suite.addTestSuite(SqlSchemaSelfTest.class);
 
         // Misc tests.

http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml b/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
index e19075e..4780f38 100644
--- a/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
+++ b/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
@@ -26,12 +26,6 @@
         http://www.springframework.org/schema/util
         http://www.springframework.org/schema/util/spring-util.xsd">
     <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-
-        <!-- Enabling ODBC. -->
-        <property name="odbcConfiguration">
-            <bean class="org.apache.ignite.configuration.OdbcConfiguration"></bean>
-        </property>
-
         <property name="cacheConfiguration">
             <list>
                 <bean class="org.apache.ignite.configuration.CacheConfiguration">

http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/platforms/cpp/odbc-test/config/queries-test-default.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/config/queries-test-default.xml b/modules/platforms/cpp/odbc-test/config/queries-test-default.xml
index c157695..2e7f374 100644
--- a/modules/platforms/cpp/odbc-test/config/queries-test-default.xml
+++ b/modules/platforms/cpp/odbc-test/config/queries-test-default.xml
@@ -28,10 +28,11 @@
     <import resource="queries-default.xml"/>
 
     <bean abstract="true" id="queries.cfg" parent="ignite.cfg">
-        <!-- Enabling ODBC. -->
-        <property name="odbcConfiguration">
-            <bean class="org.apache.ignite.configuration.OdbcConfiguration">
-                <property name="endpointAddress" value="127.0.0.1:11110"/>
+        <property name="sqlConnectorConfiguration">
+            <bean class="org.apache.ignite.configuration.SqlConnectorConfiguration">
+                <property name="host" value="127.0.0.1"/>
+                <property name="port" value="11110"/>
+                <property name="portRange" value="0"/>
             </bean>
         </property>
     </bean>

http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/platforms/cpp/odbc-test/config/queries-test-noodbc-32.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/config/queries-test-noodbc-32.xml b/modules/platforms/cpp/odbc-test/config/queries-test-noodbc-32.xml
index 01cae20..568f685 100644
--- a/modules/platforms/cpp/odbc-test/config/queries-test-noodbc-32.xml
+++ b/modules/platforms/cpp/odbc-test/config/queries-test-noodbc-32.xml
@@ -28,6 +28,10 @@
     <import resource="queries-default.xml"/>
 
     <bean parent="ignite.cfg">
+        <property name="sqlConnectorConfiguration">
+            <null/>
+        </property>
+
         <property name="memoryConfiguration">
             <bean class="org.apache.ignite.configuration.MemoryConfiguration">
                 <property name="systemCacheInitialSize" value="#{40 * 1024 * 1024}"/>

http://git-wip-us.apache.org/repos/asf/ignite/blob/776cc6e7/modules/platforms/cpp/odbc-test/config/queries-test-noodbc.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/config/queries-test-noodbc.xml b/modules/platforms/cpp/odbc-test/config/queries-test-noodbc.xml
index b21287f..5cc6044 100644
--- a/modules/platforms/cpp/odbc-test/config/queries-test-noodbc.xml
+++ b/modules/platforms/cpp/odbc-test/config/queries-test-noodbc.xml
@@ -27,5 +27,9 @@
     <!-- Imports no-ODBC Ignite configuration -->
     <import resource="queries-default.xml"/>
 
-    <bean parent="ignite.cfg"/>
+    <bean parent="ignite.cfg">
+        <property name="sqlConnectorConfiguration">
+            <null/>
+        </property>
+    </bean>
 </beans>


Mime
View raw message