Beispiel #1
0
        /// <summary>
        /// 位图测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 Bitmap 的位图缓存
            AutoCSer.CacheServer.DataStructure.Bitmap bitmap = client.GetOrCreateDataStructure <AutoCSer.CacheServer.DataStructure.Bitmap>("Bitmap").Value;
            if (bitmap == null)
            {
                return(false);
            }
            #endregion

            #region 设置第 3 个位,返回设置前的位状态 false
            AutoCSer.CacheServer.ReturnValue <bool> bit = bitmap.Set(3);
            if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value)
            {
                return(false);
            }
            #endregion

            #region 第 5 个位取反,返回取反后的结果 true
            bit = bitmap.SetNegate(5);
            if (!bit.Value)
            {
                return(false);
            }
            #endregion

            #region 获取第 3 个位,结果为 true
            bit = bitmap.Get(3);
            if (!bit.Value)
            {
                return(false);
            }
            #endregion

            #region 清除第 5 个位,返回清除前的位状态 true
            bit = bitmap.Clear(5);
            if (!bit.Value)
            {
                return(false);
            }
            #endregion

            #region 第 3 个位取反,返回取反后的结果 false
            bit = bitmap.SetNegate(3);
            if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value)
            {
                return(false);
            }
            #endregion

            #region 获取第 5 个位,结果为 false
            bit = bitmap.Get(5);
            if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value)
            {
                return(false);
            }
            #endregion

            return(true);
        }
Beispiel #2
0
 /// <summary>
 /// 链表测试
 /// </summary>
 /// <param name="client"></param>
 /// <returns></returns>
 internal static bool TestCase(AutoCSer.CacheServer.Client client)
 {
     #region 创建名称为 Link 的链表缓存
     Link <int> link = client.GetOrCreateDataStructure <Link <int> >("Link").Value;
     if (link == null)
     {
         return(false);
     }
     #endregion
     return(TestCase(link));
 }
Beispiel #3
0
 /// <summary>
 /// 数组测试
 /// </summary>
 /// <param name="client"></param>
 /// <returns></returns>
 internal static bool TestCase(AutoCSer.CacheServer.Client client)
 {
     #region 创建名称为 ValueArray 的数组缓存
     ValueArray <int> array = client.GetOrCreateDataStructure <ValueArray <int> >("ValueArray").Value;
     if (array == null)
     {
         return(false);
     }
     #endregion
     return(TestCase(array));
 }
Beispiel #4
0
        static unsafe void Main(string[] args)
        {
#if DotNetStandard
            Console.WriteLine("WARN : Linux .NET Core not support name EventWaitHandle");
#else
            bool            createdProcessWait;
            EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.TestCase.CacheServerPerformance", out createdProcessWait);
            if (createdProcessWait)
            {
                using (processWait)
                {
#endif
            Console.WriteLine(@"http://www.AutoCSer.com/CacheServer/Index.html
");
            checkFileSize("test.amc");
            checkFileSize("test.amcs");

            using (AutoCSer.CacheServer.MasterServer.TcpInternalServer server = new AutoCSer.CacheServer.MasterServer.TcpInternalServer())
            {
                if (server.IsListen)
                {
                    using (AutoCSer.CacheServer.Client client = new AutoCSer.CacheServer.Client())
                    {
                        Console.WriteLine(MesssageQueueConsumer.TestCase(client));
                        Console.WriteLine(MesssageQueueConsumers.TestCase(client));
                        Console.WriteLine(MesssageDistributor.TestCase(client));

                        Console.WriteLine(ValueArray.TestCase(client));
                        Console.WriteLine(ValueDictionary.TestCase(client));
                        Console.WriteLine(ValueSearchTreeDictionary.TestCase(client));
                        Console.WriteLine(Heap.TestCase(client));
                        Console.WriteLine(HashSet.TestCase(client));
                        Console.WriteLine(Link.TestCase(client));
                        Console.WriteLine(Bitmap.TestCase(client));

                        Console.WriteLine(Array.TestCase(client));
                        Console.WriteLine(Dictionary.TestCase(client));
                        Console.WriteLine(SearchTreeDictionary.TestCase(client));
                        Console.WriteLine("Over");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("缓存服务启动失败");
                    Console.ReadKey();
                }
            }
#if !DotNetStandard
        }
    }
#endif
        }
Beispiel #5
0
        /// <summary>
        /// 字典测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 ValueDictionary 的字典缓存
            ValueDictionary <int, int> dictionary = client.GetOrCreateDataStructure <ValueDictionary <int, int> >("ValueDictionary").Value;
            if (dictionary == null)
            {
                return(false);
            }
            #endregion

            return(TestCase(dictionary));
        }
Beispiel #6
0
        /// <summary>
        /// 哈希表测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 HashSet 的哈希表缓存
            HashSet <int> hashSet = client.GetOrCreateDataStructure <HashSet <int> >("HashSet").Value;
            if (hashSet == null)
            {
                return(false);
            }
            #endregion

            #region 添加值为 9 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isAdd = hashSet.Add(9);
            if (!isAdd.Value)
            {
                return(false);
            }
            #endregion

            #region 判断是否存在值为 9 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isValue = hashSet.Contains(9);
            if (!isValue.Value)
            {
                return(false);
            }
            #endregion

            #region 获取哈希表数据数量
            AutoCSer.CacheServer.ReturnValue <int> count = hashSet.Count;
            if (count.Value != 1)
            {
                return(false);
            }
            #endregion

            #region  除值为 9 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isRemove = hashSet.Remove(9);
            if (!isRemove.Value)
            {
                return(false);
            }
            count = hashSet.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }
            #endregion

            return(true);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
