http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/p2p/GridP2PUserVersionChangeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/p2p/GridP2PUserVersionChangeSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/p2p/GridP2PUserVersionChangeSelfTest.java new file mode 100644 index 0000000..578de03 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/p2p/GridP2PUserVersionChangeSelfTest.java @@ -0,0 +1,357 @@ +/* + * 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.p2p; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.events.*; +import org.apache.ignite.lang.*; +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.internal.util.typedef.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.config.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.net.*; +import java.util.*; +import java.util.concurrent.*; + +import static java.util.concurrent.TimeUnit.*; +import static org.apache.ignite.events.IgniteEventType.*; + +/** + * The test does the following: + * + * 1. The test should execute a task in SHARED_DEPLOY mode, restart a node with new version and make sure that a + * new class loader is created on remote node. + * 2. The test should execute a task in SHARED_DEPLOY mode, restart a node with same version and make sure + * that the same class loader is created on remote node. + * 3. The test should execute a task in SHARED_UNDEPLOY mode, restart a node with same version and + * make sure that a new class loader is created on remote node. + */ +@SuppressWarnings({"ProhibitedExceptionDeclared", "ObjectEquality", "unchecked"}) +public class GridP2PUserVersionChangeSelfTest extends GridCommonAbstractTest { + /** Current deployment mode. */ + private IgniteDeploymentMode depMode; + + /** Test task class name. */ + private static final String TEST_TASK_NAME = "org.gridgain.grid.tests.p2p.GridP2PTestTaskExternalPath1"; + + /** Test resource class name. */ + private static final String TEST_RCRS_NAME = "org.gridgain.grid.tests.p2p.GridTestUserResource"; + + /** IP finder. */ + private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + public GridP2PUserVersionChangeSelfTest() { + super(/*start grid*/false); + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 30 * 1000; + } + + /** + * @return Timeout for condition waits. + */ + private long getConditionTimeout() { + return getTestTimeout() > 10000 ? getTestTimeout() - 10000 : getTestTimeout(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setDeploymentMode(depMode); + cfg.setNetworkTimeout(10000); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(discoSpi); + + if (gridName.contains("testCacheRedeployVersionChangeContinuousMode")) { + CacheConfiguration cacheCfg = new CacheConfiguration(); + + cacheCfg.setCacheMode(GridCacheMode.REPLICATED); + + cfg.setCacheConfiguration(cacheCfg); + } + else + cfg.setCacheConfiguration(); + + return cfg; + } + + /** + * @throws Exception If test failed. + */ + public void testRedeployVersionChangeContinuousMode() throws Exception { + depMode = IgniteDeploymentMode.CONTINUOUS; + + checkRedeployVersionChange(); + } + + /** + * @throws Exception If test failed. + */ + public void testRedeployVersionChangeSharedMode() throws Exception { + depMode = IgniteDeploymentMode.SHARED; + + checkRedeployVersionChange(); + } + + /** + * @throws Exception If failed. + */ + private void checkRedeployVersionChange() throws Exception { + try { + Ignite ignite1 = startGrid(1); + Ignite ignite2 = startGrid(2); + + GridTestExternalClassLoader ldr = new GridTestExternalClassLoader( + new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, + Collections.singletonMap("META-INF/gridgain.xml", makeUserVersion("1").getBytes())); + + Class task1 = ldr.loadClass(TEST_TASK_NAME); + + final CountDownLatch undeployed = new CountDownLatch(1); + + ignite2.events().localListen(new IgnitePredicate<IgniteEvent>() { + @Override public boolean apply(IgniteEvent evt) { + if (evt.type() == EVT_TASK_UNDEPLOYED && + ((IgniteDeploymentEvent) evt).alias().equals(TEST_TASK_NAME)) + undeployed.countDown(); + + return true; + } + }, EVT_TASK_UNDEPLOYED); + + Integer res1 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + stopGrid(1); + + ldr.setResourceMap(Collections.singletonMap("META-INF/gridgain.xml", makeUserVersion("2").getBytes())); + + ignite1 = startGrid(1); + + Integer res2 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + assert !res1.equals(res2); + + // Allow P2P timeout to expire. + assert undeployed.await(30000, MILLISECONDS); + } + finally { + stopGrid(1); + stopGrid(2); + } + } + + /** + * @throws Exception If failed. + */ + public void testRedeployOnNodeRestartContinuousMode() throws Exception { + depMode = IgniteDeploymentMode.CONTINUOUS; + + try { + Ignite ignite1 = startGrid(1); + Ignite ignite2 = startGrid(2); + + GridTestExternalClassLoader ldr = new GridTestExternalClassLoader( + new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }); + + Class task1 = ldr.loadClass(TEST_TASK_NAME); + + final CountDownLatch undeployed = new CountDownLatch(1); + + ignite2.events().localListen(new IgnitePredicate<IgniteEvent>() { + @Override public boolean apply(IgniteEvent evt) { + if (evt.type() == EVT_TASK_UNDEPLOYED && + ((IgniteDeploymentEvent) evt).alias().equals(TEST_TASK_NAME)) + undeployed.countDown(); + + return true; + } + }, EVT_TASK_UNDEPLOYED); + + Integer res1 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + stopGrid(1); + + ignite1 = startGrid(1); + + Integer res2 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + assert !undeployed.await(3000, MILLISECONDS); + + assert res1.equals(res2); + } + finally { + stopGrid(1); + stopGrid(2); + } + } + + /** + * @throws Exception If failed. + */ + public void testRedeployOnNodeRestartSharedMode() throws Exception { + depMode = IgniteDeploymentMode.SHARED; + + try { + Ignite ignite1 = startGrid(1); + Ignite ignite2 = startGrid(2); + + GridTestExternalClassLoader ldr = new GridTestExternalClassLoader( + new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }); + + Class task1 = ldr.loadClass(TEST_TASK_NAME); + + final CountDownLatch undeployed = new CountDownLatch(1); + + ignite2.events().localListen(new IgnitePredicate<IgniteEvent>() { + @Override public boolean apply(IgniteEvent evt) { + if (evt.type() == EVT_TASK_UNDEPLOYED && + ((IgniteDeploymentEvent) evt).alias().equals(TEST_TASK_NAME)) + undeployed.countDown(); + + return true; + } + }, EVT_TASK_UNDEPLOYED); + + final CountDownLatch discoLatch = new CountDownLatch(1); + + ignite2.events().localListen(new IgnitePredicate<IgniteEvent>() { + @Override public boolean apply(IgniteEvent evt) { + if (evt.type() == EVT_NODE_LEFT) + discoLatch.countDown(); + + return true; + } + }, EVT_NODE_LEFT); + + Integer res1 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + stopGrid(1); + + assert discoLatch.await(1000, MILLISECONDS); + + assert undeployed.await(1000, MILLISECONDS); + + ignite1 = startGrid(1); + + Integer res2 = (Integer)ignite1.compute().execute(task1, ignite2.cluster().localNode().id()); + + assert !res1.equals(res2); + } + finally { + stopGrid(1); + stopGrid(2); + } + } + + /** + * @throws Exception If failed. + */ + // TODO: GG-5678 Uncomment when fix + public void _testCacheRedeployVersionChangeContinuousMode() throws Exception { + depMode = IgniteDeploymentMode.CONTINUOUS; + + try { + Ignite ignite1 = startGrid("testCacheRedeployVersionChangeContinuousMode1"); + Ignite ignite2 = startGrid("testCacheRedeployVersionChangeContinuousMode2"); + + GridTestExternalClassLoader ldr = new GridTestExternalClassLoader( + new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, + Collections.singletonMap("META-INF/gridgain.xml", makeUserVersion("1").getBytes())); + + Class rcrsCls = ldr.loadClass(TEST_RCRS_NAME); + + GridCache<Long, Object> cache1 = ignite1.cache(null); + + assertNotNull(cache1); + + cache1.put(1L, rcrsCls.newInstance()); + + final GridCache<Long, Object> cache2 = ignite2.cache(null); + + assertNotNull(cache2); + + // The entry should propagate to grid2, because the + // cache is REPLICATED. This happens asynchronously, we + // need to use condition wait. + assert GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() throws IgniteCheckedException { + return cache2.get(1L) != null; + } + }, getConditionTimeout()); + + stopGrid("testCacheRedeployVersionChangeContinuousMode1"); + + // Increase the user version of the test class. + ldr.setResourceMap(Collections.singletonMap("META-INF/gridgain.xml", makeUserVersion("2").getBytes())); + + ignite1 = startGrid("testCacheRedeployVersionChangeContinuousMode1"); + + cache1 = ignite1.cache(null); + + assertNotNull(cache1); + + // Put an entry with a new user version. + cache1.put(2L, rcrsCls.newInstance()); + + // At this point, old version of test resource should be undeployed + // and removed from cache asynchronously. + assert GridTestUtils.waitForCondition(new PAX() { + @Override public boolean applyx() throws IgniteCheckedException { + return cache2.get(1L) == null; + } + }, getConditionTimeout()) : "2nd condition failed [entries1=" + cache1.entrySet() + + ", entries2=" + cache2.entrySet() + ']'; + } + finally { + stopAllGrids(); + } + } + + /** + * Creates content of META-INF/gridgain.xml for specified user version. + * + * @param userVer Version to create. + * @return content of META-INF/gridgain.xml. + */ + private String makeUserVersion(String userVer) { + return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + + "<beans xmlns=\"http://www.springframework.org/schema/beans\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xmlns:util=\"http://www.springframework.org/schema/util\" " + + "xsi:schemaLocation=\"http://www.springframework.org/schema/beans " + + "http://www.springframework.org/schema/beans/spring-beans.xsd " + + "http://www.springframework.org/schema/util " + + "http://www.springframework.org/schema/util/spring-util.xsd\"> " + + "<bean id=\"userVersion\" class=\"java.lang.String\"><constructor-arg value=\"" + userVer + "\"/></bean> " + + "</beans>"; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheManagerSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheManagerSelfTest.java new file mode 100644 index 0000000..1d888c4 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheManagerSelfTest.java @@ -0,0 +1,237 @@ +/* + * 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; + +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.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; +import org.springframework.beans.factory.*; +import org.springframework.context.support.*; + +/** + * Spring cache test. + */ +public class GridSpringCacheManagerSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String CACHE_NAME = "testCache"; + + /** */ + private GridSpringCacheTestService svc; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration cache = new CacheConfiguration(); + + cache.setName(CACHE_NAME); + + cfg.setCacheConfiguration(cache); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override public String getTestGridName() { + return "testGrid"; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + BeanFactory factory = new ClassPathXmlApplicationContext("org/apache/ignite/spring/spring-caching.xml"); + + svc = (GridSpringCacheTestService)factory.getBean("testService"); + + svc.reset(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + grid().cache(CACHE_NAME).removeAll(); + } + + /** + * @throws Exception If failed. + */ + public void testSimpleKey() throws Exception { + for (int i = 0; i < 3; i++) { + assertEquals("value" + i, svc.simpleKey(i)); + assertEquals("value" + i, svc.simpleKey(i)); + } + + assertEquals(3, svc.called()); + + GridCache<Integer, String> c = grid().cache(CACHE_NAME); + + assertEquals(3, c.size()); + + for (int i = 0; i < 3; i++) + assertEquals("value" + i, c.get(i)); + } + + /** + * @throws Exception If failed. + */ + public void testComplexKey() throws Exception { + for (int i = 0; i < 3; i++) { + assertEquals("value" + i + "suffix" + i, svc.complexKey(i, "suffix" + i)); + assertEquals("value" + i + "suffix" + i, svc.complexKey(i, "suffix" + i)); + } + + assertEquals(3, svc.called()); + + GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); + + assertEquals(3, c.size()); + + for (int i = 0; i < 3; i++) + assertEquals("value" + i + "suffix" + i, c.get(new GridSpringCacheTestKey(i, "suffix" + i))); + } + + /** + * @throws Exception If failed. + */ + public void testSimpleKeyPut() throws Exception { + GridCache<Integer, String> c = grid().cache(CACHE_NAME); + + for (int i = 0; i < 3; i++) { + assertEquals("value" + i + "odd", svc.simpleKeyPut(i)); + + assertEquals(i + 1, c.size()); + assertEquals("value" + i + "odd", c.get(i)); + + assertEquals("value" + i + "even", svc.simpleKeyPut(i)); + + assertEquals(i + 1, c.size()); + assertEquals("value" + i + "even", c.get(i)); + } + + assertEquals(6, svc.called()); + } + + /** + * @throws Exception If failed. + */ + public void testComplexKeyPut() throws Exception { + GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); + + for (int i = 0; i < 3; i++) { + assertEquals("value" + i + "suffix" + i + "odd", svc.complexKeyPut(i, "suffix" + i)); + + assertEquals(i + 1, c.size()); + assertEquals("value" + i + "suffix" + i + "odd", c.get(new GridSpringCacheTestKey(i, "suffix" + i))); + + assertEquals("value" + i + "suffix" + i + "even", svc.complexKeyPut(i, "suffix" + i)); + + assertEquals(i + 1, c.size()); + assertEquals("value" + i + "suffix" + i + "even", c.get(new GridSpringCacheTestKey(i, "suffix" + i))); + } + + assertEquals(6, svc.called()); + } + + /** + * @throws Exception If failed. + */ + public void testSimpleKeyEvict() throws Exception { + GridCache<Integer, String> c = grid().cache(CACHE_NAME); + + for (int i = 0; i < 3; i++) + c.putx(i, "value" + i); + + assertEquals(3, c.size()); + + assertEquals("value0", c.get(0)); + assertEquals("value1", c.get(1)); + assertEquals("value2", c.get(2)); + + svc.simpleKeyEvict(2); + + assertEquals(2, c.size()); + + assertEquals("value0", c.get(0)); + assertEquals("value1", c.get(1)); + assertNull(c.get(2)); + } + + /** + * @throws Exception If failed. + */ + public void testComplexKeyEvict() throws Exception { + GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); + + for (int i = 0; i < 3; i++) + c.putx(new GridSpringCacheTestKey(i, "suffix" + i), "value" + i); + + assertEquals(3, c.size()); + + assertEquals("value0", c.get(new GridSpringCacheTestKey(0, "suffix" + 0))); + assertEquals("value1", c.get(new GridSpringCacheTestKey(1, "suffix" + 1))); + assertEquals("value2", c.get(new GridSpringCacheTestKey(2, "suffix" + 2))); + + svc.complexKeyEvict(2, "suffix" + 2); + + assertEquals(2, c.size()); + + assertEquals("value0", c.get(new GridSpringCacheTestKey(0, "suffix" + 0))); + assertEquals("value1", c.get(new GridSpringCacheTestKey(1, "suffix" + 1))); + assertNull(c.get(new GridSpringCacheTestKey(2, "suffix" + 2))); + } + + /** + * @throws Exception If failed. + */ + public void testEvictAll() throws Exception { + GridCache<Integer, String> c = grid().cache(CACHE_NAME); + + for (int i = 0; i < 3; i++) + c.putx(i, "value" + i); + + assertEquals(3, c.size()); + + assertEquals("value0", c.get(0)); + assertEquals("value1", c.get(1)); + assertEquals("value2", c.get(2)); + + svc.evictAll(); + + assertEquals(0, c.size()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKey.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKey.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKey.java new file mode 100644 index 0000000..70c9de0 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKey.java @@ -0,0 +1,59 @@ +/* + * 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; + +/** + * Complex key. + */ +public class GridSpringCacheTestKey { + /** */ + private final Integer p1; + + /** */ + private final String p2; + + /** + * @param p1 Parameter 1. + * @param p2 Parameter 2. + */ + public GridSpringCacheTestKey(Integer p1, String p2) { + assert p1 != null; + assert p2 != null; + + this.p1 = p1; + this.p2 = p2; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + GridSpringCacheTestKey key = (GridSpringCacheTestKey)o; + + return p1.equals(key.p1) && p2.equals(key.p2); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return 31 * p1 + p2.hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKeyGenerator.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKeyGenerator.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKeyGenerator.java new file mode 100644 index 0000000..6411029 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestKeyGenerator.java @@ -0,0 +1,41 @@ +/* + * 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; + +import org.springframework.cache.interceptor.*; + +import java.lang.reflect.*; + +/** + * Key generator. + */ +public class GridSpringCacheTestKeyGenerator implements KeyGenerator { + /** {@inheritDoc} */ + @Override public Object generate(Object target, Method mtd, Object... params) { + assert params != null; + assert params.length > 0; + + if (params.length == 1) + return params[0]; + else { + assert params.length == 2; + + return new GridSpringCacheTestKey((Integer)params[0], (String)params[1]); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestService.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestService.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestService.java new file mode 100644 index 0000000..adfedde --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringCacheTestService.java @@ -0,0 +1,124 @@ +/* + * 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; + +import org.springframework.cache.annotation.*; + +import java.util.concurrent.atomic.*; + +/** + * Test service. + */ +public class GridSpringCacheTestService { + /** */ + private final AtomicInteger cnt = new AtomicInteger(); + + /** + * @return How many times service was called. + */ + public int called() { + return cnt.get(); + } + + /** + * Resets service. + */ + public void reset() { + cnt.set(0); + } + + /** + * @param key Key. + * @return Value. + */ + @Cacheable("testCache") + public String simpleKey(Integer key) { + assert key != null; + + cnt.incrementAndGet(); + + return "value" + key; + } + + /** + * @param p1 Parameter 1. + * @param p2 Parameter 2. + * @return Value. + */ + @Cacheable("testCache") + public String complexKey(Integer p1, String p2) { + assert p1 != null; + assert p2 != null; + + cnt.incrementAndGet(); + + return "value" + p1 + p2; + } + + /** + * @param key Key. + * @return Value. + */ + @CachePut("testCache") + public String simpleKeyPut(Integer key) { + assert key != null; + + int cnt0 = cnt.incrementAndGet(); + + return "value" + key + (cnt0 % 2 == 0 ? "even" : "odd"); + } + + /** + * @param p1 Parameter 1. + * @param p2 Parameter 2. + * @return Value. + */ + @CachePut("testCache") + public String complexKeyPut(Integer p1, String p2) { + assert p1 != null; + assert p2 != null; + + int cnt0 = cnt.incrementAndGet(); + + return "value" + p1 + p2 + (cnt0 % 2 == 0 ? "even" : "odd"); + } + + /** + * @param key Key. + */ + @CacheEvict("testCache") + public void simpleKeyEvict(Integer key) { + // No-op. + } + + /** + * @param p1 Parameter 1. + * @param p2 Parameter 2. + */ + @CacheEvict("testCache") + public void complexKeyEvict(Integer p1, String p2) { + // No-op. + } + + /** + */ + @CacheEvict(value = "testCache", allEntries = true) + public void evictAll() { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheManagerSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheManagerSelfTest.java new file mode 100644 index 0000000..1184560 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheManagerSelfTest.java @@ -0,0 +1,219 @@ +/* + * 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; + +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.spring.*; +import org.apache.ignite.configuration.*; +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 org.springframework.beans.factory.*; +import org.springframework.cache.*; +import org.springframework.context.support.*; + +import java.lang.reflect.*; +import java.util.*; + +/** + * Spring cache test. + */ +public class GridSpringDynamicCacheManagerSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String DATA_CACHE_NAME = "data"; + + /** */ + private GridSpringDynamicCacheTestService svc; + + /** */ + private CacheManager mgr; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration cache = new CacheConfiguration(); + + cache.setName(DATA_CACHE_NAME); + + cfg.setCacheConfiguration(cache); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override public String getTestGridName() { + return "testGrid"; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + BeanFactory factory = new ClassPathXmlApplicationContext( + "org/apache/ignite/spring/spring-dynamic-caching.xml"); + + svc = (GridSpringDynamicCacheTestService)factory.getBean("testService"); + mgr = (CacheManager)factory.getBean("cacheManager"); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + grid().cache(DATA_CACHE_NAME).removeAll(); + } + + /** + * @throws Exception If failed. + */ + public void testNames() throws Exception { + assertEquals("value1", svc.cacheable(1)); + + Collection<String> names = mgr.getCacheNames(); + + assertEquals(names.toString(), 2, names.size()); + } + + /** + * @throws Exception If failed. + */ + public void testCacheAndEvict() throws Exception { + GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); + + assertEquals("value1", svc.cacheable(1)); + + assertEquals(2, c.size()); + + assertEquals("value1", c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + + svc.cacheEvict(1); + + assertEquals(1, c.size()); + + assertEquals(null, c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + } + + /** + * @throws Exception If failed. + */ + public void testPutAndEvict() throws Exception { + GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); + + assertEquals("value1", svc.cachePut(1)); + + assertEquals(2, c.size()); + + assertEquals("value1", c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + + svc.cacheEvict(1); + + assertEquals(1, c.size()); + + assertEquals(null, c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + } + + /** + * @throws Exception If failed. + */ + public void testCacheAndEvictAll() throws Exception { + GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); + + assertEquals("value1", svc.cacheable(1)); + assertEquals("value2", svc.cacheable(2)); + + assertEquals(4, c.size()); + + assertEquals("value1", c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + assertEquals("value2", c.get(key("testCache1", 2))); + assertEquals("value2", c.get(key("testCache2", 2))); + + svc.cacheEvictAll(); + + assertEquals(2, c.size()); + + assertEquals(null, c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + assertEquals(null, c.get(key("testCache1", 2))); + assertEquals("value2", c.get(key("testCache2", 2))); + } + + + /** + * @throws Exception If failed. + */ + public void testPutAndEvictAll() throws Exception { + GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); + + assertEquals("value1", svc.cachePut(1)); + assertEquals("value2", svc.cachePut(2)); + + assertEquals(4, c.size()); + + assertEquals("value1", c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + assertEquals("value2", c.get(key("testCache1", 2))); + assertEquals("value2", c.get(key("testCache2", 2))); + + svc.cacheEvictAll(); + + assertEquals(2, c.size()); + + assertEquals(null, c.get(key("testCache1", 1))); + assertEquals("value1", c.get(key("testCache2", 1))); + assertEquals(null, c.get(key("testCache1", 2))); + assertEquals("value2", c.get(key("testCache2", 2))); + } + + /** + * @param cacheName Cache name. + * @param key Key. + * @return Data key. + * @throws Exception In case of error. + */ + private Object key(String cacheName, int key) throws Exception { + Class<?> cls = Class.forName(GridSpringDynamicCacheManager.class.getName() + "$DataKey"); + + Constructor<?> cons = cls.getDeclaredConstructor(String.class, Object.class); + + cons.setAccessible(true); + + return cons.newInstance(cacheName, key); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheTestService.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheTestService.java b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheTestService.java new file mode 100644 index 0000000..c6043c6 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/GridSpringDynamicCacheTestService.java @@ -0,0 +1,62 @@ +/* + * 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; + +import org.springframework.cache.annotation.*; + +/** + * Test service. + */ +public class GridSpringDynamicCacheTestService { + /** + * @param key Key. + * @return Value. + */ + @Cacheable({"testCache1", "testCache2"}) + public String cacheable(Integer key) { + assert key != null; + + return "value" + key; + } + + /** + * @param key Key. + * @return Value. + */ + @CachePut({"testCache1", "testCache2"}) + public String cachePut(Integer key) { + assert key != null; + + return "value" + key; + } + + /** + * @param key Key. + */ + @CacheEvict("testCache1") + public void cacheEvict(Integer key) { + // No-op. + } + + /** + */ + @CacheEvict(value = "testCache1", allEntries = true) + public void cacheEvictAll() { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/spring-caching.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/spring-caching.xml b/modules/spring/src/test/java/org/apache/ignite/spring/spring-caching.xml new file mode 100644 index 0000000..5cb08d5 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/spring-caching.xml @@ -0,0 +1,47 @@ +<?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" + xmlns:cache="http://www.springframework.org/schema/cache" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> + <!-- + Test service with cacheable methods. + --> + <bean id="testService" class="org.apache.ignite.spring.GridSpringCacheTestService"/> + + <!-- + Cache manager. + --> + <bean id="cacheManager" class="org.apache.ignite.cache.spring.GridSpringCacheManager"> + <property name="gridName" value="testGrid"/> + </bean> + + <!-- + Key generator. + --> + <bean id="keyGenerator" class="org.apache.ignite.spring.GridSpringCacheTestKeyGenerator"/> + + <!-- + Enable annotation-driver configuration for caching. + --> + <cache:annotation-driven key-generator="keyGenerator"/> +</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/spring/spring-dynamic-caching.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/spring-dynamic-caching.xml b/modules/spring/src/test/java/org/apache/ignite/spring/spring-dynamic-caching.xml new file mode 100644 index 0000000..63c7dad --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/spring-dynamic-caching.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" + xmlns:cache="http://www.springframework.org/schema/cache" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> + <!-- + Test service with cacheable methods. + --> + <bean id="testService" class="org.apache.ignite.spring.GridSpringDynamicCacheTestService"/> + + <!-- + Cache manager. + --> + <bean id="cacheManager" class="org.apache.ignite.cache.spring.GridSpringDynamicCacheManager"> + <property name="gridName" value="testGrid"/> + <property name="dataCacheName" value="data"/> + </bean> + + <!-- + Enable annotation-driver configuration for caching. + --> + <cache:annotation-driven/> +</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/apache/ignite/testsuites/bamboo/GridSpringTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/testsuites/bamboo/GridSpringTestSuite.java b/modules/spring/src/test/java/org/apache/ignite/testsuites/bamboo/GridSpringTestSuite.java index ddb21a8..3f0a9e7 100644 --- a/modules/spring/src/test/java/org/apache/ignite/testsuites/bamboo/GridSpringTestSuite.java +++ b/modules/spring/src/test/java/org/apache/ignite/testsuites/bamboo/GridSpringTestSuite.java @@ -18,10 +18,11 @@ package org.apache.ignite.testsuites.bamboo; import junit.framework.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.p2p.*; +import org.apache.ignite.spring.*; import org.apache.ignite.testsuites.*; import org.gridgain.grid.cache.spring.*; -import org.gridgain.grid.kernal.*; -import org.gridgain.grid.p2p.*; /** * Spring tests. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheManagerSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheManagerSelfTest.java deleted file mode 100644 index 4e81739..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheManagerSelfTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -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.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.testframework.junits.common.*; -import org.springframework.beans.factory.*; -import org.springframework.context.support.*; - -/** - * Spring cache test. - */ -public class GridSpringCacheManagerSelfTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** */ - private static final String CACHE_NAME = "testCache"; - - /** */ - private GridSpringCacheTestService svc; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration cache = new CacheConfiguration(); - - cache.setName(CACHE_NAME); - - cfg.setCacheConfiguration(cache); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(disco); - - return cfg; - } - - /** {@inheritDoc} */ - @Override public String getTestGridName() { - return "testGrid"; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - BeanFactory factory = new ClassPathXmlApplicationContext("org/gridgain/grid/cache/spring/spring-caching.xml"); - - svc = (GridSpringCacheTestService)factory.getBean("testService"); - - svc.reset(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - grid().cache(CACHE_NAME).removeAll(); - } - - /** - * @throws Exception If failed. - */ - public void testSimpleKey() throws Exception { - for (int i = 0; i < 3; i++) { - assertEquals("value" + i, svc.simpleKey(i)); - assertEquals("value" + i, svc.simpleKey(i)); - } - - assertEquals(3, svc.called()); - - GridCache<Integer, String> c = grid().cache(CACHE_NAME); - - assertEquals(3, c.size()); - - for (int i = 0; i < 3; i++) - assertEquals("value" + i, c.get(i)); - } - - /** - * @throws Exception If failed. - */ - public void testComplexKey() throws Exception { - for (int i = 0; i < 3; i++) { - assertEquals("value" + i + "suffix" + i, svc.complexKey(i, "suffix" + i)); - assertEquals("value" + i + "suffix" + i, svc.complexKey(i, "suffix" + i)); - } - - assertEquals(3, svc.called()); - - GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); - - assertEquals(3, c.size()); - - for (int i = 0; i < 3; i++) - assertEquals("value" + i + "suffix" + i, c.get(new GridSpringCacheTestKey(i, "suffix" + i))); - } - - /** - * @throws Exception If failed. - */ - public void testSimpleKeyPut() throws Exception { - GridCache<Integer, String> c = grid().cache(CACHE_NAME); - - for (int i = 0; i < 3; i++) { - assertEquals("value" + i + "odd", svc.simpleKeyPut(i)); - - assertEquals(i + 1, c.size()); - assertEquals("value" + i + "odd", c.get(i)); - - assertEquals("value" + i + "even", svc.simpleKeyPut(i)); - - assertEquals(i + 1, c.size()); - assertEquals("value" + i + "even", c.get(i)); - } - - assertEquals(6, svc.called()); - } - - /** - * @throws Exception If failed. - */ - public void testComplexKeyPut() throws Exception { - GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); - - for (int i = 0; i < 3; i++) { - assertEquals("value" + i + "suffix" + i + "odd", svc.complexKeyPut(i, "suffix" + i)); - - assertEquals(i + 1, c.size()); - assertEquals("value" + i + "suffix" + i + "odd", c.get(new GridSpringCacheTestKey(i, "suffix" + i))); - - assertEquals("value" + i + "suffix" + i + "even", svc.complexKeyPut(i, "suffix" + i)); - - assertEquals(i + 1, c.size()); - assertEquals("value" + i + "suffix" + i + "even", c.get(new GridSpringCacheTestKey(i, "suffix" + i))); - } - - assertEquals(6, svc.called()); - } - - /** - * @throws Exception If failed. - */ - public void testSimpleKeyEvict() throws Exception { - GridCache<Integer, String> c = grid().cache(CACHE_NAME); - - for (int i = 0; i < 3; i++) - c.putx(i, "value" + i); - - assertEquals(3, c.size()); - - assertEquals("value0", c.get(0)); - assertEquals("value1", c.get(1)); - assertEquals("value2", c.get(2)); - - svc.simpleKeyEvict(2); - - assertEquals(2, c.size()); - - assertEquals("value0", c.get(0)); - assertEquals("value1", c.get(1)); - assertNull(c.get(2)); - } - - /** - * @throws Exception If failed. - */ - public void testComplexKeyEvict() throws Exception { - GridCache<GridSpringCacheTestKey, String> c = grid().cache(CACHE_NAME); - - for (int i = 0; i < 3; i++) - c.putx(new GridSpringCacheTestKey(i, "suffix" + i), "value" + i); - - assertEquals(3, c.size()); - - assertEquals("value0", c.get(new GridSpringCacheTestKey(0, "suffix" + 0))); - assertEquals("value1", c.get(new GridSpringCacheTestKey(1, "suffix" + 1))); - assertEquals("value2", c.get(new GridSpringCacheTestKey(2, "suffix" + 2))); - - svc.complexKeyEvict(2, "suffix" + 2); - - assertEquals(2, c.size()); - - assertEquals("value0", c.get(new GridSpringCacheTestKey(0, "suffix" + 0))); - assertEquals("value1", c.get(new GridSpringCacheTestKey(1, "suffix" + 1))); - assertNull(c.get(new GridSpringCacheTestKey(2, "suffix" + 2))); - } - - /** - * @throws Exception If failed. - */ - public void testEvictAll() throws Exception { - GridCache<Integer, String> c = grid().cache(CACHE_NAME); - - for (int i = 0; i < 3; i++) - c.putx(i, "value" + i); - - assertEquals(3, c.size()); - - assertEquals("value0", c.get(0)); - assertEquals("value1", c.get(1)); - assertEquals("value2", c.get(2)); - - svc.evictAll(); - - assertEquals(0, c.size()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKey.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKey.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKey.java deleted file mode 100644 index 71f538c..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKey.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -/** - * Complex key. - */ -public class GridSpringCacheTestKey { - /** */ - private final Integer p1; - - /** */ - private final String p2; - - /** - * @param p1 Parameter 1. - * @param p2 Parameter 2. - */ - public GridSpringCacheTestKey(Integer p1, String p2) { - assert p1 != null; - assert p2 != null; - - this.p1 = p1; - this.p2 = p2; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - GridSpringCacheTestKey key = (GridSpringCacheTestKey)o; - - return p1.equals(key.p1) && p2.equals(key.p2); - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return 31 * p1 + p2.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKeyGenerator.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKeyGenerator.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKeyGenerator.java deleted file mode 100644 index 733a06b..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestKeyGenerator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -import org.springframework.cache.interceptor.*; - -import java.lang.reflect.*; - -/** - * Key generator. - */ -public class GridSpringCacheTestKeyGenerator implements KeyGenerator { - /** {@inheritDoc} */ - @Override public Object generate(Object target, Method mtd, Object... params) { - assert params != null; - assert params.length > 0; - - if (params.length == 1) - return params[0]; - else { - assert params.length == 2; - - return new GridSpringCacheTestKey((Integer)params[0], (String)params[1]); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestService.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestService.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestService.java deleted file mode 100644 index cc5e2a4..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringCacheTestService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -import org.springframework.cache.annotation.*; - -import java.util.concurrent.atomic.*; - -/** - * Test service. - */ -public class GridSpringCacheTestService { - /** */ - private final AtomicInteger cnt = new AtomicInteger(); - - /** - * @return How many times service was called. - */ - public int called() { - return cnt.get(); - } - - /** - * Resets service. - */ - public void reset() { - cnt.set(0); - } - - /** - * @param key Key. - * @return Value. - */ - @Cacheable("testCache") - public String simpleKey(Integer key) { - assert key != null; - - cnt.incrementAndGet(); - - return "value" + key; - } - - /** - * @param p1 Parameter 1. - * @param p2 Parameter 2. - * @return Value. - */ - @Cacheable("testCache") - public String complexKey(Integer p1, String p2) { - assert p1 != null; - assert p2 != null; - - cnt.incrementAndGet(); - - return "value" + p1 + p2; - } - - /** - * @param key Key. - * @return Value. - */ - @CachePut("testCache") - public String simpleKeyPut(Integer key) { - assert key != null; - - int cnt0 = cnt.incrementAndGet(); - - return "value" + key + (cnt0 % 2 == 0 ? "even" : "odd"); - } - - /** - * @param p1 Parameter 1. - * @param p2 Parameter 2. - * @return Value. - */ - @CachePut("testCache") - public String complexKeyPut(Integer p1, String p2) { - assert p1 != null; - assert p2 != null; - - int cnt0 = cnt.incrementAndGet(); - - return "value" + p1 + p2 + (cnt0 % 2 == 0 ? "even" : "odd"); - } - - /** - * @param key Key. - */ - @CacheEvict("testCache") - public void simpleKeyEvict(Integer key) { - // No-op. - } - - /** - * @param p1 Parameter 1. - * @param p2 Parameter 2. - */ - @CacheEvict("testCache") - public void complexKeyEvict(Integer p1, String p2) { - // No-op. - } - - /** - */ - @CacheEvict(value = "testCache", allEntries = true) - public void evictAll() { - // No-op. - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheManagerSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheManagerSelfTest.java deleted file mode 100644 index c634cea..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheManagerSelfTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -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.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.testframework.junits.common.*; -import org.springframework.beans.factory.*; -import org.springframework.cache.*; -import org.springframework.context.support.*; - -import java.lang.reflect.*; -import java.util.*; - -/** - * Spring cache test. - */ -public class GridSpringDynamicCacheManagerSelfTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** */ - private static final String DATA_CACHE_NAME = "data"; - - /** */ - private GridSpringDynamicCacheTestService svc; - - /** */ - private CacheManager mgr; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration cache = new CacheConfiguration(); - - cache.setName(DATA_CACHE_NAME); - - cfg.setCacheConfiguration(cache); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(disco); - - return cfg; - } - - /** {@inheritDoc} */ - @Override public String getTestGridName() { - return "testGrid"; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - BeanFactory factory = new ClassPathXmlApplicationContext( - "org/gridgain/grid/cache/spring/spring-dynamic-caching.xml"); - - svc = (GridSpringDynamicCacheTestService)factory.getBean("testService"); - mgr = (CacheManager)factory.getBean("cacheManager"); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - grid().cache(DATA_CACHE_NAME).removeAll(); - } - - /** - * @throws Exception If failed. - */ - public void testNames() throws Exception { - assertEquals("value1", svc.cacheable(1)); - - Collection<String> names = mgr.getCacheNames(); - - assertEquals(names.toString(), 2, names.size()); - } - - /** - * @throws Exception If failed. - */ - public void testCacheAndEvict() throws Exception { - GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); - - assertEquals("value1", svc.cacheable(1)); - - assertEquals(2, c.size()); - - assertEquals("value1", c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - - svc.cacheEvict(1); - - assertEquals(1, c.size()); - - assertEquals(null, c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - } - - /** - * @throws Exception If failed. - */ - public void testPutAndEvict() throws Exception { - GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); - - assertEquals("value1", svc.cachePut(1)); - - assertEquals(2, c.size()); - - assertEquals("value1", c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - - svc.cacheEvict(1); - - assertEquals(1, c.size()); - - assertEquals(null, c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - } - - /** - * @throws Exception If failed. - */ - public void testCacheAndEvictAll() throws Exception { - GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); - - assertEquals("value1", svc.cacheable(1)); - assertEquals("value2", svc.cacheable(2)); - - assertEquals(4, c.size()); - - assertEquals("value1", c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - assertEquals("value2", c.get(key("testCache1", 2))); - assertEquals("value2", c.get(key("testCache2", 2))); - - svc.cacheEvictAll(); - - assertEquals(2, c.size()); - - assertEquals(null, c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - assertEquals(null, c.get(key("testCache1", 2))); - assertEquals("value2", c.get(key("testCache2", 2))); - } - - - /** - * @throws Exception If failed. - */ - public void testPutAndEvictAll() throws Exception { - GridCache<Object, String> c = grid().cache(DATA_CACHE_NAME); - - assertEquals("value1", svc.cachePut(1)); - assertEquals("value2", svc.cachePut(2)); - - assertEquals(4, c.size()); - - assertEquals("value1", c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - assertEquals("value2", c.get(key("testCache1", 2))); - assertEquals("value2", c.get(key("testCache2", 2))); - - svc.cacheEvictAll(); - - assertEquals(2, c.size()); - - assertEquals(null, c.get(key("testCache1", 1))); - assertEquals("value1", c.get(key("testCache2", 1))); - assertEquals(null, c.get(key("testCache1", 2))); - assertEquals("value2", c.get(key("testCache2", 2))); - } - - /** - * @param cacheName Cache name. - * @param key Key. - * @return Data key. - * @throws Exception In case of error. - */ - private Object key(String cacheName, int key) throws Exception { - Class<?> cls = Class.forName(GridSpringDynamicCacheManager.class.getName() + "$DataKey"); - - Constructor<?> cons = cls.getDeclaredConstructor(String.class, Object.class); - - cons.setAccessible(true); - - return cons.newInstance(cacheName, key); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheTestService.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheTestService.java b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheTestService.java deleted file mode 100644 index 9c4accd..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/GridSpringDynamicCacheTestService.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.gridgain.grid.cache.spring; - -import org.springframework.cache.annotation.*; - -/** - * Test service. - */ -public class GridSpringDynamicCacheTestService { - /** - * @param key Key. - * @return Value. - */ - @Cacheable({"testCache1", "testCache2"}) - public String cacheable(Integer key) { - assert key != null; - - return "value" + key; - } - - /** - * @param key Key. - * @return Value. - */ - @CachePut({"testCache1", "testCache2"}) - public String cachePut(Integer key) { - assert key != null; - - return "value" + key; - } - - /** - * @param key Key. - */ - @CacheEvict("testCache1") - public void cacheEvict(Integer key) { - // No-op. - } - - /** - */ - @CacheEvict(value = "testCache1", allEntries = true) - public void cacheEvictAll() { - // No-op. - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-caching.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-caching.xml b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-caching.xml deleted file mode 100644 index 64ad4b3..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-caching.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?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" - xmlns:cache="http://www.springframework.org/schema/cache" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> - <!-- - Test service with cacheable methods. - --> - <bean id="testService" class="org.gridgain.grid.cache.spring.GridSpringCacheTestService"/> - - <!-- - Cache manager. - --> - <bean id="cacheManager" class="org.gridgain.grid.cache.spring.GridSpringCacheManager"> - <property name="gridName" value="testGrid"/> - </bean> - - <!-- - Key generator. - --> - <bean id="keyGenerator" class="org.gridgain.grid.cache.spring.GridSpringCacheTestKeyGenerator"/> - - <!-- - Enable annotation-driver configuration for caching. - --> - <cache:annotation-driven key-generator="keyGenerator"/> -</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0e6cace/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-dynamic-caching.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-dynamic-caching.xml b/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-dynamic-caching.xml deleted file mode 100644 index ef2f80b..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/cache/spring/spring-dynamic-caching.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?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" - xmlns:cache="http://www.springframework.org/schema/cache" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> - <!-- - Test service with cacheable methods. - --> - <bean id="testService" class="org.gridgain.grid.cache.spring.GridSpringDynamicCacheTestService"/> - - <!-- - Cache manager. - --> - <bean id="cacheManager" class="org.gridgain.grid.cache.spring.GridSpringDynamicCacheManager"> - <property name="gridName" value="testGrid"/> - <property name="dataCacheName" value="data"/> - </bean> - - <!-- - Enable annotation-driver configuration for caching. - --> - <cache:annotation-driven/> -</beans>