Пример #1
0
        public virtual void Sync_Transactional_2()
        {
            int expected = 3;

            using (INamedChannel <int> c = new mq.Channel <int>("test-sync" + Salt))
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(Timeblok);
                    c.Write(expected);
                });

                IAbortableOperation <int> res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Abort();
                res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Abort();

                res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Commit();

                try
                {
                    c.Consume(Timeblok / 2);
                    Assert.Fail("Expected exception.");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }
            }
        }
Пример #2
0
        public virtual void Sync_Transactional()
        {
            int expected = 3;

            using (INamedChannel <int> c = new mq.Channel <int>("test-sync" + Salt))
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(Timeblok);
                    c.Write(expected);
                });

                try
                {
                    c.Consume(p => { throw new Exception(); }, Timeblok * 20);
                    Assert.Fail();
                }
                catch (OperationCanceledException e)
                { }

                try
                {
                    c.Consume(p => { throw new Exception(); }, Timeblok * 20);
                    Assert.Fail();
                }
                catch (OperationCanceledException e)
                { }

                c.Consume(p => Assert.AreEqual(expected, p), Timeblok * 20);

                try
                {
                    c.Consume(p => Assert.AreEqual(expected, p), Timeblok / 2);
                    Assert.Fail("Expected exception.");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }
            }
        }