Example #1
0
        private void Pulse(BatchSubscriber<int, int, int, int>.Tuple[] args)
        {
            Assert.AreEqual(NumCallsToBatch, args.Length);

            for (var ctr = 0; ctr < NumCallsToBatch; ctr++)
            {
                Assert.AreEqual(ctr, args[ctr].Item1);
                Assert.AreEqual(ctr * 2, args[ctr].Item2);
                Assert.AreEqual(ctr * 3, args[ctr].Item3);
                Assert.AreEqual(ctr * 4, args[ctr].Item4);
            }

            lock (this.pulser)
                Monitor.Pulse(this.pulser);
        }
Example #2
0
        public void TestActionObjectHandler()
        {
            Assert.IsNull(this.testActionObjectEvent);

            var batchSubscriber = new BatchSubscriber<object>(this.fiber, TimeSpan.FromMilliseconds(50), Pulse);
            this.testActionObjectEvent += batchSubscriber;

            try
            {
                Assert.IsNotNull(this.testActionObjectEvent);

                lock (pulser)
                {
                    this.testActionObjectEvent(this.pulser);
                    Assert.IsTrue(Monitor.Wait(this.pulser, 1000), "Timed out waiting for handler to pulse");

                    Assert.IsFalse(Monitor.Wait(this.pulser, 50), "Additional pulsing happened");
                }

                this.testActionObjectEvent -= batchSubscriber;

                Assert.IsNull(this.testActionObjectEvent);
            }
            finally
            {
                this.testActionObjectEvent = null;
            }
        }
Example #3
0
        public void TestAction4ArgHandler()
        {
            Assert.IsNull(this.testAction4ArgEvent);

            var eventBatchSubscriber = new BatchSubscriber<int, int, int, int>(this.fiber, TimeSpan.FromMilliseconds(50), Pulse);
            this.testAction4ArgEvent += eventBatchSubscriber;

            try
            {
                Assert.IsNotNull(this.testAction4ArgEvent);

                lock (pulser)
                {
                    for (int ctr = 0; ctr < NumCallsToBatch; ctr++)
                        this.testAction4ArgEvent(ctr, ctr * 2, ctr * 3, ctr * 4);

                    Assert.IsTrue(Monitor.Wait(this.pulser, 1000), "Timed out waiting for handler to pulse");

                    Assert.IsFalse(Monitor.Wait(this.pulser, 100), "Additional pulsing happened");
                }

                this.testAction4ArgEvent -= eventBatchSubscriber;

                Assert.IsNull(this.testAction4ArgEvent);
            }
            finally
            {
                this.testAction4ArgEvent = null;
            }
        }
        private void Pulse(BatchSubscriber<object, EventArgs<int>>.Tuple[] args)
        {
            Assert.AreEqual(NumCallsToBatch, args.Length);

            for (var ctr = 0; ctr < NumCallsToBatch; ctr++ )
            {
                Assert.AreEqual(this, args[ctr].Item1);
                Assert.AreEqual(ctr, args[ctr].Item2.Item);
            }

            lock (this.pulser)
                Monitor.Pulse(this.pulser);
        }
        private void Pulse(BatchSubscriber<object, EventArgs<object>>.Tuple[] args)
        {
            foreach (var arg in args)
            {
                Assert.AreEqual(this, arg.Item1);
                Assert.AreEqual(this.pulser, arg.Item2.Item);
            }

            lock (this.pulser)
                Monitor.Pulse(this.pulser);
        }
        private void Increment(BatchSubscriber<object, EventArgs>.Tuple[] args)
        {
            foreach (var arg in args)
            {
                Assert.AreEqual(this, arg.Item1);
                Assert.AreEqual(this.eventArgs, arg.Item2);
            }

            calls++;
            //Console.WriteLine("Increment");
        }