示例#1
0
        public void TestAdd()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());


            var valueA = "a";

            Assert.IsTrue(testSet.Add(valueA));
            Assert.IsFalse(testSet.Add(valueA));
        }
示例#2
0
        public void TestClear()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());


            testSet.Add("a");
            testSet.Add("b");
            Assert.IsTrue(testSet.Count > 0, "count before clear");
            testSet.Clear();
            Assert.IsFalse(testSet.Count > 0, "count after clear");
        }
示例#3
0
        public void TestIsSubsetOf()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());

            var bSet = new[] { "a", "b", "c" };
            var dSet = new[] { "b", "c", "d" };

            testSet.Add("a");
            testSet.Add("b");

            Assert.IsTrue(testSet.IsSubsetOf(bSet));
            Assert.IsFalse(testSet.IsSubsetOf(dSet));
        }
示例#4
0
        public void TestOverlaps()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());

            var bSet = new[] { "a", "b", "c" };
            var dSet = new[] { "b", "c", "d" };

            testSet.Add("a");
            testSet.Add("b");
            testSet.Add("c");

            Assert.IsTrue(testSet.Overlaps(bSet));
            Assert.IsTrue(testSet.Overlaps(dSet));
        }
示例#5
0
        public void Send()
        {
            var allEndpoints = new ThreadSafeSet <Endpoint>();

            while (_continueSending)
            {
                if (!_choke.ShouldBeginSend())
                {
                    continue;
                }

                var endpoints = gatherEndpoints(allEndpoints.All()).ToArray();
                if (!endpoints.Any())
                {
                    _choke.NoMessagesToSend();
                    continue;
                }
                allEndpoints.Add(endpoints);

                endpoints.Each(endpoint =>
                {
                    var messages = gatherMessagesToSend(endpoint);
                    if (!messages.Any())
                    {
                        allEndpoints.Remove(endpoint);
                        return;
                    }

                    _choke.StartSend();

                    sendMessages(endpoint, messages)
                    .ContinueWith(x => allEndpoints.Remove(endpoint));
                });
            }
        }
示例#6
0
 public void AddCells(IEnumerable <AbsoluteEntityCell> cells)
 {
     foreach (AbsoluteEntityCell cell in cells)
     {
         visibleCells.Add(cell);
     }
 }
        public void Send()
        {
            var allEndpoints = new ThreadSafeSet<Endpoint>();
            while (_continueSending)
            {
                if(!_choke.ShouldBeginSend())
                    continue;

                var endpoints = gatherEndpoints(allEndpoints.All()).ToArray();
                if (!endpoints.Any())
                {
                    _choke.NoMessagesToSend();
                    continue;
                }
                allEndpoints.Add(endpoints);

                endpoints.Each(endpoint =>
                {
                    var messages = gatherMessagesToSend(endpoint);

                    _choke.StartSend();

                    sendMessages(endpoint, messages)
                        .ContinueWith(x => allEndpoints.Remove(endpoint));
                });
            }
        }
示例#8
0
        public void TestSymmetricExceptWith()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());

            var bSet = new[] { "b" };

            testSet.Add("a");
            testSet.Add("b");

            testSet.SymmetricExceptWith(bSet);

            Assert.AreEqual("a", testSet.Single());

            testSet.SymmetricExceptWith(bSet);

            Assert.AreEqual(2, testSet.Count);
        }
示例#9
0
        public void TestIntersectWith()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());

            var bSet = new[] { "b" };

            testSet.Add("a");
            testSet.Add("b");

            testSet.IntersectWith(bSet);

            Assert.AreEqual("b", testSet.Single());

            testSet.IntersectWith(bSet);

            Assert.AreEqual("b", testSet.Single());
        }
示例#10
0
        public void TestContains()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());


            testSet.Add("a");
            Assert.IsTrue(testSet.Contains("a"), "contains valid");
            Assert.IsFalse(testSet.Contains("b"), "contains invalid");
        }
示例#11
0
        private ThreadSafeSet <string> FilledStringSet()
        {
            var hs = new ThreadSafeSet <string>();

            for (int i = 0; i != SourceDataLen; ++i)
            {
                hs.Add(SourceData[i]);
            }
            return(hs);
        }
示例#12
0
        public void EqualityComparer()
        {
            var hs = new ThreadSafeSet <string>(StringComparer.InvariantCultureIgnoreCase);

            hs.Add("Weißbier");
            Assert.IsTrue(hs.Contains("WEISSBIER"));
            Assert.IsTrue(hs.Contains("weissbier"));
            hs.Add("Δίος");
            Assert.AreEqual(2, hs.Count);
            Assert.IsTrue(hs.Contains("ΔΊΟΣ"));
            Assert.IsTrue(hs.Contains("δίος"));
            Assert.IsFalse(hs.Contains("δίοςδίος"));
            Assert.IsFalse(hs.Contains("Eggplant"));
            Assert.IsFalse(hs.Remove("aubergine"));
            Assert.IsTrue(hs.Remove("Δίος"));
            Assert.IsTrue(hs.Remove("WEISSBIER"));
            Assert.IsFalse(hs.Contains("WEISSBIER"));
            Assert.IsFalse(hs.Remove("WEISSBIER"));
            Assert.AreEqual(hs.Count, 0);
        }
