Example #1
0
 public void ForbiddenCollectionNamesTest()
 {
     using (var gridion = GridionFactory.Start())
     {
         var grid = gridion;
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetList <string>(null), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetList <string>(string.Empty), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetList <string>("   "), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetList <string>("\t"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetList <string>("\r\n"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetSet <string>(null), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetSet <string>(string.Empty), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetSet <string>("   "), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetSet <string>("\t"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetSet <string>("\r\n"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetQueue <string>(null), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetQueue <string>(string.Empty), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetQueue <string>("   "), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetQueue <string>("\t"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetQueue <string>("\r\n"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetDictionary <string, object>(null), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetDictionary <string, object>(string.Empty), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetDictionary <string, object>("   "), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetDictionary <string, object>("\t"), "The non expected exception has been thrown.");
         Assert.ThrowsException <ArgumentNullException>(() => grid.GetDictionary <string, object>("\r\n"), "The non expected exception has been thrown.");
     }
 }
Example #2
0
        public void MasterNodeTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                foreach (var nd in gridion.Cluster.Nodes)
                {
                    var node = (INodeInternal)nd;
                    Assert.IsTrue(node.IsMasterNode);
                }

                using (var gridion2 = GridionFactory.Start(new NodeConfiguration("Node2", "127.0.0.1", 24001)))
                {
                    var number = 0;
                    foreach (var node1 in gridion2.Cluster.Nodes)
                    {
                        var node = (INodeInternal)node1;
                        if (node.IsMasterNode)
                        {
                            number++;
                        }
                    }

                    Assert.AreEqual(1, number);
                }
            }
        }
        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));
            }
        }
Example #4
0
 public void GridionInterfaceNameTest()
 {
     using (var gridion = GridionFactory.Start(new NodeConfiguration("New Node")))
     {
         Assert.AreEqual("New Node", gridion.Name, "The node name is invalid.");
     }
 }
Example #5
0
        public void MultipleDefaultGridionStartWithConfigThrowsTest()
        {
            var configuration = new NodeConfiguration("127.0.0.1", 24000);

            GridionFactory.Start(configuration);

            Assert.ThrowsException <GridionException>(() => { GridionFactory.Start(configuration); }, "The expected exception hasn't been thrown.");
        }
Example #6
0
 public void GridionStartTest()
 {
     using (var gridion = GridionFactory.Start())
     {
         Assert.IsNotNull(gridion);
         Assert.AreEqual(1, GridionFactory.GetAll().Count, "Invalid instance count.");
     }
 }
Example #7
0
 /// <summary>
 ///     Dispose the internal managed/unmanaged resources.
 /// </summary>
 /// <inheritdoc />
 protected override void DisposeManaged()
 {
     lock (Lock)
     {
         ClusterCurator.Instance.Remove(this.node);
         this.node.Dispose();
         GridionFactory.RemoveGridion(this);
     }
 }
        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 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.");
            }
        }
Example #11
0
        public void GridionStopAllTest()
        {
            GridionFactory.Start();

            Assert.AreEqual(1, GridionFactory.GetAll().Count, "Invalid instance count.");

            GridionFactory.StopAll();

            Assert.AreEqual(0, GridionFactory.GetAll().Count, "Invalid instance count.");
        }
Example #12
0
        public void DistributedListNameTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                IDistributedList <string> list = gridion.GetList <string>("name");

                Assert.IsNotNull(list, "list != null");
                Assert.AreEqual("name", list.Name, "The name is incorrect.");
            }
        }
        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.");
            }
        }
Example #14
0
        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.");
            }
        }
Example #15
0
        public void DistributedQueueNameTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                IDistributedQueue <string> queue = gridion.GetQueue <string>("name");

                Assert.IsNotNull(queue, "queue != null");
                Assert.AreEqual("name", queue.Name, "The name is incorrect.");
            }
        }
