You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/09/27 11:17:24 UTC

[5/7] ignite git commit: ignite-3601

ignite-3601


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

Branch: refs/heads/ignite-3601p
Commit: d2cfe0ea5f0c00c57c7b66b904a578ad2524c464
Parents: 24a884c
Author: sboikov <sb...@gridgain.com>
Authored: Mon Sep 19 17:56:24 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon Sep 19 17:56:24 2016 +0300

----------------------------------------------------------------------
 .../colocated/GridDhtDetachedCacheEntry.java    |   5 +
 .../transactions/IgniteTxLocalAdapter.java      |  13 +-
 .../cache/CachePutIfAbsentTestTest.java         | 222 +++----------------
 .../CacheSerializableTransactionsTest.java      |  66 ++----
 4 files changed, 62 insertions(+), 244 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d2cfe0ea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
index db91134..2e05560 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
@@ -97,4 +97,9 @@ public class GridDhtDetachedCacheEntry extends GridDistributedCacheEntry {
         // No-op for detached cache entry.
         return true;
     }
+
+    /** {@inheritDoc} */
+    @Override public int partition() {
+        return cctx.affinity().partition(key);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d2cfe0ea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 637f322..b29e875 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -2286,7 +2286,18 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
                             addInvokeResult(e, cacheVal, ret, ver);
                         }
                         else {
-                            boolean success = !hasFilters || isAll(e.context(), key, cacheVal, filter);
+                            boolean success;
+
+                            if (hasFilters) {
+                                success = isAll(e.context(), key, cacheVal, filter);
+
+                                if (!success) {
+                                    e.op(READ);
+                                    e.value(cacheVal, false, false);
+                                }
+                            }
+                            else
+                                success = true;
 
                             ret.set(cacheCtx, cacheVal, success, keepBinary);
                         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d2cfe0ea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CachePutIfAbsentTestTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CachePutIfAbsentTestTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CachePutIfAbsentTestTest.java
index 42902a8..73af507 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CachePutIfAbsentTestTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CachePutIfAbsentTestTest.java
@@ -17,43 +17,28 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteTransactions;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.util.typedef.G;
-import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.spi.swapspace.inmemory.GridTestSwapSpaceSpi;
-import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
-import org.jsr166.ConcurrentHashMap8;
-
-import javax.cache.Cache;
-import javax.cache.configuration.Factory;
-import javax.cache.integration.CacheLoaderException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 import static org.apache.ignite.cache.CacheMode.PARTITIONED;
 import static org.apache.ignite.cache.CacheMode.REPLICATED;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE;
 
 /**
  *
@@ -63,34 +48,14 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
     private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
 
     /** */
-    private static final boolean FAST = false;
-
-    /** */
-    private static Map<Integer, Integer> storeMap = new ConcurrentHashMap8<>();
-
-    /** */
     private static final int SRVS = 4;
 
-    /** */
-    private static final int CLIENTS = 3;
-
-    /** */
-    private boolean client;
-
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        cfg.setPeerClassLoadingEnabled(false);
-
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
-        ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
-
-        cfg.setClientMode(client);
-
-        cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi());
-
         return cfg;
     }
 
@@ -99,12 +64,6 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
         super.beforeTestsStarted();
 
         startGridsMultiThreaded(SRVS);
-
-        client = true;
-
-        startGridsMultiThreaded(SRVS, CLIENTS);
-
-        client = false;
     }
 
     /** {@inheritDoc} */
@@ -125,36 +84,11 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
     private List<CacheConfiguration<Integer, Integer>> cacheConfigurations() {
         List<CacheConfiguration<Integer, Integer>> ccfgs = new ArrayList<>();
 
-        // No store, no near.
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, false, false));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 2, false, false));
-        ccfgs.add(cacheConfiguration(REPLICATED, FULL_SYNC, 0, false, false));
-
-        // Store, no near.
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, true, false));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 2, true, false));
-        ccfgs.add(cacheConfiguration(REPLICATED, FULL_SYNC, 0, true, false));
-
-        // No store, near.
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, false, true));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, true));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 2, false, true));
-
-        // Store, near.
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, true, true));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, true));
-        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 2, true, true));
-
-        // Swap and offheap enabled.
-        for (GridTestUtils.TestMemoryMode memMode : GridTestUtils.TestMemoryMode.values()) {
-            CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
+        ccfgs.add(cacheConfiguration(REPLICATED, FULL_SYNC, 0));
 
-            GridTestUtils.setMemoryMode(null, ccfg, memMode, 1, 64);
-
-            ccfgs.add(ccfg);
-        }
+        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0));
+        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1));
+        ccfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 2));
 
         return ccfgs;
     }
