/// <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.Cluster.LocalNode; ICacheAffinity aff = cache.Ignite.Affinity(cache.Name); List <int> keys = new List <int>(cnt); for (int i = startFrom; i < startFrom + 100000; i++) { if (aff.IsPrimary(node, i)) { keys.Add(i); if (keys.Count == cnt) { return(keys); } } } Assert.Fail("Failed to find " + cnt + " primary keys."); return(null); }
/// <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); }
public void TestAffinity() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.GetAffinity("default"); IClusterNode node = aff.MapKeyToNode(new AffinityTestKey(0, 1)); for (int i = 0; i < 10; i++) { Assert.AreEqual(node.Id, aff.MapKeyToNode(new AffinityTestKey(i, 1)).Id); } }
public void TestAffinityBinary() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.GetAffinity("default"); IBinaryObject affKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(0, 1)); IClusterNode node = aff.MapKeyToNode(affKey); for (int i = 0; i < 10; i++) { IBinaryObject otherAffKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(i, 1)); Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); } }
public void TestAffinityPortable() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.Affinity(null); IPortableObject affKey = g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(0, 1)); IClusterNode node = aff.MapKeyToNode(affKey); for (int i = 0; i < 10; i++) { IPortableObject otherAffKey = g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(i, 1)); Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); } }