Example #16
0
        public void DistributedSetNameTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                IDistributedSet <string> set = gridion.GetSet <string>("name");

                Assert.IsNotNull(set, "set != null");
                Assert.AreEqual("name", set.Name, "The name 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 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.");
            }
        }
Example #19
0
        public void MultipleGridionStartTest()
        {
            var configuration1 = new NodeConfiguration("127.0.0.1", 24000);
            var gridion1       = GridionFactory.Start(configuration1);
            var configuration2 = new NodeConfiguration("127.0.0.1", 24001);
            var gridion2       = GridionFactory.Start(configuration2);

            Assert.IsTrue(gridion1.Name.StartsWith("[Gridion] Node - {", StringComparison.InvariantCulture), "Gridion name is incorrect.");
            Assert.IsTrue(gridion2.Name.StartsWith("[Gridion] Node - {", StringComparison.InvariantCulture), "Gridion name is incorrect.");
            Assert.AreNotEqual(gridion1.Name, gridion2.Name, "Gridion names are the same.");
        }
Example #20
0
        public void GridionStopTest()
        {
            GridionFactory.Start();

            Assert.AreEqual(1, GridionFactory.GetAll().Count, "Invalid instance count.");

            var stopped = GridionFactory.Stop(new List <IGridion>(GridionFactory.GetAll())[0].Name);

            Assert.IsTrue(stopped, "The instance hasn't been stopped.");
            Assert.AreEqual(0, GridionFactory.GetAll().Count, "Invalid instance count.");
        }
        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 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.");
            }
        }
Example #23
0
        public void DistributedObjectsNumberTest1()
        {
            using (var gridion = GridionFactory.Start())
            {
                using (var gridion2 = GridionFactory.Start(new NodeConfiguration("Node2", "127.0.0.1", 24001)))
                {
                    gridion.GetDictionary <string, string>("test1");
                    gridion2.GetDictionary <string, string>("test2");

                    Assert.AreEqual(2, ClusterCurator.Instance.DistributedCollectionNumber);
                }
            }
        }
        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 TryGetDictionaryWithIncorrectArgs()
        {
            Assert.ThrowsException <InvalidCastException>(
                () =>
            {
                using (var gridion = GridionFactory.Start())
                {
                    // create a dict with name 'test1'
                    gridion.GetDictionary <int, string>("test1");

                    // try to get the dict by name but with different agrs (int, string)
                    gridion.GetDictionary <string, string>("test1");
                }
            });
        }
        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.");
            }
        }
Example #29
0
        public void GroupNodesTest()
        {
            var cfg1 = new GridionConfiguration("node1", GridionEndpoint.GetDefault().Host, GridionEndpoint.GetDefault().Port);
            var cfg2 = new GridionConfiguration("node2", GridionEndpoint.GetDefault().Host, GridionEndpoint.GetDefault().Port + 1);

            using (var gridion = GridionFactory.Start(cfg1))
            {
                Assert.AreEqual(1, gridion.Cluster.Nodes.Count);
                using (var gridion2 = GridionFactory.Start(cfg2))
                {
                    Assert.AreEqual(2, gridion.Cluster.Nodes.Count);
                    Assert.AreEqual(2, gridion2.Cluster.Nodes.Count);
                }

                Assert.AreEqual(1, gridion.Cluster.Nodes.Count);
            }
        }
 public void TryGetDictionaryWithIncorrectArgs()
 {
     Assert.ThrowsException <InvalidCastException>(
         () =>
     {
         using (var gridion = GridionFactory.Start(this.CreateNextNodeConfiguration()))
         {
             // create a dict with name 'test1' on the first node
             gridion.GetDictionary <int, string>("test1");
             using (var gridion2 = GridionFactory.Start(this.CreateNextNodeConfiguration()))
             {
                 // try to get the dict by name but with different agrs (int, string) on different node
                 gridion2.GetDictionary <string, string>("test1");
             }
         }
     });
 }