Example #1
0
        public void TestMultiNodesDbData()
        {
            var rh1 = new RedisHelper("192.168.197.34");
            var rh2 = new RedisHelper("192.168.197.13");
            var rh3 = new RedisHelper("192.168.197.29");

            var list1 = rh1.GetAllKeys();
            var list2 = rh2.GetAllKeys();
            var list3 = rh2.GetAllKeys();

            Console.WriteLine("Node1 total keys: {0}", list1.Count);
            Console.WriteLine("Node2 total keys :{0}", list2.Count);
            Console.WriteLine("Node3 total keys :{0}", list3.Count);

            var same12 = RedisHelper.GetIntersection(list1, list2);
            var same13 = RedisHelper.GetIntersection(list1, list3);
            var same23 = RedisHelper.GetIntersection(list2, list3);

            var same123 = RedisHelper.GetIntersection(same12, same13);

            Console.WriteLine("Node12 same keys count: {0}", same12.Count);
            Console.WriteLine("Node13 same keys count: {0}", same13.Count);
            Console.WriteLine("Node23 same keys count: {0}", same23.Count);

            var diff12 = RedisHelper.GetExceptList(list1, list2);
            var diff21 = RedisHelper.GetExceptList(list2, list1);

            Console.WriteLine("Diff12 info(length): {0}", diff12.Count);
            foreach (var item in diff12)
            {
                Console.WriteLine("Diff12: {0}", item);
            }

            Console.WriteLine("Diff21 info(length): {0}", diff21.Count);
            foreach (var item in diff21)
            {
                Console.WriteLine("Diff21: {0}", item);
            }

            var diff13 = RedisHelper.GetExceptList(list1, list3);
            var diff31 = RedisHelper.GetExceptList(list3, list1);

            Console.WriteLine("Diff13 info(length): {0}", diff13.Count);
            foreach (var item in diff13)
            {
                Console.WriteLine("Diff13: {0}", item);
            }

            Console.WriteLine("Diff31 info(length): {0}", diff31.Count);
            foreach (var item in diff31)
            {
                Console.WriteLine("Diff31: {0}", item);
            }

            var diff23 = RedisHelper.GetExceptList(list2, list3);
            var diff32 = RedisHelper.GetExceptList(list3, list2);

            Console.WriteLine("Diff23 info(length): {0}", diff23.Count);
            foreach (var item in diff23)
            {
                Console.WriteLine("Diff23: {0}", item);
            }

            Console.WriteLine("Diff23 info(length): {0}", diff32.Count);
            foreach (var item in diff32)
            {
                Console.WriteLine("Diff32: {0}", item);
            }

            TypeSummarySet tss1 = new TypeSummarySet();
            TypeSummarySet tss2 = new TypeSummarySet();
            TypeSummarySet tss3 = new TypeSummarySet();

            Console.WriteLine("Compare same key with diff data scenario:");
            foreach (var item in same123)
            {
                if (item == "ping")
                {
                    continue;
                }

                //Redis Value
                var    byteArray1 = rh1.GetT <byte[]>(item);
                string hexValue1  = BitConverter.ToString(byteArray1, 0).Replace("-", string.Empty).ToLower();

                var    byteArray2 = rh2.GetT <byte[]>(item);
                string hexValue2  = BitConverter.ToString(byteArray2, 0).Replace("-", string.Empty).ToLower();

                var    byteArray3 = rh3.GetT <byte[]>(item);
                string hexValue3  = BitConverter.ToString(byteArray3, 0).Replace("-", string.Empty).ToLower();

                //Rpc Call
                string method = "get_deserialized_info";
                string url1   = "http://192.168.197.34:8000";
                string url2   = "http://192.168.197.13:8000";
                string url3   = "http://192.168.197.29:8000";

                if (hexValue1 != hexValue2)
                {
                    Console.WriteLine("Vaule1 Value2 diff: {0}", item);

                    string parameter1 = "{\"key\":\"" + item + "\",\"value\":\"" + hexValue1 + "\"}";
                    string code1      = string.Empty;

                    var    request1  = new RpcRequestManager(url1);
                    string response1 = request1.PostRequest(method, parameter1, out code1);
                    Console.WriteLine("Db1 rpc data:\r\n" + response1);
                    var    result1 = JObject.Parse(response1);
                    string type1   = result1["result"]["TypeName"].ToString();
                    string value1  = result1["result"]["Value"].ToString();

                    var data1 = new DataResult(item, type1, value1);
                    tss1.AddDataResult(data1);
                    tss1.AddTypeSummary(data1);

                    string parameter2 = "{\"key\":\"" + item + "\",\"value\":\"" + hexValue2 + "\"}";
                    string code2      = string.Empty;

                    var    request2  = new RpcRequestManager(url2);
                    string response2 = request2.PostRequest(method, parameter2, out code2);
                    Console.WriteLine("Db2 rpc data:\r\n" + response2);
                    var    result2 = JObject.Parse(response2);
                    string type2   = result2["result"]["TypeName"].ToString();
                    string value2  = result2["result"]["Value"].ToString();

                    var data2 = new DataResult(item, type2, value2);
                    tss2.AddDataResult(data2);
                    tss2.AddTypeSummary(data2);
                }

                if (hexValue1 != hexValue3)
                {
                    Console.WriteLine("Vaule1 Value3 diff: {0}", item);
                    string parameter3 = "{\"key\":\"" + item + "\",\"value\":\"" + hexValue3 + "\"}";
                    string code3      = string.Empty;

                    var    request3  = new RpcRequestManager(url3);
                    string response3 = request3.PostRequest(method, parameter3, out code3);
                    Console.WriteLine("Db3 rpc data:\r\n" + response3);
                    var    result3 = JObject.Parse(response3);
                    string type3   = result3["result"]["TypeName"].ToString();
                    string value3  = result3["result"]["Value"].ToString();

                    var data3 = new DataResult(item, type3, value3);
                    tss3.AddDataResult(data3);
                    tss3.AddTypeSummary(data3);
                }
                Assert.IsTrue(true);
            }
        }
 public void AddDataResult(DataResult data)
 {
     DataCollection.Add(data);
 }