You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2017/03/17 17:04:22 UTC
ignite git commit: IGNITE-4829 Added tests.
Repository: ignite
Updated Branches:
refs/heads/ignite-4829 4121c244f -> dd1f9913e
IGNITE-4829 Added tests.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dd1f9913
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dd1f9913
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dd1f9913
Branch: refs/heads/ignite-4829
Commit: dd1f9913e66c1cbdc666305751718f4dc0230d6b
Parents: 4121c24
Author: Alexey Kuznetsov <ak...@gridgain.com>
Authored: Sat Mar 18 00:04:11 2017 +0700
Committer: Alexey Kuznetsov <ak...@gridgain.com>
Committed: Sat Mar 18 00:04:11 2017 +0700
----------------------------------------------------------------------
modules/clients/pom.xml | 7 +
.../src/test/config/jdbc-config-cache-store.xml | 130 +++++++++++++++++++
.../internal/jdbc2/JdbcSpringSelfTest.java | 71 ++++++++++
.../jdbc/suite/IgniteJdbcDriverTestSuite.java | 1 +
.../testframework/junits/GridAbstractTest.java | 62 +++++++++
5 files changed, 271 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/dd1f9913/modules/clients/pom.xml
----------------------------------------------------------------------
diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml
index 022edb7..195204c 100644
--- a/modules/clients/pom.xml
+++ b/modules/clients/pom.xml
@@ -117,6 +117,13 @@
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${h2.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/ignite/blob/dd1f9913/modules/clients/src/test/config/jdbc-config-cache-store.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/config/jdbc-config-cache-store.xml b/modules/clients/src/test/config/jdbc-config-cache-store.xml
new file mode 100644
index 0000000..e5d8cb1
--- /dev/null
+++ b/modules/clients/src/test/config/jdbc-config-cache-store.xml
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite Spring configuration file.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <!-- Data source beans for POJO store. -->
+ <bean id="dsTest" class="org.h2.jdbcx.JdbcDataSource">
+ <property name="URL" value="jdbc:h2:mem:demo-db"/>
+ <property name="user" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <!-- JDBC driver should force true value -->
+ <property name="clientMode" value="false"/>
+
+ <property name="localHost" value="127.0.0.1"/>
+
+ <property name="marshaller">
+ <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <property name="requireSerializable" value="false"/>
+ </bean>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <value>127.0.0.1:47500..47501</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+
+ <property name="peerClassLoadingEnabled" value="true"/>
+
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="custom-cache"/>
+ </bean>
+
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="TestCacheWithStore"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="ATOMIC"/>
+
+ <property name="cacheStoreFactory">
+ <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
+ <property name="dataSourceBean" value="dsTest"/>
+ <property name="dialect">
+ <bean class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/>
+ </property>
+
+ <property name="types">
+ <list>
+ <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
+ <property name="cacheName" value="TestCacheWithStore"/>
+ <property name="keyType" value="java.lang.Integer"/>
+ <property name="valueType" value="java.lang.String"/>
+ <property name="databaseSchema" value="public"/>
+ <property name="databaseTable" value="city"/>
+
+ <property name="keyFields">
+ <list>
+ <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+ <constructor-arg>
+ <util:constant static-field="java.sql.Types.INTEGER"/>
+ </constructor-arg>
+ <constructor-arg value="id"/>
+ <constructor-arg value="int"/>
+ <constructor-arg value="id"/>
+ </bean>
+ </list>
+ </property>
+
+ <property name="valueFields">
+ <list>
+ <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+ <constructor-arg>
+ <util:constant static-field="java.sql.Types.VARCHAR"/>
+ </constructor-arg>
+ <constructor-arg value="name"/>
+ <constructor-arg value="java.lang.String"/>
+ <constructor-arg value="name"/>
+ </bean>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+ </property>
+
+ <property name="readThrough" value="true"/>
+ <property name="writeThrough" value="true"/>
+ </bean>
+ </list>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/dd1f9913/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
new file mode 100644
index 0000000..1e8e198
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.jdbc2;
+
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.GridTestUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
+
+/**
+ * Test of cluster and JDBC driver with config that contains cache with POJO store and datasource bean.
+ */
+public class JdbcSpringSelfTest extends JdbcConnectionSelfTest {
+ /** Grid count. */
+ private static final int GRID_CNT = 2;
+
+ /** Ignite configuration URL. */
+ private static final String CFG_URL = "modules/clients/src/test/config/jdbc-config-cache-store.xml";
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsWithSpringCtx(GRID_CNT, false, CFG_URL);
+
+ Class.forName("org.apache.ignite.IgniteJdbcDriver");
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Override public void testClientNodeId() throws Exception {
+ IgniteEx client = (IgniteEx) startGridWithSpringCtx(getTestGridName(), true, CFG_URL);
+
+ UUID clientId = client.localNode().id();
+
+ final String url = CFG_URL_PREFIX + "nodeId=" + clientId + '@' + CFG_URL;
+
+ GridTestUtils.assertThrows(
+ log,
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ try (Connection conn = DriverManager.getConnection(url)) {
+ return conn;
+ }
+ }
+ },
+ SQLException.class,
+ "Failed to establish connection with node (is it a server node?): " + clientId
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/dd1f9913/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
index 7395fcb..85e7d90 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
@@ -52,6 +52,7 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
// Ignite client node based driver tests
suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcConnectionSelfTest.class));
+ suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcSpringSelfTest.class));
suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcStatementSelfTest.class));
suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcPreparedStatementSelfTest.class));
suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcResultSetSelfTest.class));
http://git-wip-us.apache.org/repos/asf/ignite/blob/dd1f9913/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index ab4d593..45483b7 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -71,6 +71,7 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.LT;
import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.marshaller.Marshaller;
@@ -803,6 +804,67 @@ public abstract class GridAbstractTest extends TestCase {
}
/**
+ * Starts new grid with given name.
+ *
+ * @param gridName Grid name.
+ * @param client Client mode.
+ * @param cfgUrl Config URL.
+ * @return Started grid.
+ * @throws Exception If failed.
+ */
+ protected Ignite startGridWithSpringCtx(String gridName, boolean client, String cfgUrl) throws Exception {
+ IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap =
+ IgnitionEx.loadConfigurations(cfgUrl);
+
+ IgniteConfiguration cfg = F.first(cfgMap.get1());
+
+ cfg.setGridName(gridName);
+ cfg.setClientMode(client);
+
+ return IgnitionEx.start(cfg, cfgMap.getValue());
+ }
+
+ /**
+ * Starts new node with given index.
+ *
+ * @param idx Index of the node to start.
+ * @param client Client mode.
+ * @param cfgUrl Config URL.
+ * @return Started node.
+ * @throws Exception If failed.
+ */
+ protected Ignite startGridWithSpringCtx(int idx, boolean client, String cfgUrl) throws Exception {
+ return startGridWithSpringCtx(getTestGridName(idx), client, cfgUrl);
+ }
+
+ /**
+ * Start specified amount of nodes.
+ *
+ * @param cnt Nodes count.
+ * @param client Client mode.
+ * @param cfgUrl Config URL.
+ * @return First started node.
+ * @throws Exception If failed.
+ */
+ protected Ignite startGridsWithSpringCtx(int cnt, boolean client, String cfgUrl) throws Exception {
+ assert cnt > 0;
+
+ Ignite ignite = null;
+
+ for (int i = 0; i < cnt; i++)
+ if (ignite == null)
+ ignite = startGridWithSpringCtx(i, client, cfgUrl);
+ else
+ startGridWithSpringCtx(i, client, cfgUrl);
+
+ checkTopology(cnt);
+
+ assert ignite != null;
+
+ return ignite;
+ }
+
+ /**
* Starts new grid at another JVM with given name.
*
* @param gridName Grid name.