public virtual void SerializeObjects() { string name = "test-SerializeObjects" + Salt; Queue <string> rq = new Queue <string>(new string[] { "aaa", "aab", "abb", "bbb", "bbc", "bcc", "ccc" }); Queue <string> wq = new Queue <string>(new string[] { "aaa", "aab", "abb", "bbb", "bbc", "bcc", "ccc" }); AbstractChannelsFactory fc = new RabbitMQChannelsFactory(); Task tr = Task.Factory.StartNew(() => { using (IChannelReader <SerializeObjectsData> ch = fc.GetSubscribableChannel <SerializeObjectsData>(name).Subscribe()) { foreach (SerializeObjectsData item in ch.Enumerate()) { Assert.AreEqual(item.OpId, rq.Dequeue()); } Assert.IsTrue(ch.Drained); } }); Task tw = Task.Factory.StartNew(() => { using (IChannelWriter <SerializeObjectsData> ch = fc.GetSubscribableChannel <SerializeObjectsData>(name)) { while (wq.Count > 0) { ch.Write(new SerializeObjectsData() { OpId = wq.Dequeue(), Status = "test", Message = "/messaggio/lungo/con/sbarre" }); } ch.Close(); } }); Task.WaitAll(tr, tw); }
public virtual void DifferentTypesTest() { int count = 100; int[] expected = Enumerable.Range(0, count).ToArray(); List <int> actualInt = new List <int>(); string testString = "test"; string queueName = "test-DifferentTypesTest" + Salt; using (ISubscribableChannel <int> c = new mq.SubscribableChannel <int>(queueName)) using (ISubscribableChannel <string> w = new mq.SubscribableChannel <string>(queueName)) { IChannelReader <string> t = w.Subscribe(); IChannelReader <int> x = c.Subscribe(); Task.Factory.StartNew(() => { for (int i = 0; i < count; i++) { if (i == 2) { w.Write(testString); } c.Write(i); } c.Close(); }); string val = t.Read(); foreach (int item in x.Enumerate()) { actualInt.Add(item); } w.Write(testString + "1"); val = t.Read(); Assert.AreEqual(val, testString + "1"); Assert.IsFalse(t.Drained); Assert.IsTrue(x.Drained); } }