ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [26/50] [abbrv] ignite git commit: IGNITE-4823 - Fixed SpringCache#putIfAbsent implementation. This fixes #1624.
Date Thu, 06 Apr 2017 09:32:17 GMT
IGNITE-4823 - Fixed SpringCache#putIfAbsent implementation. This fixes #1624.


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

Branch: refs/heads/ignite-4003
Commit: f66be1af78137af9306d2665a7d4a6eb062db2e5
Parents: b43dd2b
Author: Vyacheslav Daradur <daradurvs@gmail.com>
Authored: Fri Mar 31 21:55:04 2017 -0700
Committer: Valentin Kulichenko <valentin.lulichenko@gmail.com>
Committed: Fri Mar 31 21:55:04 2017 -0700

----------------------------------------------------------------------
 .../apache/ignite/cache/spring/SpringCache.java |   4 +-
 .../ignite/cache/spring/SpringCacheTest.java    | 177 +++++++++++++++++++
 .../testsuites/IgniteSpringTestSuite.java       |   3 +
 3 files changed, 182 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f66be1af/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCache.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCache.java
b/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCache.java
index afd060a..77b30c5 100644
--- a/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCache.java
+++ b/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCache.java
@@ -86,9 +86,9 @@ class SpringCache implements Cache {
         Object old;
 
         if (val == null)
-            old = cache.withSkipStore().putIfAbsent(key, NULL);
+            old = cache.withSkipStore().getAndPutIfAbsent(key, NULL);
         else
-            old = cache.putIfAbsent(key, val);
+            old = cache.getAndPutIfAbsent(key, val);
 
         return old != null ? fromValue(old) : null;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f66be1af/modules/spring/src/test/java/org/apache/ignite/cache/spring/SpringCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/cache/spring/SpringCacheTest.java
b/modules/spring/src/test/java/org/apache/ignite/cache/spring/SpringCacheTest.java
new file mode 100644
index 0000000..2324235
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/cache/spring/SpringCacheTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.cache.spring;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests for {@link SpringCache}
+ */
+public class SpringCacheTest extends GridCommonAbstractTest {
+    /** */
+    private static Ignite ignite;
+
+    /** Wrapped cache. */
+    private IgniteCache nativeCache;
+
+    /** Working cache. */
+    private SpringCache springCache;
+
+    /** */
+    private String cacheName;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        ignite = startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        G.stop(true);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        cacheName = String.valueOf(System.currentTimeMillis());
+        nativeCache = ignite.getOrCreateCache(cacheName);
+        springCache = new SpringCache(nativeCache);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        ignite.destroyCache(cacheName);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetName() throws Exception {
+        assertEquals(cacheName, springCache.getName());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetNativeCache() throws Exception {
+        assertEquals(nativeCache, springCache.getNativeCache());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetByKey() throws Exception {
+        String key = "key";
+        String value = "value";
+
+        springCache.put(key, value);
+        assertEquals(value, springCache.get(key).get());
+
+        assertNull(springCache.get("wrongKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetByKeyType() throws Exception {
+        String key = "key";
+        String value = "value";
+
+        springCache.put(key, value);
+        assertEquals(value, springCache.get(key, String.class));
+
+        try {
+            springCache.get(key, Integer.class);
+            fail("Missing exception");
+        }
+        catch (Exception e) {
+            assertTrue(e.getMessage().startsWith("Cached value is not of required type [cacheName="
+ cacheName));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPut() throws Exception {
+        String key = "key";
+        assertNull(springCache.get(key));
+
+        String value = "value";
+        springCache.put(key, value);
+
+        assertEquals(value, springCache.get(key).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutIfAbsent() throws Exception {
+        String key = "key";
+        String expected = "value";
+
+        assertNull(springCache.putIfAbsent(key, expected));
+
+        assertEquals(expected, springCache.putIfAbsent(key, "wrongValue").get());
+
+        assertEquals(expected, springCache.get(key).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEvict() throws Exception {
+        String key = "key";
+        assertNull(springCache.get(key));
+
+        springCache.put(key, "value");
+        assertNotNull(springCache.get(key));
+
+        springCache.evict(key);
+        assertNull(springCache.get(key));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClear() throws Exception {
+        String key;
+        springCache.put((key = "key1"), "value1");
+        assertNotNull(springCache.get(key));
+        springCache.put((key = "key2"), "value2");
+        assertNotNull(springCache.get(key));
+        springCache.put((key = "key3"), "value3");
+        assertNotNull(springCache.get(key));
+
+        springCache.clear();
+
+        assertNull(springCache.get("key1"));
+        assertNull(springCache.get("key2"));
+        assertNull(springCache.get("key3"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f66be1af/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
index 671d339..9ebb784 100644
--- a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
+++ b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.cache.spring.GridSpringCacheManagerSelfTest;
 import org.apache.ignite.cache.spring.SpringCacheManagerContextInjectionTest;
+import org.apache.ignite.cache.spring.SpringCacheTest;
 import org.apache.ignite.internal.IgniteSpringBeanTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactorySelfTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactorySelfTest;
@@ -82,6 +83,8 @@ public class IgniteSpringTestSuite extends TestSuite {
         suite.addTestSuite(SpringCacheManagerContextInjectionTest.class);
         suite.addTestSuite(SpringTransactionManagerContextInjectionTest.class);
 
+        suite.addTestSuite(SpringCacheTest.class);
+
         return suite;
     }
 }


Mime
View raw message