@@ -163,16 +97,12 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
      * @param cacheMode Cache mode.
      * @param syncMode Write synchronization mode.
      * @param backups Number of backups.
-     * @param storeEnabled If {@code true} adds cache store.
-     * @param nearCache If {@code true} near cache is enabled.
      * @return Cache configuration.
      */
     private CacheConfiguration<Integer, Integer> cacheConfiguration(
         CacheMode cacheMode,
         CacheWriteSynchronizationMode syncMode,
-        int backups,
-        boolean storeEnabled,
-        boolean nearCache) {
+        int backups) {
         CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>();
 
         ccfg.setCacheMode(cacheMode);
@@ -182,15 +112,6 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
         if (cacheMode == PARTITIONED)
             ccfg.setBackups(backups);
 
-        if (storeEnabled) {
-            ccfg.setCacheStoreFactory(new TestStoreFactory());
-            ccfg.setWriteThrough(true);
-            ccfg.setReadThrough(true);
-        }
-
-        if (nearCache)
-            ccfg.setNearConfiguration(new NearCacheConfiguration<Integer, Integer>());
-
         return ccfg;
     }
 
@@ -206,124 +127,35 @@ public class CachePutIfAbsentTestTest extends GridCommonAbstractTest {
             try {
                 IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
 
-                Integer key = getNoneLocalKey(ignite0, cache);
-
-                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
-                    Object old = cache.getAndPutIfAbsent(key, 2);
-
-                    assertNull(old);
-
-                    tx.commit();
-                }
-
-                Object val = cache.get(key);
-
-                info("Val: " + val);
-
-                assertEquals(2, val);
-
-                Object old = cache.getAndPutIfAbsent(key, 3);
+                ThreadLocalRandom rnd = ThreadLocalRandom.current();
 
-                assertEquals(2, old);
+                for (int i = 0; i < 10; i++) {
+                    Integer key = rnd.nextInt(10_000);
 
-                val = cache.get(key);
+                    cache.put(key, 2);
 
-                info("Val: " + val);
+                    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
+                        for (TransactionIsolation isolation : TransactionIsolation.values()) {
+                            try (Transaction tx = txs.txStart(concurrency, isolation)) {
+                                Object old = cache.getAndPutIfAbsent(key, 3);
 
-                assertEquals(2, val);
+                                assertEquals(2, old);
 
-                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
-                    old = cache.getAndPutIfAbsent(key, 3);
+                                Object val = cache.get(key);
 
-                    info("Val: " + old);
+                                assertEquals(2, val);
 
-                    assertEquals(2, old);
+                                tx.commit();
+                            }
 
-                    val = cache.get(key);
-
-                    info("Val: " + val);
-
-//                    assertEquals(val, old);
-
-                    tx.commit();
+                            assertEquals((Integer)2, cache.get(key));
+                        }
+                    }
                 }
-
-                info("Val: " + cache.get(key));
-
-                assertEquals(val, old);
             }
             finally {
-                destroyCache(ccfg.getName());
+                ignite0.destroyCache(ccfg.getName());
             }
         }
     }
