Esempio n. 1
0
        public void WriteOneNotifyData()
        {
            CacheNotifyDataMap.ResetMap();

            CacheNotifyData data = PrepareData("Test");

            CacheNotifyDataMap.WriteCacheNotifyData(data);

            long lastTicks = 0;

            CacheNotifyData[] dataRead = CacheNotifyDataMap.ReadCacheNotifyData(ref lastTicks);

            CacheNotifyDataMapInfo mapInfo = CacheNotifyDataMap.GetCacheNotifyDataMapInfo();

            Console.WriteLine(mapInfo.Pointer);
            Console.WriteLine(lastTicks);

            Assert.AreEqual(1, mapInfo.Pointer);
            Assert.IsTrue(dataRead.Length > 0);
            Assert.IsTrue(lastTicks > 0);
            AssertCacheNotifyData(data, dataRead[0]);

            CacheNotifyData[] dataReadAgain = CacheNotifyDataMap.ReadCacheNotifyData(ref lastTicks);

            Assert.AreEqual(0, dataReadAgain.Length);
        }
Esempio n. 2
0
        public void WriteNotExistNotifyData()
        {
            CacheNotifyDataMap.ResetMap();

            CacheNotifyDataMap.WriteCacheNotifyData(PrepareData("TestExistData"));
            CacheNotifyDataMap.WriteCacheNotifyData(PrepareData("Test1"));

            long lastTicks = 0;

            CacheNotifyDataMap.WriteNotExistCacheNotifyData(lastTicks, PrepareData("TestExistData"));
            CacheNotifyDataMap.WriteNotExistCacheNotifyData(lastTicks, PrepareData("Test2"));

            CacheNotifyData[] dataRead = CacheNotifyDataMap.ReadCacheNotifyData(ref lastTicks);

            Assert.AreEqual(3, dataRead.Length);
        }
Esempio n. 3
0
        public void WriteOverflowNotifyData()
        {
            CacheNotifyDataMap.ResetMap();

            long lastTicks = DateTime.Now.Ticks;

            //会比最大项多写一项
            for (int i = 0; i <= CacheNotifyDataMapInfo.CacheDataItemCount; i++)
            {
                CacheNotifyData data = PrepareData("Test" + i.ToString());

                CacheNotifyDataMap.WriteCacheNotifyData(data);
            }

            CacheNotifyData[] dataRead = CacheNotifyDataMap.ReadCacheNotifyData(ref lastTicks);

            Assert.AreEqual(CacheNotifyDataMapInfo.CacheDataItemCount, dataRead.Length);

            bool existZeroItem = false;
            bool existLastItem = false;

            for (int i = 0; i < dataRead.Length; i++)
            {
                if (dataRead[i].CacheKey.ToString() == "Test0")
                {
                    existZeroItem = true;
                }
                else
                if (dataRead[i].CacheKey.ToString() == "Test" + CacheNotifyDataMapInfo.CacheDataItemCount)
                {
                    existLastItem = true;
                }
            }

            Assert.IsFalse(existZeroItem, "第0项应该被挤掉");
            Assert.IsTrue(existLastItem, "最后一项应该被保留");
        }