Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C0CF718DAC for ; Fri, 11 Dec 2015 04:29:06 +0000 (UTC) Received: (qmail 81767 invoked by uid 500); 11 Dec 2015 04:29:06 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 81684 invoked by uid 500); 11 Dec 2015 04:29:06 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 81310 invoked by uid 99); 11 Dec 2015 04:29:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Dec 2015 04:29:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 19C10E17EF; Fri, 11 Dec 2015 04:29:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Fri, 11 Dec 2015 04:29:10 -0000 Message-Id: <2d654c4cab214d8ab165b6f05c971568@git.apache.org> In-Reply-To: <8c6f60a4ba2b4c02acdd2c6f977a4ea6@git.apache.org> References: <8c6f60a4ba2b4c02acdd2c6f977a4ea6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/30] ignite git commit: ignite-2023 Fixed test to do not use hard-coded keys ignite-2023 Fixed test to do not use hard-coded keys Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6d7a6eaa Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6d7a6eaa Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6d7a6eaa Branch: refs/heads/ignite-843-rc2 Commit: 6d7a6eaaf6ab8be9aa10043841817a3944193b41 Parents: 6cdd580 Author: sboikov Authored: Thu Dec 10 12:17:50 2015 +0300 Committer: sboikov Committed: Thu Dec 10 12:17:50 2015 +0300 ---------------------------------------------------------------------- ...niteCacheClientNodeChangingTopologyTest.java | 125 +++++++++++++++++-- 1 file changed, 115 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6d7a6eaa/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java index 1e3382d..e7657a6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheClientNodeChangingTopologyTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache.distributed; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -43,16 +44,20 @@ import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteTransactions; import org.apache.ignite.cache.CacheAtomicWriteOrderMode; import org.apache.ignite.cache.affinity.Affinity; +import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.events.EventType; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.IgniteNodeAttributes; import org.apache.ignite.internal.managers.communication.GridIoMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; @@ -68,12 +73,14 @@ import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.resources.LoggerResource; import org.apache.ignite.spi.IgniteSpiException; 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.testframework.GridTestUtils; @@ -116,6 +123,8 @@ public class IgniteCacheClientNodeChangingTopologyTest extends GridCommonAbstrac @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); + cfg.setConsistentId(gridName); + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true); cfg.setClientMode(client); @@ -681,6 +690,93 @@ public class IgniteCacheClientNodeChangingTopologyTest extends GridCommonAbstrac } /** + * Tries to find keys for two partitions: for one partition assignment should not change after node join, + * for another primary node should change. + * + * @param ignite Ignite. + * @param nodes Current nodes. + * @return Found keys. + */ + private IgniteBiTuple findKeys(Ignite ignite, ClusterNode...nodes) { + ClusterNode newNode = new TcpDiscoveryNode(); + + GridTestUtils.setFieldValue(newNode, "consistentId", getTestGridName(4)); + GridTestUtils.setFieldValue(newNode, "id", UUID.randomUUID()); + + List topNodes = new ArrayList<>(); + + Collections.addAll(topNodes, nodes); + + topNodes.add(newNode); + + DiscoveryEvent discoEvt = new DiscoveryEvent(newNode, "", EventType.EVT_NODE_JOINED, newNode); + + final long topVer = ignite.cluster().topologyVersion(); + + GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(topNodes, + null, + discoEvt, + new AffinityTopologyVersion(topVer + 1), + 1); + + AffinityFunction affFunc = ignite.cache(null).getConfiguration(CacheConfiguration.class).getAffinity(); + + List> newAff = affFunc.assignPartitions(ctx); + + List> curAff = ((IgniteKernal)ignite).context().cache().internalCache(null).context(). + affinity().assignments(new AffinityTopologyVersion(topVer)); + + Integer key1 = null; + Integer key2 = null; + + Affinity aff = ignite.affinity(null); + + for (int i = 0; i < curAff.size(); i++) { + if (key1 == null) { + List oldNodes = curAff.get(i); + List newNodes = newAff.get(i); + + if (oldNodes.equals(newNodes)) + key1 = findKey(aff, i); + } + + if (key2 == null) { + ClusterNode oldPrimary = F.first(curAff.get(i)); + ClusterNode newPrimary = F.first(newAff.get(i)); + + if (!oldPrimary.equals(newPrimary)) + key2 = findKey(aff, i); + } + + if (key1 != null && key2 != null) + break; + } + + if (key1 == null || key2 == null) + fail("Failed to find nodes required for test."); + + return new IgniteBiTuple<>(key1, key2); + } + + /** + * @param aff Affinity. + * @param part Required key partition. + * @return Key. + */ + private Integer findKey(Affinity aff, int part) { + for (int i = 0; i < 10_000; i++) { + Integer key = i; + + if (aff.partition(key) == part) + return key; + } + + fail(); + + return null; + } + + /** * Tests specific scenario when mapping for first locked keys does not change, but changes for second one. * * @throws Exception If failed. @@ -710,8 +806,11 @@ public class IgniteCacheClientNodeChangingTopologyTest extends GridCommonAbstrac TestCommunicationSpi spi = (TestCommunicationSpi)ignite3.configuration().getCommunicationSpi(); - final Integer key1 = 0; - final Integer key2 = 7; + IgniteBiTuple keys = + findKeys(ignite0, ignite0.localNode(), ignite1.localNode(), ignite2.localNode()); + + final Integer key1 = keys.get1(); + final Integer key2 = keys.get2(); spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id()); spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id()); @@ -1168,22 +1267,28 @@ public class IgniteCacheClientNodeChangingTopologyTest extends GridCommonAbstrac IgniteCache cache = ignite3.cache(null); + Affinity aff = ignite0.affinity(null); + try (Transaction tx = ignite3.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { - cache.put(1, 1); - cache.put(2, 2); - cache.put(3, 3); + Integer key1 = findKey(aff, 1); + Integer key2 = findKey(aff, 2); + Integer key3 = findKey(aff, 3); + + cache.put(key1, 1); + cache.put(key2, 2); + cache.put(key3, 3); tx.commit(); } checkClientLockMessages(spi.recordedMessages(), 3); - Map map = new HashMap<>(); + Map map = new LinkedHashMap<>(); - map.put(4, 4); - map.put(5, 5); - map.put(6, 6); - map.put(7, 7); + map.put(primaryKey(ignite0.cache(null)), 4); + map.put(primaryKey(ignite1.cache(null)), 5); + map.put(primaryKey(ignite2.cache(null)), 6); + map.put(primaryKeys(ignite0.cache(null), 1, 10_000).get(0), 7); try (Transaction tx = ignite3.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.putAll(map);