#if DotNetStandard
            Console.WriteLine("WARN : Linux .NET Core not support name EventWaitHandle");
#else
            bool            createdProcessWait;
            EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.TestCase.CacheClientPerformance", out createdProcessWait);
            if (createdProcessWait)
            {
                using (processWait)
                {
#endif
            Console.WriteLine(@"http://www.AutoCSer.com/CacheServer/Index.html
");
            AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Metadata.TypeAttribute.GetAttribute <AutoCSer.Net.TcpInternalServer.ServerAttribute>(typeof(AutoCSer.CacheServer.MasterServer), false);
            serverAttribute.VerifyString = "!2#4%6&8QwErTyAsDfZx";
            AutoCSer.Net.TcpInternalServer.ServerAttribute fileServerAttribute = AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute);

            fileServerAttribute.Port -= 1;
            using (AutoCSer.CacheServer.Client client = new AutoCSer.CacheServer.Client(new AutoCSer.CacheServer.MasterServer.TcpInternalClient(serverAttribute)))
                using (AutoCSer.CacheServer.Client fileClient = new AutoCSer.CacheServer.Client(new AutoCSer.CacheServer.MasterServer.TcpInternalClient(fileServerAttribute)))
                {
                    do
                    {
                        new MessageQueue(fileClient).Test();
                        new MesssageDistributor(fileClient).Test();

                        new Dictionary(client, false).Test();
                        new Dictionary(fileClient, true).Test();

                        new Array(client, false).Test();
                        new Array(fileClient, true).Test();

                        new Binary(client, false).Test();
                        new Binary(fileClient, true).Test();

                        new Json(client, false).Test();
                        new Json(fileClient, true).Test();
                    }while (true);
                }
#if !DotNetStandard
        }
    }
#endif
        }
Beispiel #8
0
        /// <summary>
        /// 锁测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 Lock 的锁缓存
            AutoCSer.CacheServer.DataStructure.Lock Lock = client.GetOrCreateDataStructure <AutoCSer.CacheServer.DataStructure.Lock>("Lock").Value;
            if (Lock == null)
            {
                return(false);
            }
            #endregion

            #region  步等待申请锁,锁超时为 5 秒
            AutoCSer.CacheServer.ReturnValue <AutoCSer.CacheServer.Lock.Manager> manager = Lock.GetEnter(5 * 1000);
            if (manager.Value == null)
            {
                return(false);
            }
            #endregion

            using (manager.Value)
            {
                #region 尝试申请锁
                AutoCSer.CacheServer.ReturnValue <AutoCSer.CacheServer.Lock.Manager> tryManager = Lock.GetTryEnter(5 * 1000);
                if (tryManager.Type != AutoCSer.CacheServer.ReturnType.Locked)
                {
                    return(false);
                }
                #endregion
            }

            manager = Lock.GetTryEnter(5 * 1000);
            if (manager.Value == null)
            {
                return(false);
            }
            #region 释放锁,使用 using 也可以
            manager.Value.Exit();
            #endregion

            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// 搜索树字典测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 SearchTreeDictionary 的搜索树字典缓存
            SearchTreeDictionary <int, ValueArray <int> > dictionary = client.GetOrCreateDataStructure <SearchTreeDictionary <int, ValueArray <int> > >("SearchTreeDictionary").Value;
            if (dictionary == null)
            {
                return(false);
            }
            #endregion

            #region 创建或者获取关键字为 1 的子节点
            ValueArray <int> array = dictionary.GetOrCreate(1).Value;
            if (array == null)
            {
                return(false);
            }
            #endregion

            if (!ValueArray.TestCase(array))
            {
                return(false);
            }

            #region 创建短路径
            AutoCSer.CacheServer.ShortPath.Array <int> shortPathArray = array.CreateShortPath().Value;
            if (shortPathArray == null)
            {
                return(false);
            }
            #endregion

            if (!ValueArray.TestCase(shortPathArray))
            {
                return(false);
            }

            #region 判断关键字 1 是否存在
            AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1);
            if (!isKey.Value)
            {
                return(false);
            }
            #endregion

            #region 获取字典数据数量
            AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count;
            if (count.Value != 1)
            {
                return(false);
            }
            #endregion

            #region  除关键字为 1 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1);
            if (!isRemove.Value)
            {
                return(false);
            }
            count = dictionary.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }
            #endregion

            return(true);
        }
