Ejemplo n.º 1
0
 public void GridionInterfaceNameTest()
 {
     using (var gridion = GridionFactory.Start(new NodeConfiguration("New Node")))
     {
         Assert.AreEqual("New Node", gridion.Name, "The node name is invalid.");
     }
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 3
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.");
     }
 }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
 public void GridionStartTest()
 {
     using (var gridion = GridionFactory.Start())
     {
         Assert.IsNotNull(gridion);
         Assert.AreEqual(1, GridionFactory.GetAll().Count, "Invalid instance count.");
     }
 }
Ejemplo n.º 6
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.");
        }
Ejemplo n.º 7
0
        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.");
            }
        }
Ejemplo n.º 8
0
        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"]);
            }
        }
Ejemplo n.º 9
0
        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.");
            }
        }
Ejemplo n.º 10
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.");
        }
Ejemplo n.º 11
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.");
            }
        }
Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 13
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.");
            }
        }
Ejemplo n.º 14
0
        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.");
            }
        }
Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 16
0
        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.");
            }
        }
Ejemplo n.º 17
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.");
        }
Ejemplo n.º 18
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.");
        }
Ejemplo n.º 19
0
        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.");
            }
        }
Ejemplo n.º 20
0
        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.");
            }
        }
Ejemplo n.º 21
0
        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.");
            }
        }
Ejemplo n.º 22
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);
                }
            }
        }
Ejemplo n.º 23
0
        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.");
            }
        }
Ejemplo n.º 24
0
        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.");
            }
        }
Ejemplo n.º 25
0
        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.");
            }
        }
Ejemplo n.º 26
0
        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");
                }
            });
        }
Ejemplo n.º 27
0
        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.");
            }
        }
Ejemplo n.º 28
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);
            }
        }
Ejemplo n.º 29
0
        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.");
            }
        }
Ejemplo n.º 30
0
 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");
             }
         }
     });
 }