-
-    /**
-     * @param ignite Ignite.
-     * @param cache Cache.
-     */
-    private Integer getNoneLocalKey(Ignite ignite, IgniteCache cache) {
-        for (int i =0; i<100; i++)
-            if (!isKeyLocal(ignite, cache, i))
-                return i;
-
-        fail("Can't find none local key.");
-
-        return null;
-    }
-
-    /**
-     * Checks, whether the key is stored locally.
-     * @param ignite Ignite 0.
-     * @param cache Cache.
-     * @param key Key.
-     */
-    private boolean isKeyLocal(Ignite ignite, IgniteCache cache, Integer key) {
-        return ((TcpDiscoveryNode)((ArrayList)ignite.affinity(cache.getName())
-            .mapKeyToPrimaryAndBackups(ignite.affinity(cache.getName()).affinityKey(key)))
-            .get(0)).id().equals(((IgniteKernal)ignite).getLocalNodeId());
-    }
-
-    /**
-     * @param cacheName Cache name.
-     */
-    private void destroyCache(String cacheName) {
-        storeMap.clear();
-
-        for (Ignite ignite : G.allGrids()) {
-            try {
-                ignite.destroyCache(cacheName);
-            }
-            catch (IgniteException ignore) {
-                // No-op.
-            }
-
-            GridTestSwapSpaceSpi spi = (GridTestSwapSpaceSpi)ignite.configuration().getSwapSpaceSpi();
-
-            spi.clearAll();
-        }
-    }
-
-
-    /**
-     *
-     */
-    private static class TestStoreFactory implements Factory<CacheStore<Integer, Integer>> {
-        /** {@inheritDoc} */
-        @Override public CacheStore<Integer, Integer> create() {
-            return new CacheStoreAdapter<Integer, Integer>() {
-                @Override public Integer load(Integer key) throws CacheLoaderException {
-                    return storeMap.get(key);
-                }
-
-                @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) {
-                    storeMap.put(entry.getKey(), entry.getValue());
-                }
-
-                @Override public void delete(Object key) {
-                    storeMap.remove(key);
-                }
-            };
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d2cfe0ea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
index f855991..e3d321c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
@@ -56,7 +56,6 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.G;
@@ -66,7 +65,6 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteClosure;
 import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.spi.swapspace.inmemory.GridTestSwapSpaceSpi;
@@ -1358,26 +1356,14 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest {
 
                     checkValue(key, 2, cache.getName());
 
-                    try {
-                        try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
-                            Object old = cache.getAndPutIfAbsent(key, 4);
-
-                            Object newValue = cache.get(key);
-
-                            assertEquals(2, old);
-
-                            assertEquals(old, newValue);
+                    try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                        Object old = cache.getAndPutIfAbsent(key, 4);
 
-                            updateKey(cache, key, 3);
+                        assertEquals(2, old);
 
-                            tx.commit();
-                        }
+                        updateKey(cache, key, 3);
 
-                        log.info("Read only optimistic commit.");
-                    }
-                    catch (TransactionOptimisticException e) {
-                        log.info("Expected exception: " + e);
-                        fail();
+                        tx.commit();
                     }
 
                     checkValue(key, 3, cache.getName());
@@ -2632,22 +2618,14 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest {
             cache0.put(key2, -1);
             cache0.put(key3, -1);
 
-            try {
-                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
-                    cache.get(key1);
-                    cache.get(key2);
-                    cache.get(key3);
+            try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                cache.get(key1);
+                cache.get(key2);
+                cache.get(key3);
 
-                    updateKey(near ? cache : cache0, key2, -2);
+                updateKey(near ? cache : cache0, key2, -2);
 
-                    tx.commit();
-                }
-
-                log.info("Read only optimistic commit.");
-            }
-            catch (TransactionOptimisticException e) {
-                log.info("Expected exception: " + e);
-                fail();
+                tx.commit();
             }
 
             checkValue(key1, -1, cacheName);
@@ -2898,24 +2876,16 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest {
                 checkValue(key1, newVal, CACHE1);
                 checkValue(key2, newVal, CACHE2);
 
-                try {
-                    try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
-                        Object val1 = cache1.get(key1);
-                        Object val2 = cache2.get(key2);
-
-                        assertEquals(newVal, val1);
-                        assertEquals(newVal, val2);
+                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                    Object val1 = cache1.get(key1);
+                    Object val2 = cache2.get(key2);
 
-                        updateKey(cache2, key2, newVal);
+                    assertEquals(newVal, val1);
+                    assertEquals(newVal, val2);
 
-                        tx.commit();
-                    }
+                    updateKey(cache2, key2, newVal);
 
-                    log.info("Read only optimistic commit.");
-                }
-                catch (TransactionOptimisticException e) {
-                    log.info("Expected exception: " + e);
-                    fail();
+                    tx.commit();
                 }
 
                 try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {