Repository: incubator-ignite Updated Branches: refs/heads/ignite-884 [created] d41af24d2
IGNITE-884 - Spring autowiring Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/c3459a2d Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/c3459a2d Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/c3459a2d Branch: refs/heads/ignite-884 Commit: c3459a2dfd31de86b10aa8ab5abcc0ce5588e9d5 Parents: 40f826b Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Fri Jun 12 22:08:21 2015 -0700 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Fri Jun 12 22:08:21 2015 -0700 ---------------------------------------------------------------------- .../processors/cache/CacheStartContext.java | 104 +++++++++++ .../processors/cache/GridCacheProcessor.java | 17 +- .../resource/GridResourceProcessor.java | 8 + .../resource/GridSpringResourceContext.java | 6 + .../resource/GridSpringResourceContextImpl.java | 15 +- .../spring/autowired/SpringAutowiredBean.java | 40 +++++ .../autowired/SpringAutowiredSelfTest.java | 180 +++++++++++++++++++ .../autowired/SpringAutowiredTestService.java | 72 ++++++++ .../autowired/SpringAutowiredTestStore.java | 76 ++++++++ .../spring/autowired/autowired-service.xml | 64 +++++++ .../ignite/spring/autowired/autowired.xml | 36 ++++ 11 files changed, 613 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStartContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStartContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStartContext.java new file mode 100644 index 0000000..f305a47 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheStartContext.java @@ -0,0 +1,104 @@ +/* + * 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.processors.cache; + +import org.apache.ignite.cache.store.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; + +import javax.cache.configuration.*; +import javax.cache.expiry.*; +import java.util.*; + +/** + * Cache start context. + */ +public class CacheStartContext { + /** */ + private CacheStore store; + + /** */ + private ExpiryPolicy expPlc; + + /** */ + private CacheStoreSessionListener[] sesLsnrs; + + /** + * @param cfg Configuration. + */ + public CacheStartContext(GridKernalContext ctx, CacheConfiguration<?, ?> cfg) { + assert ctx != null; + assert cfg != null; + + store = create(ctx, cfg.getCacheStoreFactory()); + expPlc = create(ctx, cfg.getExpiryPolicyFactory()); + //sesLsnrs = create(ctx, cfg.getCacheStoreSessionListenerFactories()); + } + + /** + * @return Cache store. + */ + public CacheStore store() { + return store; + } + + /** + * @return Expiry policy. + */ + public ExpiryPolicy expiryPolicy() { + return expPlc; + } + + /** + * @return Store session listeners. + */ + public CacheStoreSessionListener[] storeSessionListeners() { + return sesLsnrs; + } + + /** + * @param ctx Context. + * @param factory Factory. + * @return Object. + */ + private <T> T create(GridKernalContext ctx, Factory<T> factory) { + T obj = factory != null ? factory.create() : null; + + ctx.resource().autowireSpringBean(obj); + + return obj; + } + + /** + * @param ctx Context. + * @param factories Factories. + * @return Objects. + */ + private <T> T[] create(GridKernalContext ctx, Factory<T>[] factories) { + Collection<T> col = new ArrayList<>(factories.length); + + for (Factory<T> factory : factories) { + T obj = create(ctx, factory); + + if (obj != null) + col.add(obj); + } + + return (T[])col.toArray(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/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 4fdec33..b20d32c 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 @@ -57,6 +57,7 @@ import org.apache.ignite.marshaller.*; import org.apache.ignite.marshaller.jdk.*; import org.apache.ignite.spi.*; import org.jetbrains.annotations.*; +import org.jsr166.*; import javax.cache.configuration.*; import javax.cache.integration.*; @@ -118,6 +119,9 @@ public class GridCacheProcessor extends GridProcessorAdapter { /** Cache templates. */ private ConcurrentMap<String, DynamicCacheDescriptor> registeredTemplates = new ConcurrentHashMap<>(); + /** Start contexts. */ + private ConcurrentMap<String, CacheStartContext> startCtxs = new ConcurrentHashMap8<>(); + /** */ private IdentityHashMap<CacheStore, ThreadLocal> sesHolders = new IdentityHashMap<>(); @@ -222,7 +226,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { } if (cfg.getCacheStoreFactory() == null) { - Factory<CacheLoader> ldrFactory = cfg.getCacheLoaderFactory(); + Factory<CacheLoader> ldrFactory = cfg.isReadThrough() ? cfg.getCacheLoaderFactory() : null; Factory<CacheWriter> writerFactory = cfg.isWriteThrough() ? cfg.getCacheWriterFactory() : null; if (ldrFactory != null || writerFactory != null) @@ -1072,7 +1076,12 @@ public class GridCacheProcessor extends GridProcessorAdapter { { assert cfg != null; - CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null; + CacheStartContext startCtx = startCtxs.remove(maskNull(cfg.getName())); + + if (startCtx == null) + startCtx = new CacheStartContext(ctx, cfg); + + CacheStore cfgStore = startCtx.store(); validate(ctx.config(), cfg, cacheType, cfgStore); @@ -1958,6 +1967,8 @@ public class GridCacheProcessor extends GridProcessorAdapter { req.cacheType(cacheType); + startCtxs.putIfAbsent(maskNull(cacheName), new CacheStartContext(ctx, req.startCacheConfiguration())); + return F.first(initiateCacheChanges(F.asList(req), failIfExists)); } @@ -3040,6 +3051,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { @Override public boolean onDone(@Nullable Object res, @Nullable Throwable err) { // Make sure to remove future before completion. pendingFuts.remove(maskNull(cacheName), this); + startCtxs.remove(maskNull(cacheName)); return super.onDone(res, err); } @@ -3143,4 +3155,3 @@ public class GridCacheProcessor extends GridProcessorAdapter { } } } - http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java index f5ba492..faa7142 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java @@ -556,6 +556,14 @@ public class GridResourceProcessor extends GridProcessorAdapter { } /** + * @param bean Spring bean. + */ + public void autowireSpringBean(@Nullable Object bean) { + if (rsrcCtx != null) + rsrcCtx.autowireBean(bean); + } + + /** * Returns GridResourceIoc object. For tests only!!! * * @return GridResourceIoc object. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContext.java index f0d17ec..dfce905 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContext.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.resource; import org.apache.ignite.*; import org.apache.ignite.internal.*; +import org.jetbrains.annotations.*; /** * Interface was introduced to avoid compile-time dependency on spring framework. Spring resource context @@ -44,5 +45,10 @@ public interface GridSpringResourceContext { * @throws IgniteCheckedException If unwrap failed. */ public Object unwrapTarget(Object target) throws IgniteCheckedException; + + /** + * @param bean Spring bean. + */ + public void autowireBean(@Nullable Object bean); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContextImpl.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContextImpl.java b/modules/spring/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContextImpl.java index c49d891..024dd2f 100644 --- a/modules/spring/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContextImpl.java +++ b/modules/spring/src/main/java/org/apache/ignite/internal/processors/resource/GridSpringResourceContextImpl.java @@ -26,16 +26,21 @@ import org.springframework.context.*; * Implementation of {@link GridSpringResourceContext}. */ public class GridSpringResourceContextImpl implements GridSpringResourceContext { + /** Spring context. */ + private final ApplicationContext springCtx; + /** Spring application context injector. */ - private GridResourceInjector springCtxInjector; + private final GridResourceInjector springCtxInjector; /** Spring bean resources injector. */ - private GridResourceInjector springBeanInjector; + private final GridResourceInjector springBeanInjector; /** * @param springCtx Spring application context. */ public GridSpringResourceContextImpl(@Nullable ApplicationContext springCtx) { + this.springCtx = springCtx; + springCtxInjector = new GridResourceBasicInjector<>(springCtx); springBeanInjector = new GridResourceSpringBeanInjector(springCtx); } @@ -64,4 +69,10 @@ public class GridSpringResourceContextImpl implements GridSpringResourceContext return target; } + + /** {@inheritDoc} */ + @Override public void autowireBean(@Nullable Object bean) { + if (springCtx != null && bean != null) + springCtx.getAutowireCapableBeanFactory().autowireBean(bean); + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredBean.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredBean.java b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredBean.java new file mode 100644 index 0000000..b7d85c0 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredBean.java @@ -0,0 +1,40 @@ +/* + * 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.spring.autowired; + +/** + * Autowired bean. + */ +public class SpringAutowiredBean { + /** */ + private String name; + + /** + * @param name Name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return Name. + */ + public String getName() { + return name; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredSelfTest.java new file mode 100644 index 0000000..43c45ef --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredSelfTest.java @@ -0,0 +1,180 @@ +/* + * 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.spring.autowired; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; +import org.springframework.context.*; +import org.springframework.context.support.*; +import org.springframework.core.io.*; + +import javax.cache.configuration.*; +import java.net.*; +import java.util.*; + +/** + * Spring autowiring test. + */ +public class SpringAutowiredSelfTest extends GridCommonAbstractTest { + /** */ + public static final String CACHE_NAME = SpringAutowiredSelfTest.class.getSimpleName(); + + /** */ + private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(); + + static { + IP_FINDER.setAddresses(Arrays.asList("127.0.0.1:47500")); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + SpringAutowiredTestStore.load.clear(); + SpringAutowiredTestStore.write.clear(); + SpringAutowiredTestStore.delete.clear(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testStoreAtomic() throws Exception { + testStore(CacheAtomicityMode.ATOMIC); + + assertEquals(3, SpringAutowiredTestStore.load.size()); + assertEquals(3, SpringAutowiredTestStore.write.size()); + assertEquals(3, SpringAutowiredTestStore.delete.size()); + } + + /** + * @throws Exception If failed. + */ + public void testStoreTransactional() throws Exception { + testStore(CacheAtomicityMode.TRANSACTIONAL); + + assertEquals(3, SpringAutowiredTestStore.load.size()); + assertEquals(1, SpringAutowiredTestStore.write.size()); + assertEquals(1, SpringAutowiredTestStore.delete.size()); + } + + /** + * @param mode Atomicity mode. + * @throws Exception In case of error. + */ + private void testStore(CacheAtomicityMode mode) throws Exception { + ApplicationContext appCtx = new ClassPathXmlApplicationContext( + "org/apache/ignite/spring/autowired/autowired.xml"); + + for (int i = 0; i < 3; i++) + IgniteSpring.start(configuration("server-" + i), appCtx); + + Ignition.setClientMode(true); + + Ignite client = IgniteSpring.start(configuration("client"), appCtx); + + CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(); + + ccfg.setName(CACHE_NAME); + ccfg.setAtomicityMode(mode); + ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(SpringAutowiredTestStore.class)); + ccfg.setReadThrough(true); + ccfg.setWriteThrough(true); + + IgniteCache<Integer, Integer> cache = client.createCache(ccfg); + + for (int i = 0; i < 100; i++) + cache.get(i); + + for (int i = 0; i < 100; i++) + cache.put(i, i); + + for (int i = 0; i < 100; i++) + cache.remove(i); + } + + /** + * @throws Exception If failed. + */ + public void testServiceAtomic() throws Exception { + ApplicationContext appCtx = new ClassPathXmlApplicationContext( + "org/apache/ignite/spring/autowired/autowired.xml"); + + for (int i = 0; i < 3; i++) + IgniteSpring.start(configuration("server-" + i), appCtx); + + SpringAutowiredTestService.mode = CacheAtomicityMode.ATOMIC; + + URL url = new ClassPathResource("org/apache/ignite/spring/autowired/autowired-service.xml").getURL(); + + SpringAutowiredTestService svc = Ignition.loadSpringBean(url, "test-service"); + + svc.run(); + + assertEquals(3, SpringAutowiredTestStore.load.size()); + assertEquals(3, SpringAutowiredTestStore.write.size()); + assertEquals(3, SpringAutowiredTestStore.delete.size()); + } + + /** + * @throws Exception If failed. + */ + public void testServiceTransactional() throws Exception { + ApplicationContext appCtx = new ClassPathXmlApplicationContext( + "org/apache/ignite/spring/autowired/autowired.xml"); + + for (int i = 0; i < 3; i++) + IgniteSpring.start(configuration("server-" + i), appCtx); + + SpringAutowiredTestService.mode = CacheAtomicityMode.TRANSACTIONAL; + + URL url = new ClassPathResource("org/apache/ignite/spring/autowired/autowired-service.xml").getURL(); + + SpringAutowiredTestService svc = Ignition.loadSpringBean(url, "test-service"); + + svc.run(); + + assertEquals(3, SpringAutowiredTestStore.load.size()); + assertEquals(1, SpringAutowiredTestStore.write.size()); + assertEquals(1, SpringAutowiredTestStore.delete.size()); + } + + /** + * @param name Name. + * @return Configuration. + */ + private IgniteConfiguration configuration(String name) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(name); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + return cfg; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestService.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestService.java b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestService.java new file mode 100644 index 0000000..e011cae --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestService.java @@ -0,0 +1,72 @@ +/* + * 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.spring.autowired; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.springframework.beans.factory.*; + +import javax.cache.configuration.*; + +/** + * Test service. + */ +public class SpringAutowiredTestService implements InitializingBean { + /** */ + public static CacheAtomicityMode mode; + + /** */ + private Ignite ignite; + + /** */ + private IgniteCache<Integer, Integer> cache; + + /** + * @param ignite Ignite. + */ + public void setIgnite(Ignite ignite) { + this.ignite = ignite; + } + + /** {@inheritDoc} */ + @Override public void afterPropertiesSet() throws Exception { + CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(); + + ccfg.setName(SpringAutowiredSelfTest.CACHE_NAME); + ccfg.setAtomicityMode(mode); + ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(SpringAutowiredTestStore.class)); + ccfg.setReadThrough(true); + ccfg.setWriteThrough(true); + + cache = ignite.createCache(ccfg); + } + + /** + */ + public void run() { + for (int i = 0; i < 100; i++) + cache.get(i); + + for (int i = 0; i < 100; i++) + cache.put(i, i); + + for (int i = 0; i < 100; i++) + cache.remove(i); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestStore.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestStore.java b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestStore.java new file mode 100644 index 0000000..d51c767 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/SpringAutowiredTestStore.java @@ -0,0 +1,76 @@ +/* + * 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.spring.autowired; + +import org.apache.ignite.*; +import org.apache.ignite.cache.store.*; +import org.apache.ignite.resources.*; +import org.springframework.beans.factory.annotation.*; + +import javax.cache.*; +import javax.cache.integration.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * Test store. + */ +public class SpringAutowiredTestStore extends CacheStoreAdapter<Integer, Integer> { + /** */ + public static final Set<UUID> load = new ConcurrentSkipListSet<>(); + + /** */ + public static final Set<UUID> write = new ConcurrentSkipListSet<>(); + + /** */ + public static final Set<UUID> delete = new ConcurrentSkipListSet<>(); + + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** */ + @Autowired + private SpringAutowiredBean bean; + + /** {@inheritDoc} */ + @Override public Integer load(Integer key) throws CacheLoaderException { + load.add(ignite.cluster().localNode().id()); + + assert bean != null; + assert "test-bean".equals(bean.getName()) : bean.getName(); + + return null; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) throws CacheWriterException { + write.add(ignite.cluster().localNode().id()); + + assert bean != null; + assert "test-bean".equals(bean.getName()) : bean.getName(); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + delete.add(ignite.cluster().localNode().id()); + + assert bean != null; + assert "test-bean".equals(bean.getName()) : bean.getName(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired-service.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired-service.xml b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired-service.xml new file mode 100644 index 0000000..7062a2e --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired-service.xml @@ -0,0 +1,64 @@ +<?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 configuration with all defaults and enabled p2p deployment and enabled events. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-2.5.xsd"> + <context:annotation-config/> + + <bean class="org.apache.ignite.spring.autowired.SpringAutowiredBean"> + <property name="name" value="test-bean"/> + </bean> + + <bean id="ignite" class="org.apache.ignite.IgniteSpringBean"> + <property name="configuration"> + <bean class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="gridName" value="client"/> + + <property name="clientMode" value="true"/> + + <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</value> + </list> + </property> + </bean> + </property> + </bean> + </property> + </bean> + </property> + </bean> + + <bean id="test-service" class="org.apache.ignite.spring.autowired.SpringAutowiredTestService"> + <property name="ignite" ref="ignite"/> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3459a2d/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired.xml b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired.xml new file mode 100644 index 0000000..6bae746 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/autowired/autowired.xml @@ -0,0 +1,36 @@ +<?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 configuration with all defaults and enabled p2p deployment and enabled events. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-2.5.xsd"> + <context:annotation-config/> + + <bean class="org.apache.ignite.spring.autowired.SpringAutowiredBean"> + <property name="name" value="test-bean"/> + </bean> +</beans>