isapego commented on a change in pull request #8866:
URL: https://github.com/apache/ignite/pull/8866#discussion_r591514865
##########
File path:
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTest.cs
##########
@@ -121,6 +121,45 @@ public void TestAffinityKeyMappedWithQueryEntitySpringXml()
}
}
+ /// <summary>
+ /// Tests that <see cref="AffinityKey"/> works when used as <see
cref="QueryEntity.KeyType"/>.
+ /// </summary>
+ [Test]
+ public void TestAffinityKeyWithQueryEntity()
+ {
+ var cacheCfg = new CacheConfiguration(TestUtils.TestName)
+ {
+ QueryEntities = new List<QueryEntity>
+ {
+ new QueryEntity(typeof(AffinityKey),
typeof(QueryEntityValue))
+ }
+ };
+
+ var ignite = Ignition.GetIgnite("grid-0");
+ var cache = ignite.GetOrCreateCache<AffinityKey,
QueryEntityValue>(cacheCfg);
+ var aff = ignite.GetAffinity(cache.Name);
+
+ var ignite2 = Ignition.GetIgnite("grid-1");
+ var cache2 = ignite2.GetOrCreateCache<AffinityKey,
QueryEntityValue>(cacheCfg);
+ var aff2 = ignite2.GetAffinity(cache2.Name);
+
+ // Check mapping.
+ for (var i = 0; i < 100; i++)
+ {
+ Assert.AreEqual(aff.GetPartition(i), aff.GetPartition(new
AffinityKey("foo", i)));
+ Assert.AreEqual(aff2.GetPartition(i), aff2.GetPartition(new
AffinityKey("bar", i)));
+ Assert.AreEqual(aff.GetPartition(i), aff2.GetPartition(i));
+ }
+
+ // Check put/get.
+ var key = new AffinityKey("x", 123);
+ cache[key] = new QueryEntityValue {Name = "y", AffKey = 321};
+
+ var val = cache2[key];
+ Assert.AreEqual("y", val.Name);
+ Assert.AreEqual(321, val.AffKey);
Review comment:
Not critical, but there is duplication.
```suggestion
var key = new AffinityKey("x", 123);
var expected = new QueryEntityValue {Name = "y", AffKey = 321};
cache[key] = expected;
var val = cache2[key];
Assert.AreEqual(expected.Name, val.Name);
Assert.AreEqual(expected.AffKey, val.AffKey);
```
##########
File path:
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTest.cs
##########
@@ -121,6 +121,45 @@ public void TestAffinityKeyMappedWithQueryEntitySpringXml()
}
}
+ /// <summary>
+ /// Tests that <see cref="AffinityKey"/> works when used as <see
cref="QueryEntity.KeyType"/>.
+ /// </summary>
+ [Test]
+ public void TestAffinityKeyWithQueryEntity()
+ {
+ var cacheCfg = new CacheConfiguration(TestUtils.TestName)
+ {
+ QueryEntities = new List<QueryEntity>
+ {
+ new QueryEntity(typeof(AffinityKey),
typeof(QueryEntityValue))
+ }
+ };
+
+ var ignite = Ignition.GetIgnite("grid-0");
+ var cache = ignite.GetOrCreateCache<AffinityKey,
QueryEntityValue>(cacheCfg);
+ var aff = ignite.GetAffinity(cache.Name);
+
+ var ignite2 = Ignition.GetIgnite("grid-1");
+ var cache2 = ignite2.GetOrCreateCache<AffinityKey,
QueryEntityValue>(cacheCfg);
+ var aff2 = ignite2.GetAffinity(cache2.Name);
+
+ // Check mapping.
+ for (var i = 0; i < 100; i++)
+ {
+ Assert.AreEqual(aff.GetPartition(i), aff.GetPartition(new
AffinityKey("foo", i)));
Review comment:
I think we test is going to be more robust if we add variability to the
string field as well. How about `"foo" + i`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]