Beispiel #1
0
        public virtual void TestRepeatingThread()
        {
            AtomicInteger counter = new AtomicInteger();

            MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext();
            ctx.AddThread(new _RepeatingTestThread_118(counter, ctx));
            ctx.StartThreads();
            long st = Time.Now();

            ctx.WaitFor(3000);
            ctx.Stop();
            long et      = Time.Now();
            long elapsed = et - st;

            // Test should have waited just about 3 seconds
            Assert.True("Test took " + (et - st) + "ms", Math.Abs(elapsed -
                                                                  3000) < 500);
            // Counter should have been incremented lots of times in 3 full seconds
            Assert.True("Counter value = " + counter.Get(), counter.Get() >
                        1000);
        }
Beispiel #2
0
        public virtual void TestNoErrors()
        {
            AtomicInteger threadsRun = new AtomicInteger();

            MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext();
            for (int i = 0; i < 3; i++)
            {
                ctx.AddThread(new _TestingThread_42(threadsRun, ctx));
            }
            Assert.Equal(0, threadsRun.Get());
            ctx.StartThreads();
            long st = Time.Now();

            ctx.WaitFor(30000);
            long et = Time.Now();

            // All threads should have run
            Assert.Equal(3, threadsRun.Get());
            // Test shouldn't have waited the full 30 seconds, since
            // the threads exited faster than that.
            Assert.True("Test took " + (et - st) + "ms", et - st < 5000);
        }
Beispiel #3
0
        public virtual void TestThreadThrowsCheckedException()
        {
            MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext();
            ctx.AddThread(new _TestingThread_91(ctx));
            ctx.StartThreads();
            long st = Time.Now();

            try
            {
                ctx.WaitFor(30000);
                NUnit.Framework.Assert.Fail("waitFor did not throw");
            }
            catch (RuntimeException rte)
            {
                // expected
                Assert.Equal("my ioe", rte.InnerException.Message);
            }
            long et = Time.Now();

            // Test shouldn't have waited the full 30 seconds, since
            // the thread throws faster than that
            Assert.True("Test took " + (et - st) + "ms", et - st < 5000);
        }
Beispiel #4
0
 public _TestingThread_66(MultithreadedTestUtil.TestContext baseArg1)
     : base(baseArg1)
 {
 }
Beispiel #5
0
 public _TestingThread_42(AtomicInteger threadsRun, MultithreadedTestUtil.TestContext
                          baseArg1)
     : base(baseArg1)
 {
     this.threadsRun = threadsRun;
 }
Beispiel #6
0
 public _RepeatingTestThread_118(AtomicInteger counter, MultithreadedTestUtil.TestContext
                                 baseArg1)
     : base(baseArg1)
 {
     this.counter = counter;
 }
 public RepeatingTestThread(MultithreadedTestUtil.TestContext ctx)
     : base(ctx)
 {
 }
 public TestingThread(MultithreadedTestUtil.TestContext ctx)
 {
     this.ctx = ctx;
 }