Beispiel #10
0
 /// <summary>
 /// 简单数组测试
 /// </summary>
 /// <param name="client">测试客户端</param>
 /// <param name="isFile">服务端是否文件持久化</param>
 internal Binary(AutoCSer.CacheServer.Client client, bool isFile) : base(client, isFile)
 {
     getCallbackReturnParameter = AutoCSer.CacheServer.ReturnParameter.GetCallback <Binary <int> >(getCallback);
     dictionary = client.GetOrCreateDataStructure <ValueDictionary <int, Binary <int> > >("Binary");
 }
Beispiel #11
0
        /// <summary>
        /// 最小堆测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 Heap 的最小堆缓存
            Heap <int, int> heap = client.GetOrCreateDataStructure <Heap <int, int> >("Heap").Value;
            if (heap == null)
            {
                return(false);
            }
            #endregion

            #region 添加关键字为 6 值为 9 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isSet = heap.Push(6, 9);
            if (!isSet.Value)
            {
                return(false);
            }
            #endregion

            isSet = heap.Push(2, 8);
            if (!isSet.Value)
            {
                return(false);
            }

            isSet = heap.Push(4, 7);
            if (!isSet.Value)
            {
                return(false);
            }

            #region 获取数据数量
            AutoCSer.CacheServer.ReturnValue <int> count = heap.Count;
            if (count.Value != 3)
            {
                return(false);
            }
            #endregion

            #region 获取堆顶关键字
            AutoCSer.CacheServer.ReturnValue <int> key = heap.GetTopKey();
            if (key.Value != 2)
            {
                return(false);
            }
            #endregion

            #region 获取堆顶数据
            AutoCSer.CacheServer.ReturnValue <int> value = heap.GetTopValue();
            if (value.Value != 8)
            {
                return(false);
            }
            #endregion

            #region  除堆顶数据
            isSet = heap.PopTop();
            if (!isSet.Value)
            {
                return(false);
            }
            #endregion

            #region  除堆顶数据并返回关键字
            key = heap.GetPopTopKey();
            if (key.Value != 4)
            {
                return(false);
            }
            #endregion

            #region  除堆顶数据并返回数据
            value = heap.GetPopTopValue();
            if (value.Value != 9)
            {
                return(false);
            }
            #endregion

            count = heap.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #12
0
 /// <summary>
 /// 简单数组测试
 /// </summary>
 /// <param name="client">测试客户端</param>
 /// <param name="isFile">服务端是否文件持久化</param>
 internal Array(AutoCSer.CacheServer.Client client, bool isFile) : base(client, isFile)
 {
     getCallbackReturnParameter = AutoCSer.CacheServer.ReturnParameter.GetCallback <int>(getCallback);
     array = client.GetOrCreateDataStructure <ValueArray <int> >("Array");
 }
Beispiel #13
0
 /// <summary>
 /// 消息分发测试
 /// </summary>
 /// <param name="client">测试客户端</param>
 internal MesssageDistributor(AutoCSer.CacheServer.Client client) : base(client, true)
 {
     enqueueCallbackReturnParameter            = AutoCSer.CacheServer.ReturnParameter.GetCallback(setCallback);
     enqueueCallbackInterlockedReturnParameter = AutoCSer.CacheServer.ReturnParameter.GetCallback(setCallbackInterlocked);
 }
Beispiel #14
0
 /// <summary>
 /// 测试基类
 /// </summary>
 /// <param name="client">测试客户端</param>
 /// <param name="isFile">服务端是否文件持久化</param>
 protected Test(AutoCSer.CacheServer.Client client, bool isFile)
 {
     this.client = client;
     this.isFile = isFile;
     setCallbackReturnParameter = AutoCSer.CacheServer.ReturnParameter.GetCallback(setCallback);
 }
