public void TestAffinityKeyMappedWithQueryEntity() { var cacheCfg = new CacheConfiguration(TestUtils.TestName) { QueryEntities = new List <QueryEntity> { new QueryEntity(typeof(QueryEntityKey), typeof(QueryEntityValue)) } }; var cache = Ignition.GetIgnite("grid-0").GetOrCreateCache <QueryEntityKey, QueryEntityValue>(cacheCfg); var cache2 = Ignition.GetIgnite("grid-1").GetOrCreateCache <QueryEntityKey, QueryEntityValue>(cacheCfg); TestAffinityKeyMappedWithQueryEntity0(Ignition.GetIgnite("grid-0"), cacheCfg.Name); TestAffinityKeyMappedWithQueryEntity0(Ignition.GetIgnite("grid-1"), cacheCfg.Name); // Check put/get. var key = new QueryEntityKey { Data = "x", AffinityKey = 123 }; cache[key] = new QueryEntityValue { Name = "y", AffKey = 321 }; var val = cache2[key]; Assert.AreEqual("y", val.Name); Assert.AreEqual(321, val.AffKey); }
private void PopulateNavigateResult(EntitySetDataRow row, QueryEntityValue entityInstance, AssociationSet associationSet, AssociationSetEnd fromSetEnd, AssociationSetEnd toSetEnd) { EntityContainerData containerData = row.Parent.Parent; var associationSetData = containerData.GetAssociationSetData(associationSet.Name); var targetInstanceLookup = this.rowInstances[toSetEnd.EntitySet.Name]; var associatedObjects = associationSetData.Rows .Where(r => r.GetRoleKey(fromSetEnd.AssociationEnd.RoleName).Equals(row.Key)) .Select(r => targetInstanceLookup[r.GetRoleKey(toSetEnd.AssociationEnd.RoleName)]) .ToArray(); var toEntityType = toSetEnd.AssociationEnd.EntityType; var toQueryEntityType = this.GetQueryType(toSetEnd.EntitySet.Name, toEntityType); if (toSetEnd.AssociationEnd.Multiplicity == EndMultiplicity.Many) { var collectionType = toQueryEntityType.CreateCollectionType(); var collectionValue = collectionType.CreateCollectionWithValues(associatedObjects); entityInstance.SetNavigateResult(associationSet.AssociationType, toSetEnd.AssociationEnd, collectionValue); } else { if (associatedObjects.Length == 0) { entityInstance.SetNavigateResult(associationSet.AssociationType, toSetEnd.AssociationEnd, toQueryEntityType.NullValue); } else { if (associatedObjects.Length != 1) { var debugAssociatedValues = string.Join("," + Environment.NewLine, associatedObjects.Select(ao => ao.ToString())); throw new TaupoInfrastructureException( string.Format( CultureInfo.InvariantCulture, "Found {0} associated objects for {1}.{2}, on Entity Instance {3} associated Objects = {4}", associatedObjects.Length, associationSet.AssociationType.FullName, fromSetEnd.AssociationEnd.RoleName, entityInstance, debugAssociatedValues)); } var targetInstance = associatedObjects.Single(); entityInstance.SetNavigateResult(associationSet.AssociationType, toSetEnd.AssociationEnd, targetInstance); } } }
/// <summary> /// Checks affinity mapping. /// </summary> private static void TestAffinityKeyMappedWithQueryEntity0(IIgnite ignite, string cacheName) { var aff = ignite.GetAffinity(cacheName); var key1 = new QueryEntityKey { Data = "data1", AffinityKey = 1 }; var key2 = new QueryEntityKey { Data = "data2", AffinityKey = 1 }; var val1 = new QueryEntityValue { Name = "foo", AffKey = 100 }; var val2 = new QueryEntityValue { Name = "bar", AffKey = 100 }; Assert.AreEqual(aff.GetPartition(key1), aff.GetPartition(key2)); Assert.AreEqual(aff.GetPartition(val1), aff.GetPartition(val2)); }
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, i))); Assert.AreEqual(aff2.GetPartition(i), aff2.GetPartition(new AffinityKey("bar" + i, i))); Assert.AreEqual(aff.GetPartition(i), aff2.GetPartition(i)); } // Check put/get. 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); }