Repository: incubator-ignite Updated Branches: refs/heads/ignite-1019 [created] 56013700a
# IGNITE-1019 Resources are not injected on cache store factory. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/56013700 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/56013700 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/56013700 Branch: refs/heads/ignite-1019 Commit: 56013700a0de5d40999d3f1a5f6df3ea70821358 Parents: ec0f7c8 Author: sevdokimov <sergey.evdoki...@jetbrains.com> Authored: Wed Jul 22 20:12:52 2015 +0300 Committer: sevdokimov <sergey.evdoki...@jetbrains.com> Committed: Wed Jul 22 20:12:52 2015 +0300 ---------------------------------------------------------------------- .../GridCacheLoaderWriterStoreFactory.java | 14 +++ .../processors/cache/GridCacheProcessor.java | 9 +- .../store/StoreResourceInjectionSelfTest.java | 92 ++++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 1 + 4 files changed, 115 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56013700/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 3e27894..36f1d70 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 @@ -56,4 +56,18 @@ class GridCacheLoaderWriterStoreFactory<K, V> implements Factory<CacheStore<K, V return new GridCacheLoaderWriterStore<>(ldr, writer); } + + /** + * @return Loader factory. + */ + public Factory<CacheLoader<K, V>> loaderFactory() { + return ldrFactory; + } + + /** + * @return Writer factory. + */ + public Factory<CacheWriter<K, V>> writerFactory() { + return writerFactory; + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56013700/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 f5ccaec..2fd920b 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 @@ -1207,7 +1207,14 @@ 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/incubator-ignite/blob/56013700/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..7f93351 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/StoreResourceInjectionSelfTest.java @@ -0,0 +1,92 @@ +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.testframework.junits.common.*; + +import javax.cache.configuration.*; + +/** + * Test resource injection. + */ +public class StoreResourceInjectionSelfTest extends GridCommonAbstractTest { + /** */ + 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); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * + */ + public void testResourcesInStoreFactory() throws Exception { + cacheCfg.setCacheStoreFactory(new MyCacheStoreFactory()); + + startGrid(0); + } + + /** + * + */ + public void testResourcesInLoderFactory() 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/incubator-ignite/blob/56013700/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 bafdfef..2133ee3 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 @@ -133,6 +133,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(GridCacheTtlManagerSelfTest.class);