Example #1
0
 /// <summary>
 /// 补发缓存数据列表
 /// </summary>
 public static void ReissueBufferList()
 {
     try
     {
         int idx = 0;
         for (idx = 0; idx < BufferList.Count; idx++)
         {
             if (!WriteToDB(BufferList[idx]))
             {
                 break;
             }
         }
         if (0 != idx)
         {
             // 如果有补发成功的要删掉原来的缓存文件
             File.Delete(LocalBufFileName);
             StreamWriter  sw       = new StreamWriter(LocalBufFileName, false);
             List <string> tempList = new List <string>();
             for (; idx < BufferList.Count; idx++)
             {
                 tempList.Add(BufferList[idx]);
                 sw.WriteLine(BufferList[idx]);
             }
             sw.Close();
             // 清空缓存列表
             BufferList.Clear();
             BufferList = tempList;
         }
         Thread.Sleep(200);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(ex.ToString());
     }
 }
        public void GivenBufferListWhenEmptyShouldNotDispatchCleared()
        {
            var list   = new BufferList <int>(1000, TimeSpan.FromSeconds(10));
            var called = false;

            list.Cleared += _ => called = true;

            list.Clear();

            called.Should().BeFalse();
        }
Example #3
0
    public void Clear()
    {
        if (Count == 0)
        {
            return;
        }

        val2idx.Clear();
        idx2val.Clear();
        vals.Clear();
    }
        public void CheckInBuffers()
        {
            lock (_lockObject)
            {
                foreach (var buffer in BufferList)
                {
                    BufferManager.CheckIn(buffer);
                }

                BufferList.Clear();
            }
        }
Example #5
0
    public void Clear()
    {
        if (Count == 0)
        {
            return;
        }

        key2idx.Clear();
        idx2key.Clear();
        keys.Clear();
        vals.Clear();
    }
        public void GivenBufferShouldCountFailedList()
        {
            var list = new BufferList <int>(10, Timeout.InfiniteTimeSpan)
            {
                1
            };

            list.Cleared += items => throw new Exception();

            list.Clear();

            list.Count.Should().Be(1);
        }
        public async Task GivenBufferWhenFailedHasAnyShouldDispatchClearForFailedMessages()
        {
            var list           = new BufferList <int>(1, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);
            var i = 0;

            list.Cleared += removed =>
            {
                autoResetEvent.Set();
                if (++i == 1)
                {
                    throw new Exception();
                }
            };


            list.Add(1);
            autoResetEvent.WaitOne();
            await Task.Delay(300);

            list.GetFailed().Should().NotBeEmpty();
            list.Clear();
            list.GetFailed().Should().BeEmpty();
        }
Example #8
0
 public void Flush()
 {
     _publisherBuffer.Clear();
     Task.Delay(1000).Wait();
 }