Exemplo n.º 1
0
        public virtual void TestTransactionalOfferPoll2()
        {
            ITransactionContext context = null;

            try
            {
                var latch = new ManualResetEvent(false);
                var queue = Client.GetQueue <string>(_name);
                var t     = new Thread(delegate()
                {
                    try
                    {
                        latch.WaitOne();
                        //Thread.Sleep(3000);
                        queue.Offer("item0");
                    }
                    catch
                    {
                        Assert.Fail();
                    }
                });
                t.Start();

                context = Client.NewTransactionContext();
                context.BeginTransaction();
                var    q0 = context.GetQueue <string>(_name);
                string s  = null;
                latch.Set();
                t.Join();
                try
                {
                    s = q0.Poll(20, TimeUnit.Seconds);
                }
                catch (Exception e)
                {
                    Assert.Fail(e.Message);
                }
                Assert.AreEqual("item0", s);
                context.CommitTransaction();
                context = null;
                Assert.AreEqual(0, queue.Count);
            }
            finally
            {
                if (context != null)
                {
                    context.RollbackTransaction();
                }
            }
        }