示例#13
0
        public void BackAgainDiff()
        {
            var hs = new ThreadSafeSet <string>();

            for (int i = 0; i < SourceDataLen; i += 2)
            {
                hs.Add(SourceData[i]);
            }
            int count = SourceDataLen / 2;

            while (count != 0)
            {
                --count;
                hs.Remove(SourceData[count * 2]);
            }
            for (int i = 1; i < SourceDataLen; i += 2)
            {
                hs.Add(SourceData[i]);
            }
            Assert.AreEqual(SourceDataLen / 2, hs.Count);
        }
示例#14
0
        public void TestCopyTo()
        {
            var testSet = new ThreadSafeSet <string>(new HashSet <string>());


            testSet.Add("a");

            string[] array = new string[1];
            testSet.CopyTo(array, 0);
            Assert.AreEqual("a", array[0]);
            Assert.AreEqual(1, array.Length);
        }
示例#15
0
        public void EqualityComparer()
        {
            if (!StringComparer.InvariantCultureIgnoreCase.Equals("Weißbier", "WEISSBIER"))
            {
                Assert.Ignore("Bugs in Mono make this test irrelevant. When the bug is fixed, this test will run.");
            }
            var hs = new ThreadSafeSet <string>(StringComparer.InvariantCultureIgnoreCase);

            hs.Add("Weißbier");
            Assert.IsTrue(hs.Contains("WEISSBIER"));
            Assert.IsTrue(hs.Contains("weissbier"));
            hs.Add("Δίος");
            Assert.AreEqual(2, hs.Count);
            Assert.IsTrue(hs.Contains("ΔΊΟΣ"));
            Assert.IsTrue(hs.Contains("δίος"));
            Assert.IsFalse(hs.Contains("δίοςδίος"));
            Assert.IsFalse(hs.Contains("Eggplant"));
            Assert.IsFalse(hs.Remove("aubergine"));
            Assert.IsTrue(hs.Remove("Δίος"));
            Assert.IsTrue(hs.Remove("WEISSBIER"));
            Assert.IsFalse(hs.Contains("WEISSBIER"));
            Assert.IsFalse(hs.Remove("WEISSBIER"));
            Assert.AreEqual(hs.Count, 0);
        }
示例#16
0
        public void Serialisation()
        {
            //Note that the behaviour of the BinaryFormatter will fix some of the strings
            //used in many of these tests, as not being valid Unicode. This is desirable behaviour
            //in real code, but would give false negatives to this test.
            var hs = new ThreadSafeSet <string>(Enumerable.Range(0, 10000).Select(i => i.ToString()));

            hs.Add(null);
            using (MemoryStream ms = new MemoryStream())
            {
                new BinaryFormatter().Serialize(ms, hs);
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                Assert.IsTrue(EqualSets(hs, (ThreadSafeSet <string>) new BinaryFormatter().Deserialize(ms)));
            }
        }
示例#17
0
        public QueueManager(IPEndPoint endpoint, string path, QueueManagerConfiguration configuration, ILogger logger = null)
        {
            Configuration = configuration;

            _endpoint     = endpoint;
            _path         = path;
            _logger       = logger ?? LogManager.GetLogger(GetType());
            _queueStorage = new QueueStorage(path, configuration);
            _queueStorage.Initialize();

            _queueStorage.Global(actions =>
            {
                _receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds());
            });

            HandleRecovery();
        }
示例#18
0
        public QueueManager(IPEndPoint endpoint, string path, QueueManagerConfiguration configuration)
        {
            Configuration = configuration;

            this.endpoint = endpoint;
            this.path     = path;
            queueStorage  = new QueueStorage(path, configuration);
            queueStorage.Initialize();

            queueStorage.Global(actions =>
            {
                receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds());

                actions.Commit();
            });

            HandleRecovery();
        }
示例#19
0
        public QueueManager(IPEndPoint endpoint, string path)
        {
            NumberOfMessagesToKeepInProcessedQueues = 100;
            NumberOfMessagesToKeepOutgoingQueues    = 100;
            NumberOfReceivedMessagesToKeep          = 100000;
            OldestMessageInProcessedQueues          = TimeSpan.FromDays(3);
            OldestMessageInOutgoingQueues           = TimeSpan.FromDays(3);

            this.endpoint = endpoint;
            this.path     = path;
            queueStorage  = new QueueStorage(path);
            queueStorage.Initialize();

            queueStorage.Global(actions =>
            {
                receivedMsgs.Add(actions.GetAlreadyReceivedMessageIds());

                actions.Commit();
            });

            receiver = new Receiver(endpoint, AcceptMessages);
            receiver.Start();

            HandleRecovery();

            queuedMessagesSender = new QueuedMessagesSender(queueStorage, this);
            sendingThread        = new Thread(queuedMessagesSender.Send)
            {
                IsBackground = true,
                Name         = "Rhino Queue Sender Thread for " + path
            };
            sendingThread.Start();
            purgeOldDataTimer = new Timer(PurgeOldData, null,
                                          TimeSpan.FromMinutes(3),
                                          TimeSpan.FromMinutes(3));
        }
 /// <summary>Tries to add a new item to the collection.</summary>
 /// <returns>True if the element was added, false if there was already a matching element.</returns>
 /// <param name="item">Item to add.</param>
 public bool TryAdd(T item)
 {
     return(_store.Add(item));
 }