Beispiel #15
0
        /// <summary>
        /// 搜索树字典测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 ValueSearchTreeDictionary 的搜索树字典缓存
            ValueSearchTreeDictionary <int, int> dictionary = client.GetOrCreateDataStructure <ValueSearchTreeDictionary <int, int> >("ValueSearchTreeDictionary").Value;
            if (dictionary == null)
            {
                return(false);
            }
            #endregion

            #region dictionary[1] = 9;
            AutoCSer.CacheServer.ReturnValue <bool> isSet = dictionary.Set(1, 9);
            if (!isSet.Value)
            {
                return(false);
            }
            #endregion

            #region 判断关键字 1 是否存在
            AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1);
            if (!isKey.Value)
            {
                return(false);
            }
            #endregion

            #region 获取关键字为 1 的数据
            AutoCSer.CacheServer.ReturnValue <int> value = dictionary.Get(1);
            if (value.Value != 9)
            {
                return(false);
            }
            #endregion

            #region 获取关键字为 1 的数字更新
            AutoCSer.CacheServer.OperationUpdater.Number <int> number1 = dictionary.GetNumberUpdater(1);
            #endregion

            #region 关键字为 1 的数据 +2
            value = number1 + 2;
            if (value.Value != 11)
            {
                return(false);
            }
            #endregion

            #region 关键字为 1 的数据 -5
            value = number1 - 5;
            if (value.Value != 6)
            {
                return(false);
            }
            #endregion

            #region 获取关键字为 1 的数据
            value = dictionary.Get(1);
            if (value.Value != 6)
            {
                return(false);
            }
            #endregion

            #region dictionary[3] = 8;
            isSet = dictionary.Set(3, 8);
            if (!isSet.Value)
            {
                return(false);
            }
            #endregion

            #region 获取逆序分页数据
            AutoCSer.CacheServer.ReturnValue <int[]> page = dictionary.GetPageDesc(1, 10);
            if (page.Value == null || page.Value.Length != 2 || page.Value[0] != 8 || page.Value[1] != 6)
            {
                return(false);
            }
            #endregion

            #region 获取字典数据数量
            AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count;
            if (count.Value != 2)
            {
                return(false);
            }
            #endregion

            #region  除关键字为 1 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1);
            if (!isRemove.Value)
            {
                return(false);
            }
            #endregion

            isRemove = dictionary.Remove(3);
            if (!isRemove.Value)
            {
                return(false);
            }
            count = dictionary.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #16
0
        /// <summary>
        /// 字典测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 Dictionary 的字典缓存
            Dictionary <int, Link <int> > dictionary = client.GetOrCreateDataStructure <Dictionary <int, Link <int> > >("Dictionary").Value;
            if (dictionary == null)
            {
                return(false);
            }
            #endregion

            #region 创建或者获取关键字为 1 的子节点
            Link <int> link = dictionary.GetOrCreate(1).Value;
            if (link == null)
            {
                return(false);
            }
            #endregion

            #region 判断是否存在关键字为 1 的子节点
            AutoCSer.CacheServer.ReturnValue <bool> isNode = dictionary.ContainsKey(1);
            if (!isNode.Value)
            {
                return(false);
            }
            #endregion

            if (!Link.TestCase(link))
            {
                return(false);
            }

            #region 创建短路径
            AutoCSer.CacheServer.ShortPath.Link <int> shortPathLink = link.CreateShortPath().Value;
            if (shortPathLink == null)
            {
                return(false);
            }
            #endregion

            if (!Link.TestCase(shortPathLink))
            {
                return(false);
            }

            #region 获取字典数据数量
            AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count;
            if (count.Value != 1)
            {
                return(false);
            }
            #endregion

            #region  除关键字为 1 的数据
            AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1);
            if (!isRemove.Value)
            {
                return(false);
            }
            count = dictionary.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }
            #endregion

            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// 数组测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            #region 创建名称为 Array 的数组缓存
            Array <ValueDictionary <int, int> > array = client.GetOrCreateDataStructure <Array <ValueDictionary <int, int> > >("Array").Value;
            if (array == null)
            {
                return(false);
            }
            #endregion

            #region 创建或者获取子节点
            ValueDictionary <int, int> dictionary = array.GetOrCreate(1).Value;
            if (dictionary == null)
            {
                return(false);
            }
            #endregion

            #region 判断第一个节点是否可用
            AutoCSer.CacheServer.ReturnValue <bool> isNode = array.IsNode(1);
            if (!isNode.Value)
            {
                return(false);
            }
            #endregion

            if (!ValueDictionary.TestCase(dictionary))
            {
                return(false);
            }

            #region 创建短路径
            AutoCSer.CacheServer.ShortPath.Dictionary <int, int> shortPathDictionary = dictionary.CreateShortPath().Value;
            if (shortPathDictionary == null)
            {
                return(false);
            }
            #endregion

            if (!ValueDictionary.TestCase(shortPathDictionary))
            {
                return(false);
            }

            #region 获取数组已使用长度
            AutoCSer.CacheServer.ReturnValue <int> count = array.Count;
            if (count.Value != 2)
            {
                return(false);
            }
            #endregion

            #region 清除所有数据
            AutoCSer.CacheServer.ReturnValue <bool> isClear = array.Clear();
            if (!isClear.Value)
            {
                return(false);
            }
            count = array.Count;
            if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0)
            {
                return(false);
            }
            #endregion

            return(true);
        }