public void ToArray1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); KeyValuePair <string, int>[] array = dictionary.ToArray(); Assert.AreEqual(1, array.Length, "The length is invalid."); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.AreEqual(1, array.Length, "The length is invalid."); dictionary.AddOrUpdate("key2", 2, (_, _) => 2); array = dictionary.ToArray(); Assert.AreEqual(2, array.Length, "The length is invalid."); var values = new int[array.Length]; var index = 0; foreach (KeyValuePair <string, int> pair in array) { values[index] = pair.Value; index++; } Assert.IsTrue(values.Contains(1)); Assert.IsTrue(values.Contains(2)); } }
public static async Task PopulateDictionaryAsync( TransactionalReplicator transactionalReplicator, Uri dictionaryName, long startingNumber, int batchCount, int batchSize) { var dictionary = GetDictionary <long, long>(transactionalReplicator, dictionaryName); IDistributedDictionary <long, long> distributedDictionary = dictionary as IDistributedDictionary <long, long>; var startingCount = distributedDictionary.Count; for (var batchIndex = 0; batchIndex < batchCount; batchIndex++) { using (var txn = transactionalReplicator.CreateTransaction()) { for (var key = (batchIndex * batchSize) + startingNumber; key < ((batchIndex + 1) * batchSize) + startingNumber; key++) { await dictionary.AddAsync(txn, key, key).ConfigureAwait(false); } Assert.AreEqual(startingCount + (batchIndex * batchSize), distributedDictionary.Count); await txn.CommitAsync().ConfigureAwait(false); } Assert.AreEqual(startingCount + ((batchIndex + 1) * batchSize), distributedDictionary.Count); } var finalCount = distributedDictionary.Count; Assert.AreEqual(startingCount + (batchCount * batchSize), finalCount); await VerifyDictionaryAsync(transactionalReplicator, dictionaryName, startingNumber, batchCount, batchSize).ConfigureAwait(false); }
/// <summary> /// displays dictionary objects /// </summary> /// <param name="distributedDictionary">Dictionary to display</param> public void DisplayDictionaryData(IDistributedDictionary <string, object> distributedDictionary) { Console.WriteLine("Result count: " + distributedDictionary.Count); foreach (KeyValuePair <string, object> pair in distributedDictionary) { Console.WriteLine("--"); DisplayCustomerData((Customer)pair.Value); } }
public void GetName1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.AreEqual("testDictionary", dictionary.Name, "The collection name is invalid."); } }
public void TryUpdate1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.IsTrue(dictionary.TryUpdate("key", 2, 1), "dictionary.TryUpdate('key', 2, 1) is invalid."); } }
public void GetItem1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.AreEqual(1, dictionary["key"]); } }
public void GetCount1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.AreEqual(1, dictionary.Count, "The collection count is incorrect."); } }
public void ContainsKey1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.IsTrue(dictionary.ContainsKey("key"), "dictionary.ContainsKey('key') failed."); } }
public void DistributedDictionaryNameTest() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, object> dictionary = gridion.GetDictionary <string, object>("name"); Assert.IsNotNull(dictionary, "dictionary != null"); Assert.AreEqual("name", dictionary.Name, "The name is incorrect."); } }
/// <summary> /// Remove an object from distributed Dictionary by instance and Key of object /// </summary> /// <param name="customer">Instance of object to be deleted from distributed Dictionary</param> /// <param name="key"> Key of object to be deleted from distributed Dictionary</param> private static void RemoveObjectFromDictionary(string key, Customer customer) { IDistributedDictionary <string, Customer> dictionary = _cache.DataTypeManager.GetDictionary <string, Customer>(_dictionaryName); // Remove the existing customer // Expensive operation use carefully bool removed = dictionary.Remove(new KeyValuePair <string, Customer>(key, customer)); //Print output on console. Console.WriteLine("\nObject is" + ((removed) ? " " : " not ") + "removed from distributed Dictionary."); }
public void TryGetValue1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.IsTrue(dictionary.TryGetValue("key", out var value), "dictionary.TryGetValue('key', out int value) is incorrect."); Assert.AreEqual(1, value, "The value is incorrect."); } }
/// <summary> /// Gets partitions (nodes) with assotiated indexes. /// </summary> /// <returns></returns> //public List<(int partId, int minKey, int maxKey)> GetPartitions() //{ // if (IsRemotelyDistributed) // { // IHtmDistCalculus map = this.sparseMap as IHtmDistCalculus; // return map.GetPartitions(); // } // else // throw new InvalidOperationException("GetPartitions can only be ued for remotely distributed collections."); //} /** * Constructs a new {@code SparseObjectMatrix} * @param dimensions the dimensions of this array */ //public SparseObjectMatrix(int[] dimensions) : base(dimensions, false) //{ //} /// <summary> /// Constructs a new <see cref="SparseObjectMatrix{T}"/> /// </summary> /// <param name="dimensions">the dimensions of this array</param> /// <param name="useColumnMajorOrdering">where inner index increments most frequently</param> /// <param name="dict"></param> public SparseObjectMatrix(int[] dimensions, bool useColumnMajorOrdering = false, IDistributedDictionary <int, T> dict = null) : base(dimensions, useColumnMajorOrdering) { if (dict == null) { this.m_SparseMap = new InMemoryDistributedDictionary <int, T>(1); } else { this.m_SparseMap = dict; } }
public void TryRemove1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.IsTrue(dictionary.TryRemove("key", out var value), "dictionary.TryRemove('key', out int value) is invalid."); Assert.AreEqual(1, value, "The values are different."); Assert.IsFalse(dictionary.TryRemove("key", out _), "dictionary.TryRemove('key', out int value) is invalid."); } }
public void SetItem1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("keyItem", 1, (_, _) => 1); dictionary["keyItem"] = 2; Assert.AreEqual(2, dictionary["keyItem"], "The values are invalid."); } }
public void TryAdd1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); // the first try Assert.IsTrue(dictionary.TryAdd("key", 1), "dictionary.TryAdd('key', 1) is invalid."); // the second try Assert.IsFalse(dictionary.TryAdd("key", 1), "dictionary.TryAdd('key', 1) is invalid."); } }
public void Clear1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.AreEqual(1, dictionary.Count, "dictionary.Count is invalid."); dictionary.Clear(); Assert.AreEqual(0, dictionary.Count, "dictionary.Count is invalid."); } }
public void GetIsEmpty1Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); Assert.IsFalse(dictionary.IsEmpty, "dictionary.IsEmpty is incorrect."); dictionary.TryRemove("key", out _); Assert.IsTrue(dictionary.IsEmpty, "dictionary.IsEmpty is incorrect."); } }
public void GetValues1GenericTest() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); var i = 0; foreach (var unused in dictionary.Values) { i++; } Assert.AreEqual(1, i, "The collection count is incorrect."); } }
/// <summary> /// modify dictionary entry by CustomerID /// </summary> /// <param name="distributedDictionary"></param> public void ModifyDictionaryValue(IDistributedDictionary <string, object> distributedDictionary) { distributedDictionary.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName); InputDataFromUser(); distributedDictionary[CustomerID] = new Customer() { CustomerID = CustomerID, ContactName = ContactName, CompanyName = CompanyName, Address = Address, City = City, Country = Country, PostalCode = PostalCode, ContactNo = Phone, Fax = Fax, }; }
public void GetKeys1GenericTest() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); dictionary.AddOrUpdate("key", 1, (_, _) => 1); var val = dictionary["key"]; foreach (var key in dictionary.Keys) { Assert.AreEqual("key", key); } Assert.AreEqual(1, val, "Values are different."); } }
public void AddOrUpdate3Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, int> dictionary = gridion.GetDictionary <string, int>("testDictionary"); var addedValue = dictionary.AddOrUpdate("key", (_, _) => 1, (_, _, _) => 1, 0d); IDistributedDictionary <string, int> dictionary2 = gridion.GetDictionary <string, int>("testDictionary"); Assert.AreEqual(dictionary.Count, dictionary2.Count, "The collection lengths are different."); foreach (KeyValuePair <string, int> pair in dictionary) { Assert.IsTrue(dictionary2.TryGetValue(pair.Key, out var val), "dictionary2.TryGetValue(pair.Key, out var val) failed."); Assert.AreEqual(addedValue, val, "The values are different."); Assert.IsTrue(dictionary[pair.Key] == val, "dictionary[pair.Key] is not equal to val."); } } }
/// <summary> /// Creates a distributed Dictionary to which instances of customers are to be added /// </summary> /// <param name="DictionaryName">The name of Dictionary. This name is ultimately going to /// be the key against which distributed Dictionary is to be stored.</param> private static IDictionary <string, Customer> GetOrCreateDictionary(string DictionaryName) { IDistributedDictionary <string, Customer> dictionary = _cache.DataTypeManager.GetDictionary <string, Customer>(_dictionaryName); if (dictionary == null) { //Add expiration details DataTypeAttributes attributes = new DataTypeAttributes { Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)) }; // Creating distributed Dictionary with absolute expiration of 1 minute dictionary = _cache.DataTypeManager.CreateDictionary <string, Customer>(DictionaryName, attributes); } return(dictionary); }
public void GetOrAdd3Test() { using (var gridion = GridionFactory.Start()) { IDistributedDictionary <string, DictionaryTestObject> dictionary = gridion.GetDictionary <string, DictionaryTestObject>("testDictionary"); var expected = new DictionaryTestObject(1); var actual = dictionary.GetOrAdd("key", (_, _) => expected, 0d); Assert.IsNotNull(actual, "actual != null."); Assert.AreEqual(expected, actual, "The objects are different."); Assert.AreEqual(1, dictionary.Count, "The collection size is invalid."); actual = dictionary.GetOrAdd("key", expected); Assert.IsNotNull(actual, "actual != null."); Assert.AreEqual(1, dictionary.Count, "The collection size is invalid."); } }
public void AddOrUpdate1Test() { using (var gridion = GridionFactory.Start()) { using (var gridion2 = GridionFactory.Start(new NodeConfiguration("Node2", "127.0.0.1", 24001))) { IDistributedDictionary <string, int> expected = gridion.GetDictionary <string, int>("testDictionary"); var addedValue = expected.AddOrUpdate("key", _ => 1, (_, _) => 1); IDistributedDictionary <string, int> actual = gridion2.GetDictionary <string, int>("testDictionary"); Assert.AreEqual(expected.Count, actual.Count, "The collection lengths are different."); foreach (KeyValuePair <string, int> pair in expected) { Assert.IsTrue(actual.TryGetValue(pair.Key, out var val), "dictionary2.TryGetValue(pair.Key, out var val) failed."); Assert.AreEqual(addedValue, val, "The values are different."); Assert.IsTrue(expected[pair.Key] == val, "dictionary[pair.Key] is not equal to val."); } } } }
public void DistributedDictionaryTest2Nodes() { var configuration = new GridionConfiguration("127.0.0.1", 24000); var configuration2 = new GridionConfiguration("127.0.0.1", 24001); using (var gridion = GridionFactory.Start(configuration)) { using (var gridion2 = GridionFactory.Start(configuration2)) { IDistributedDictionary <string, object> dictionary = gridion.GetDictionary <string, object>("name"); Assert.IsNotNull(dictionary, "dictionary != null"); Assert.AreEqual("name", dictionary.Name, "The name is incorrect."); IDistributedDictionary <string, object> dictionary2 = gridion2.GetDictionary <string, object>("name"); Assert.IsNotNull(dictionary2, "dictionary != null"); Assert.AreEqual("name", dictionary2.Name, "The name is incorrect."); } } }
/// <summary> /// remove dictionary entry by CustomerID /// </summary> /// <param name="distributedDictionary"></param> public void RemoveDictionaryValue(IDistributedDictionary <string, object> distributedDictionary) { distributedDictionary.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName); distributedDictionary.Remove(CustomerID); }