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:02:11 UTC

[12/27] incubator-ignite git commit: #ignite-960: Check that application context in CacheJdbcBlobStoreFactory contains bean + add test for it.

#ignite-960: Check that application context in CacheJdbcBlobStoreFactory contains bean + add test for it.


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

Branch: refs/heads/ignite-gg-10411
Commit: 0f124048e77ddfeb1323b71c1a52251d4071d361
Parents: 5c4bb21
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 2 13:27:58 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 2 13:27:58 2015 +0300

----------------------------------------------------------------------
 .../store/jdbc/CacheJdbcBlobStoreFactory.java   |  3 ++
 .../src/test/config/incorrect-store-cache.xml   | 57 ++++++++++++++++++++
 .../jdbc/CacheJdbcBlobStoreFactorySelfTest.java | 17 ++++++
 3 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f124048/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 9d572b6..df9adf8 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
@@ -117,6 +117,9 @@ public class CacheJdbcBlobStoreFactory<K, V>  implements Factory<CacheJdbcBlobSt
             if (appContext == null)
                 throw new IgniteException("Spring application context resource is not injected.");
 
+            if (!appContext.containsBean(dataSrcBean))
+                throw new IgniteException("Cannot find bean in application context. [beanName=" + dataSrcBean + "].");
+
             DataSource data = (DataSource) appContext.getBean(dataSrcBean);
 
             store.setDataSource(data);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f124048/modules/spring/src/test/config/incorrect-store-cache.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/incorrect-store-cache.xml b/modules/spring/src/test/config/incorrect-store-cache.xml
new file mode 100644
index 0000000..9a0b7c6
--- /dev/null
+++ b/modules/spring/src/test/config/incorrect-store-cache.xml
@@ -0,0 +1,57 @@
+<?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="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <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 = "simpleDataSource"/>
+                        </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/0f124048/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 6289e34..4a693a7 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
@@ -24,6 +24,8 @@ import org.apache.ignite.testframework.junits.common.*;
 import org.h2.jdbcx.*;
 import sun.jdbc.odbc.ee.*;
 
+import java.util.concurrent.*;
+
 /**
  * Test for Cache jdbc blob store factory.
  */
@@ -65,6 +67,21 @@ public class CacheJdbcBlobStoreFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testIncorrectBeanConfiguration() throws Exception {
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                try(Ignite ignite = Ignition.start("modules/spring/src/test/config/incorrect-store-cache.xml")) {
+                    ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class).
+                        getCacheStoreFactory().create();
+                }
+                return null;
+            }
+        }, IgniteException.class, "Cannot find bean in application context.");
+    }
+
+    /**
      * @return Cache configuration with store.
      */
     private CacheConfiguration<Integer, String> cacheConfiguration() {