.NET: Fix EventsTest
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/bec4a3eb Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/bec4a3eb Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/bec4a3eb Branch: refs/heads/ignite-4587 Commit: bec4a3eba3aec10864202aef1c097d4dd3367b77 Parents: 40347ed Author: Pavel Tupitsyn <[email protected]> Authored: Fri Apr 14 11:05:20 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Fri Apr 14 11:05:20 2017 +0300 ---------------------------------------------------------------------- .../Cache/CacheMetricsTest.cs | 5 +-- .../Continuous/ContinuousQueryAbstractTest.cs | 41 +------------------- .../Compute/ComputeApiTest.cs | 8 ++-- .../Apache.Ignite.Core.Tests/EventsTest.cs | 4 +- .../Apache.Ignite.Core.Tests/TestUtils.cs | 21 ++++++++++ 5 files changed, 30 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/bec4a3eb/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheMetricsTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheMetricsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheMetricsTest.cs index d12afd2..fd5822a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheMetricsTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheMetricsTest.cs @@ -25,7 +25,6 @@ namespace Apache.Ignite.Core.Tests.Cache using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.Impl.Cache; using NUnit.Framework; - using System.Linq; /// <summary> /// Tests cache metrics propagation. @@ -224,9 +223,7 @@ namespace Apache.Ignite.Core.Tests.Cache Assert.IsTrue(localCache.GetConfiguration().EnableStatistics); Assert.IsTrue(remoteCache.GetConfiguration().EnableStatistics); - var aff = localIgnite.GetAffinity(cacheName); - var localNode = localIgnite.GetCluster().GetLocalNode(); - var localKey = Enumerable.Range(1, 10000).First(x => aff.IsPrimary(localNode, x)); + var localKey = TestUtils.GetPrimaryKey(localIgnite, cacheName); localCache.Put(localKey, 1); localCache.Get(localKey); http://git-wip-us.apache.org/repos/asf/ignite/blob/bec4a3eb/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs index 3c0633d..57f3d00 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs @@ -30,7 +30,6 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous using Apache.Ignite.Core.Cache.Event; using Apache.Ignite.Core.Cache.Query; using Apache.Ignite.Core.Cache.Query.Continuous; - using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Impl.Cache.Event; using Apache.Ignite.Core.Resource; @@ -712,7 +711,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous public void TestBufferSize() { // Put two remote keys in advance. - List<int> rmtKeys = PrimaryKeys(cache2, 2); + var rmtKeys = TestUtils.GetPrimaryKeys(cache2.Ignite, cache2.Name).Take(2).ToList(); ContinuousQuery<int, BinarizableEntry> qry = new ContinuousQuery<int, BinarizableEntry>(new Listener<BinarizableEntry>()); @@ -983,43 +982,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous /// <returns>Primary key.</returns> private static int PrimaryKey<T>(ICache<int, T> cache) { - return PrimaryKeys(cache, 1)[0]; - } - - /// <summary> - /// Get primary keys for cache. - /// </summary> - /// <param name="cache">Cache.</param> - /// <param name="cnt">Amount of keys.</param> - /// <param name="startFrom">Value to start from.</param> - /// <returns></returns> - private static List<int> PrimaryKeys<T>(ICache<int, T> cache, int cnt, int startFrom = 0) - { - IClusterNode node = cache.Ignite.GetCluster().GetLocalNode(); - - ICacheAffinity aff = cache.Ignite.GetAffinity(cache.Name); - - List<int> keys = new List<int>(cnt); - - Assert.IsTrue( - TestUtils.WaitForCondition(() => - { - for (int i = startFrom; i < startFrom + 100000; i++) - { - if (aff.IsPrimary(node, i)) - { - keys.Add(i); - - if (keys.Count == cnt) - return true; - } - } - - return false; - }, 5000), "Failed to find " + cnt + " primary keys."); - - - return keys; + return TestUtils.GetPrimaryKey(cache.Ignite, cache.Name); } /// <summary> http://git-wip-us.apache.org/repos/asf/ignite/blob/bec4a3eb/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs index 3ef9ad0..b5b6c05 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs @@ -1177,9 +1177,9 @@ namespace Apache.Ignite.Core.Tests.Compute foreach (var node in nodes) { - var primaryKey = Enumerable.Range(1, int.MaxValue).First(x => aff.IsPrimary(node, x)); + var primaryKey = TestUtils.GetPrimaryKey(_grid1, cacheName, node); - var affinityKey = _grid1.GetAffinity(cacheName).GetAffinityKey<int, int>(primaryKey); + var affinityKey = aff.GetAffinityKey<int, int>(primaryKey); _grid1.GetCompute().AffinityRun(cacheName, affinityKey, new ComputeAction()); Assert.AreEqual(node.Id, ComputeAction.LastNodeId); @@ -1204,9 +1204,9 @@ namespace Apache.Ignite.Core.Tests.Compute foreach (var node in nodes) { - var primaryKey = Enumerable.Range(1, int.MaxValue).First(x => aff.IsPrimary(node, x)); + var primaryKey = TestUtils.GetPrimaryKey(_grid1, cacheName, node); - var affinityKey = _grid1.GetAffinity(cacheName).GetAffinityKey<int, int>(primaryKey); + var affinityKey = aff.GetAffinityKey<int, int>(primaryKey); var result = _grid1.GetCompute().AffinityCall(cacheName, affinityKey, new ComputeFunc()); http://git-wip-us.apache.org/repos/asf/ignite/blob/bec4a3eb/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs index 2587479..6f0e2d1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs @@ -238,7 +238,7 @@ namespace Apache.Ignite.Core.Tests { EventType = EventType.CacheAll, EventObjectType = typeof (CacheEvent), - GenerateEvent = g => g.GetCache<int, int>(null).Put(1, 1), + GenerateEvent = g => g.GetCache<int, int>(null).Put(TestUtils.GetPrimaryKey(g), 1), VerifyEvents = (e, g) => VerifyCacheEvents(e, g), EventCount = 3 }; @@ -739,7 +739,7 @@ namespace Apache.Ignite.Core.Tests cache.Clear(); - cache.Put(1, 1); + cache.Put(TestUtils.GetPrimaryKey(g), 1); cache.Query(new ScanQuery<int, int>()).GetAll(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/bec4a3eb/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs index 0bb3b7f..02df61a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs @@ -24,6 +24,7 @@ namespace Apache.Ignite.Core.Tests using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; + using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Discovery.Tcp; using Apache.Ignite.Core.Discovery.Tcp.Static; using Apache.Ignite.Core.Impl; @@ -381,5 +382,25 @@ namespace Apache.Ignite.Core.Tests return marsh.Unmarshal<T>(marsh.Marshal(obj)); } + + /// <summary> + /// Gets the primary keys. + /// </summary> + public static IEnumerable<int> GetPrimaryKeys(IIgnite ignite, string cacheName = null, + IClusterNode node = null) + { + var aff = ignite.GetAffinity(cacheName); + node = node ?? ignite.GetCluster().GetLocalNode(); + + return Enumerable.Range(1, int.MaxValue).Where(x => aff.IsPrimary(node, x)); + } + + /// <summary> + /// Gets the primary key. + /// </summary> + public static int GetPrimaryKey(IIgnite ignite, string cacheName = null, IClusterNode node = null) + { + return GetPrimaryKeys(ignite, cacheName, node).First(); + } } }
