コード例 #1
0
        public void WrapsJobFactoryException()
        {
            JobExecutionContext context = new JobExecutionContext(
                Mocks.CreateMock <IScheduler>(), Mocks.CreateMock <ILogger>(),
                new JobSpec("job", "description", "key", Mocks.CreateMock <Trigger>()), null);

            IJobFactory jobFactory = Mocks.CreateMock <IJobFactory>();

            Expect.Call(jobFactory.GetJob("key")).Throw(new Exception("Ack!"));
            Mocks.ReplayAll();

            DefaultJobRunner jobRunner = new DefaultJobRunner(jobFactory);

            jobRunner.BeginExecute(context, null, null);
        }
コード例 #2
0
        public void CreateRunnerAndExecuteJob_WithCallback()
        {
            JobExecutionContext context = new JobExecutionContext(
                Mocks.CreateMock <IScheduler>(), Mocks.CreateMock <ILogger>(),
                new JobSpec("job", "description", "key", Mocks.CreateMock <Trigger>()), null);

            IJobFactory jobFactory = Mocks.CreateMock <IJobFactory>();
            IJob        job        = Mocks.CreateMock <IJob>();

            Expect.Call(jobFactory.GetJob("key")).Return(job);
            Expect.Call(job.Execute(context)).Return(true);
            Expect.Call(delegate { jobFactory.ReleaseJob(null); }).IgnoreArguments();

            Mocks.ReplayAll();

            DefaultJobRunner runner = new DefaultJobRunner(jobFactory);

            IAsyncResult resultPassedToCallback = null;
            object       barrier = new object();

            IAsyncResult asyncResult = runner.BeginExecute(context, delegate(IAsyncResult r)
            {
                resultPassedToCallback = r;

                lock (barrier)
                    Monitor.PulseAll(barrier);
            }, "state");

            lock (barrier)
                if (resultPassedToCallback == null)
                {
                    Monitor.Wait(barrier, 10000);
                }

            Assert.AreEqual("state", asyncResult.AsyncState);
            Assert.IsNotNull(asyncResult.AsyncWaitHandle);
            Assert.IsFalse(asyncResult.CompletedSynchronously);
            Assert.IsTrue(runner.EndExecute(asyncResult));
            Assert.IsTrue(asyncResult.IsCompleted);

            Assert.AreSame(asyncResult, resultPassedToCallback);
        }
コード例 #3
0
ファイル: DefaultJobRunnerTest.cs プロジェクト: QMTech/Attic
		public void CreateRunnerAndExecuteJob_WithCallback()
		{
			JobExecutionContext context = new JobExecutionContext(
				Mocks.CreateMock<IScheduler>(), Mocks.CreateMock<ILogger>(),
				new JobSpec("job", "description", "key", Mocks.CreateMock<Trigger>()), null);

			IJobFactory jobFactory = Mocks.CreateMock<IJobFactory>();
			IJob job = Mocks.CreateMock<IJob>();

			Expect.Call(jobFactory.GetJob("key")).Return(job);
			Expect.Call(job.Execute(context)).Return(true);
			Expect.Call(delegate { jobFactory.ReleaseJob(null); }).IgnoreArguments();

			Mocks.ReplayAll();

			DefaultJobRunner runner = new DefaultJobRunner(jobFactory);

			IAsyncResult resultPassedToCallback = null;
			object barrier = new object();

			IAsyncResult asyncResult = runner.BeginExecute(context, delegate(IAsyncResult r)
			{
				resultPassedToCallback = r;

				lock (barrier)
					Monitor.PulseAll(barrier);
			}, "state");

			lock (barrier)
				if (resultPassedToCallback == null)
					Monitor.Wait(barrier, 10000);

			Assert.AreEqual("state", asyncResult.AsyncState);
			Assert.IsNotNull(asyncResult.AsyncWaitHandle);
			Assert.IsFalse(asyncResult.CompletedSynchronously);
			Assert.IsTrue(runner.EndExecute(asyncResult));
			Assert.IsTrue(asyncResult.IsCompleted);

			Assert.AreSame(asyncResult, resultPassedToCallback);
		}
コード例 #4
0
		public void CreateRunnerAndExecuteJob_NoCallback()
		{
			JobExecutionContext context = new JobExecutionContext(
				Mocks.CreateMock<IScheduler>(), Mocks.CreateMock<ILogger>(),
				new JobSpec("job", "description", "key", Mocks.CreateMock<Trigger>()), null);

			IJobFactory jobFactory = Mocks.CreateMock<IJobFactory>();
			IJob job = Mocks.CreateMock<IJob>();

			Expect.Call(jobFactory.GetJob("key")).Return(job);
			Expect.Call(job.Execute(context)).Return(true);
			Expect.Call(delegate { jobFactory.ReleaseJob(null); }).IgnoreArguments();

			Mocks.ReplayAll();

			DefaultJobRunner runner = new DefaultJobRunner(jobFactory);
			IAsyncResult asyncResult = runner.BeginExecute(context, null, "state");
			Assert.AreEqual("state", asyncResult.AsyncState);
			Assert.IsNotNull(asyncResult.AsyncWaitHandle);
			Assert.IsFalse(asyncResult.CompletedSynchronously);
			Assert.IsTrue(runner.EndExecute(asyncResult));
			Assert.IsTrue(asyncResult.IsCompleted);
		}
コード例 #5
0
        public void CreateRunnerAndExecuteJob_NoCallback()
        {
            JobExecutionContext context = new JobExecutionContext(
                Mocks.CreateMock <IScheduler>(), Mocks.CreateMock <ILogger>(),
                new JobSpec("job", "description", "key", Mocks.CreateMock <Trigger>()), null);

            IJobFactory jobFactory = Mocks.CreateMock <IJobFactory>();
            IJob        job        = Mocks.CreateMock <IJob>();

            Expect.Call(jobFactory.GetJob("key")).Return(job);
            Expect.Call(job.Execute(context)).Return(true);
            Expect.Call(delegate { jobFactory.ReleaseJob(null); }).IgnoreArguments();

            Mocks.ReplayAll();

            DefaultJobRunner runner      = new DefaultJobRunner(jobFactory);
            IAsyncResult     asyncResult = runner.BeginExecute(context, null, "state");

            Assert.AreEqual("state", asyncResult.AsyncState);
            Assert.IsNotNull(asyncResult.AsyncWaitHandle);
            Assert.IsFalse(asyncResult.CompletedSynchronously);
            Assert.IsTrue(runner.EndExecute(asyncResult));
            Assert.IsTrue(asyncResult.IsCompleted);
        }
コード例 #6
0
		public void WrapsJobFactoryException()
		{
			JobExecutionContext context = new JobExecutionContext(
				Mocks.CreateMock<IScheduler>(), Mocks.CreateMock<ILogger>(),
				new JobSpec("job", "description", "key", Mocks.CreateMock<Trigger>()), null);

			IJobFactory jobFactory = Mocks.CreateMock<IJobFactory>();
			Expect.Call(jobFactory.GetJob("key")).Throw(new Exception("Ack!"));
			Mocks.ReplayAll();

			DefaultJobRunner jobRunner = new DefaultJobRunner(jobFactory);

			jobRunner.BeginExecute(context, null, null);
		}