You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/06/17 10:00:52 UTC

[10/26] incubator-ignite git commit: #ignite-960: Add tests.

#ignite-960: Add tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/fef12fc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/fef12fc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/fef12fc2

Branch: refs/heads/ignite-gg-10425
Commit: fef12fc23a45d1bc4cade87460a76315c7dee6f0
Parents: c9dd891
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 2 12:57:34 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 2 12:57:34 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheProcessor.java    |  3 +-
 .../store/jdbc/CacheJdbcBlobStoreFactory.java   |  6 +-
 modules/spring/src/test/config/node.xml         | 43 ++++++++++++++
 modules/spring/src/test/config/store-cache1.xml | 62 ++++++++++++++++++++
 .../jdbc/CacheJdbcBlobStoreFactorySelfTest.java | 51 ++++++++++++++--
 5 files changed, 154 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fef12fc2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 354172a..a220ae6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -1052,8 +1052,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     {
         assert cfg != null;
 
-        if (cfg.getCacheStoreFactory() != null)
-            ctx.resource().injectGeneric(cfg.getCacheStoreFactory());
+        prepare(cfg, cfg.getCacheStoreFactory(), false);
 
         CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fef12fc2/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java b/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java
index 743e5e8..9d572b6 100644
--- a/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java
+++ b/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java
@@ -63,7 +63,7 @@ import javax.sql.*;
  * <br>
  * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
  */
-public class CacheJdbcBlobStoreFactory  implements Factory<CacheJdbcBlobStore> {
+public class CacheJdbcBlobStoreFactory<K, V>  implements Factory<CacheJdbcBlobStore<K, V>> {
     /** Connection URL. */
     private String connUrl = CacheJdbcBlobStore.DFLT_CONN_URL;
 
@@ -100,8 +100,8 @@ public class CacheJdbcBlobStoreFactory  implements Factory<CacheJdbcBlobStore> {
     private ApplicationContext appContext;
 
     /** {@inheritDoc} */
-    @Override public CacheJdbcBlobStore create() {
-        CacheJdbcBlobStore store = new CacheJdbcBlobStore();
+    @Override public CacheJdbcBlobStore<K, V> create() {
+        CacheJdbcBlobStore<K, V> store = new CacheJdbcBlobStore();
 
         store.setInitSchema(initSchema);
         store.setConnectionUrl(connUrl);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fef12fc2/modules/spring/src/test/config/node.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/node.xml b/modules/spring/src/test/config/node.xml
new file mode 100644
index 0000000..36d64cb
--- /dev/null
+++ b/modules/spring/src/test/config/node.xml
@@ -0,0 +1,43 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="simpleDataSource" class="org.h2.jdbcx.JdbcDataSource"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fef12fc2/modules/spring/src/test/config/store-cache1.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/store-cache1.xml b/modules/spring/src/test/config/store-cache1.xml
new file mode 100644
index 0000000..9209e52
--- /dev/null
+++ b/modules/spring/src/test/config/store-cache1.xml
@@ -0,0 +1,62 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+
+    <bean id="simpleDataSource1" class="sun.jdbc.odbc.ee.ConnectionPoolDataSource"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="gridName" value="ignite1"/>
+
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory">
+                            <property name="user" value = "GridGain" />
+                            <property name="dataSourceBean" value = "simpleDataSource1"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fef12fc2/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java
index bdfdcb9..eebd48d 100644
--- a/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java
@@ -22,22 +22,61 @@ import org.apache.ignite.configuration.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
 import org.h2.jdbcx.*;
+import sun.jdbc.odbc.ee.*;
 
 /**
  * Test for Cache jdbc blob store factory.
  */
 public class CacheJdbcBlobStoreFactorySelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "test";
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testXmlConfiguration() throws Exception {
         try (Ignite ignite = Ignition.start("modules/spring/src/test/config/store-cache.xml")) {
-            IgniteCache<Integer, String> cache = ignite.cache("test");
+            try(Ignite ignite1 = Ignition.start("modules/spring/src/test/config/store-cache1.xml")) {
+                checkStore(ignite.<Integer, String>cache(CACHE_NAME), JdbcDataSource.class);
+
+                checkStore(ignite1.<Integer, String>cache(CACHE_NAME), ConnectionPoolDataSource.class);
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheConfiguration() throws Exception {
+        try (Ignite ignite = Ignition.start("modules/spring/src/test/config/node.xml")) {
+            CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
+
+            CacheJdbcBlobStoreFactory<Integer, String> factory = new CacheJdbcBlobStoreFactory();
 
-            CacheJdbcBlobStore store = (CacheJdbcBlobStore) cache.getConfiguration(CacheConfiguration.class).
-                getCacheStoreFactory().create();
+            factory.setUser("GridGain");
 
-            assertEquals("GridGain", GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "user"));
+            factory.setDataSourceBean("simpleDataSource");
 
-            assertEquals(JdbcDataSource.class,
-                GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "dataSrc").getClass());
+            cfg.setCacheStoreFactory(factory);
+
+            try(IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
+                checkStore(cache, JdbcDataSource.class);
+            }
         }
     }
+
+    /**
+     * @param cache Ignite cache.
+     * @param dataSrcClass Data source class.
+     * @throws Exception If store parameters is not the same as in configuration xml.
+     */
+    private void checkStore(IgniteCache<Integer, String> cache, Class<?> dataSrcClass) throws Exception {
+        CacheJdbcBlobStore store = (CacheJdbcBlobStore) cache.getConfiguration(CacheConfiguration.class).
+            getCacheStoreFactory().create();
+
+        assertEquals("GridGain", GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "user"));
+
+        assertEquals(dataSrcClass,
+            GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "dataSrc").getClass());
+    }
 }