ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/9] ignite git commit: IGNITE-1019 - Cache store factory injection
Date Thu, 03 Sep 2015 10:06:04 GMT
IGNITE-1019 - Cache store factory injection


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

Branch: refs/heads/ignite-1349
Commit: b8471482613288d607202e8903185ed10cf15f8d
Parents: 2a4839c
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Wed Sep 2 19:59:57 2015 -0700
Committer: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Committed: Wed Sep 2 19:59:57 2015 -0700

----------------------------------------------------------------------
 .../GridCacheLoaderWriterStoreFactory.java      |  20 +++-
 .../processors/cache/GridCacheProcessor.java    |  10 +-
 .../store/StoreResourceInjectionSelfTest.java   | 104 +++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite.java |   4 +-
 4 files changed, 133 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b8471482/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLoaderWriterStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLoaderWriterStoreFactory.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLoaderWriterStoreFactory.java
index 73573bd..9ba1190 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLoaderWriterStoreFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheLoaderWriterStoreFactory.java
@@ -5,9 +5,9 @@
  * 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.
@@ -56,4 +56,18 @@ class GridCacheLoaderWriterStoreFactory<K, V> implements Factory<CacheStore<K,
V
 
         return new GridCacheLoaderWriterStore<>(ldr, writer);
     }
-}
\ No newline at end of file
+
+    /**
+     * @return Loader factory.
+     */
+    Factory<CacheLoader<K, V>> loaderFactory() {
+        return ldrFactory;
+    }
+
+    /**
+     * @return Writer factory.
+     */
+    Factory<CacheWriter<K, V>> writerFactory() {
+        return writerFactory;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b8471482/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 cf8c8d6..75d4c43 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
@@ -1252,7 +1252,15 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     {
         assert cfg != null;
 
-        prepare(cfg, cfg.getCacheStoreFactory(), false);
+        if (cfg.getCacheStoreFactory() instanceof GridCacheLoaderWriterStoreFactory) {
+            GridCacheLoaderWriterStoreFactory factory = (GridCacheLoaderWriterStoreFactory)cfg.getCacheStoreFactory();
+
+            prepare(cfg, factory.loaderFactory(), false);
+            prepare(cfg, factory.writerFactory(), false);
+        }
+        else
+            prepare(cfg, cfg.getCacheStoreFactory(), false);
+
 
         CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create()
: null;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b8471482/modules/core/src/test/java/org/apache/ignite/cache/store/StoreResourceInjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/StoreResourceInjectionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/store/StoreResourceInjectionSelfTest.java
new file mode 100644
index 0000000..207cbfb
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/StoreResourceInjectionSelfTest.java
@@ -0,0 +1,104 @@
+package org.apache.ignite.cache.store;/*
+ * 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.
+ */
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import javax.cache.configuration.*;
+
+/**
+ * Test resource injection.
+ */
+public class StoreResourceInjectionSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<>();
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cacheCfg.setReadThrough(true);
+        cacheCfg.setWriteThrough(true);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     *
+     */
+    public void testResourcesInStoreFactory() throws Exception {
+        cacheCfg.setCacheStoreFactory(new MyCacheStoreFactory());
+
+        startGrid(0);
+    }
+
+    /**
+     *
+     */
+    public void testResourcesInLoaderFactory() throws Exception {
+        cacheCfg.setCacheLoaderFactory(new MyCacheStoreFactory());
+
+        startGrid(0);
+    }
+
+    /**
+     *
+     */
+    public void testResourcesInWriterFactory() throws Exception {
+        cacheCfg.setCacheWriterFactory(new MyCacheStoreFactory());
+
+        startGrid(0);
+    }
+
+    /**
+     *
+     */
+    public static class MyCacheStoreFactory implements Factory<CacheStore<Integer,
String>> {
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public CacheStore<Integer, String> create() {
+            assert ignite != null;
+
+            return new GridCacheTestStore();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b8471482/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index dac38de..1deb3bc 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -28,6 +28,7 @@ import org.apache.ignite.cache.affinity.fair.GridFairAffinityFunctionSelfTest;
 import org.apache.ignite.cache.affinity.fair.IgniteFairAffinityDynamicCacheSelfTest;
 import org.apache.ignite.cache.store.GridCacheBalancingStoreSelfTest;
 import org.apache.ignite.cache.store.GridCacheLoadOnlyStoreAdapterSelfTest;
+import org.apache.ignite.cache.store.StoreResourceInjectionSelfTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreMultitreadedSelfTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreTest;
 import org.apache.ignite.cache.store.jdbc.GridCacheJdbcBlobStoreMultithreadedSelfTest;
@@ -220,6 +221,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheObjectToStringSelfTest.class);
         suite.addTestSuite(GridCacheLoadOnlyStoreAdapterSelfTest.class);
         suite.addTestSuite(GridCacheGetStoreErrorSelfTest.class);
+        suite.addTestSuite(StoreResourceInjectionSelfTest.class);
         suite.addTestSuite(CacheFutureExceptionSelfTest.class);
         suite.addTestSuite(GridCacheAsyncOperationsLimitSelfTest.class);
         suite.addTestSuite(IgniteCacheManyAsyncOperationsTest.class);
@@ -266,4 +268,4 @@ public class IgniteCacheTestSuite extends TestSuite {
 
         return suite;
     }
-}
\ No newline at end of file
+}


Mime
View raw message