You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2022/10/21 06:51:49 UTC

[ignite] branch master updated: IGNITE-17946 .NET: Fix PartitionLossTest flakiness (#10339)

This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 6aeb74588ad IGNITE-17946 .NET: Fix PartitionLossTest flakiness (#10339)
6aeb74588ad is described below

commit 6aeb74588add4339ea531e45140f01c513055421
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Fri Oct 21 09:51:39 2022 +0300

    IGNITE-17946 .NET: Fix PartitionLossTest flakiness (#10339)
    
    Add `PlatformWaitForRebalanceTask` to wait for rebalance reliably.
---
 .../platform/PlatformWaitForRebalanceTask.java     | 104 +++++++++++++++++++++
 .../Cache/PartitionLossTest.cs                     |  51 +++++-----
 2 files changed, 131 insertions(+), 24 deletions(-)

diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformWaitForRebalanceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformWaitForRebalanceTask.java
new file mode 100644
index 00000000000..8a2a544c9aa
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformWaitForRebalanceTask.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.platform;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskAdapter;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Task that waits for rebalance to complete.
+ */
+public class PlatformWaitForRebalanceTask extends ComputeTaskAdapter<Object[], Boolean> {
+    /** {@inheritDoc} */
+    @NotNull
+    @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object[] args)
+            throws IgniteException {
+        return Collections.singletonMap(new Job(args), F.first(subgrid));
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Boolean reduce(List<ComputeJobResult> results) throws IgniteException {
+        return results.get(0).getData();
+    }
+
+    /**
+     * Job.
+     */
+    private static class Job extends ComputeJobAdapter {
+        /** Expected version. */
+        private final AffinityTopologyVersion topVer;
+
+        /** Cache name. */
+        private final String cacheName;
+
+        /** Timeout. */
+        private final long timeout;
+
+        /** Ignite. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /**
+         * Ctor.
+         *
+         * @param args Args.
+         */
+        private Job(Object[] args) {
+            cacheName = (String)args[0];
+            topVer = new AffinityTopologyVersion((Long)args[1], (Integer)args[2]);
+            timeout = (Long)args[3];
+        }
+
+        /** {@inheritDoc} */
+        @Override public Boolean execute() throws IgniteException {
+            final GridDhtPartitionTopology top =
+                    ((IgniteEx)ignite).context().cache().context().cacheContext(CU.cacheId(cacheName)).topology();
+
+            try {
+
+                return GridTestUtils.waitForCondition(() -> {
+                    ignite.log().info("PlatformWaitForRebalanceTask.Job: Waiting for rebalance to complete [expectedTopVer="
+                            + topVer + ", readyTopVer=" + top.readyTopologyVersion() + ']');
+
+                    return top.rebalanceFinished(topVer);
+                }, timeout);
+            }
+            catch (IgniteInterruptedCheckedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PartitionLossTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PartitionLossTest.cs
index c4d6e19a0f0..cd8f139d2bb 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PartitionLossTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PartitionLossTest.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Tests.Cache
     using System.Collections.Generic;
     using System.Linq;
     using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cache.Affinity;
     using Apache.Ignite.Core.Cache.Affinity.Rendezvous;
     using Apache.Ignite.Core.Cache.Configuration;
     using NUnit.Framework;
@@ -35,11 +36,17 @@ namespace Apache.Ignite.Core.Tests.Cache
         /** */
         private const string CacheName = "lossTestCache";
 
+        /** */
+        private const string WaitForRebalanceTask = "org.apache.ignite.platform.PlatformWaitForRebalanceTask";
+
+        /** */
+        private const int TimeoutMs = 7000;
+
         /// <summary>
         /// Fixture set up.
         /// </summary>
-        [TestFixtureSetUp]
-        public void FixtureSetUp()
+        [SetUp]
+        public void SetUp()
         {
             Ignition.Start(TestUtils.GetTestConfiguration());
         }
@@ -47,21 +54,10 @@ namespace Apache.Ignite.Core.Tests.Cache
         /// <summary>
         /// Fixture tear down.
         /// </summary>
-        [TestFixtureTearDown]
-        public void FixtureTearDown()
-        {
-            Ignition.StopAll(true);
-        }
-
-        /// <summary>
-        /// Test teardown.
-        /// </summary>
         [TearDown]
         public void TearDown()
         {
-            var ignite = Ignition.GetIgnite();
-
-            ignite.GetCacheNames().ToList().ForEach(ignite.DestroyCache);
+            Ignition.StopAll(true);
         }
 
         /// <summary>
@@ -130,7 +126,7 @@ namespace Apache.Ignite.Core.Tests.Cache
 
             // Loose data and verify lost partition.
             var lostPart = PrepareTopology();
-            TestUtils.WaitForTrueCondition(() => cache.GetLostPartitions().Any());
+            TestUtils.WaitForTrueCondition(() => cache.GetLostPartitions().Any(), TimeoutMs);
             var lostParts = cache.GetLostPartitions();
             Assert.IsTrue(lostParts.Contains(lostPart));
 
@@ -146,15 +142,16 @@ namespace Apache.Ignite.Core.Tests.Cache
                 Assert.IsFalse(recoverCache.TryGet(part, out unused));
             }
 
-            // Reset and verify.
-            ignite.ResetLostPartitions(CacheName);
-            Assert.IsEmpty(cache.GetLostPartitions());
+            // Reset and verify. Test different ResetLostPartitions overloads.
+            if (canWrite)
+            {
+                ignite.ResetLostPartitions(CacheName);
+            }
+            else
+            {
+                ignite.ResetLostPartitions(new List<string> {CacheName, "foo"});
+            }
 
-            // Check another ResetLostPartitions overload.
-            PrepareTopology();
-            TestUtils.WaitForTrueCondition(() => cache.GetLostPartitions().Any());
-            Assert.IsNotEmpty(cache.GetLostPartitions());
-            ignite.ResetLostPartitions(new List<string> {CacheName, "foo"});
             Assert.IsEmpty(cache.GetLostPartitions());
         }
 
@@ -251,7 +248,13 @@ namespace Apache.Ignite.Core.Tests.Cache
                 // Wait for rebalance to complete.
                 var node = ignite.GetCluster().GetLocalNode();
                 Func<int, bool> isPrimary = x => affinity.IsPrimary(node, x);
-                TestUtils.WaitForTrueCondition(() => keys.Any(isPrimary));
+                TestUtils.WaitForTrueCondition(() => keys.Any(isPrimary), TimeoutMs);
+
+                var expectedTopVer = new AffinityTopologyVersion(2, 1);
+
+                Assert.IsTrue(ignite.GetCompute().ExecuteJavaTask<bool>(
+                    WaitForRebalanceTask,
+                    new object[] { CacheName, expectedTopVer.Version, expectedTopVer.MinorVersion, (long)TimeoutMs }));
 
                 return keys.First(isPrimary);
             }