RAMJobStoreTest.cs :  » Business-Application » Quartz-Enterprise-Scheduler » Quartz » Tests » Unit » Simpl » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » Quartz Enterprise Scheduler 
Quartz Enterprise Scheduler » Quartz » Tests » Unit » Simpl » RAMJobStoreTest.cs
/* 
 * Copyright 2004-2006 OpenSymphony 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations 
 * under the License.
 */
using System;

using NUnit.Framework;
#if NET_20
using NullableDateTimeSystem.NullableSystem.DateTime;
#else
using Nullables;
#endif

using Quartz.Impl.Calendar;
using Quartz.Job;
using Quartz.Simpl;
using Quartz.Spi;

namespace Quartz.Tests.Unit.Simpl{
  /// <summary>
  ///  Unit test for RAMJobStore.  These tests were submitted by Johannes Zillmann
  /// as part of issue QUARTZ-306.
  /// </summary>
  [TestFixture]
  public class RAMJobStoreTest
  {
    private IJobStore fJobStore;
    private JobDetail fJobDetail;
    private SampleSignaler fSignaler;

    [SetUp]
    protected void SetUp()
    {
      fJobStore = new RAMJobStore();
      fSignaler = new SampleSignaler();
      fJobStore.Initialize(null, fSignaler);

      fJobDetail = new JobDetail("job1", "jobGroup1", typeof (NoOpJob));
      fJobDetail.Durable = true;
      fJobStore.StoreJob(null, fJobDetail, false);
    }

    [Test]
    public void TestAcquireNextTrigger()
    {
      DateTime d = DateTime.UtcNow;
      Trigger trigger1 =
        new SimpleTrigger("trigger1", "triggerGroup1", fJobDetail.Name,
                          fJobDetail.Group, d.AddSeconds(200),
                          d.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
      Trigger trigger2 =
        new SimpleTrigger("trigger2", "triggerGroup1", fJobDetail.Name,
                          fJobDetail.Group, d.AddSeconds(-100),
                                  d.AddSeconds(20), 2, TimeSpan.FromSeconds(2));
      Trigger trigger3 =
        new SimpleTrigger("trigger1", "triggerGroup2", fJobDetail.Name,
                          fJobDetail.Group, d.AddSeconds(100),
                                  d.AddSeconds(200), 2, TimeSpan.FromSeconds(2));

      trigger1.ComputeFirstFireTimeUtc(null);
      trigger2.ComputeFirstFireTimeUtc(null);
      trigger3.ComputeFirstFireTimeUtc(null);
      fJobStore.StoreTrigger(null, trigger1, false);
      fJobStore.StoreTrigger(null, trigger2, false);
      fJobStore.StoreTrigger(null, trigger3, false);

      Trigger t = fJobStore.AcquireNextTrigger(null, d.AddMilliseconds(10));
      Assert.IsNull(t);
      Assert.AreEqual(
        trigger2,
        fJobStore.AcquireNextTrigger(null, trigger1.GetNextFireTimeUtc().Value.AddSeconds(10)));
      Assert.AreEqual(
        trigger3,
        fJobStore.AcquireNextTrigger(null, trigger1.GetNextFireTimeUtc().Value.AddSeconds(10)));
      Assert.AreEqual(
        trigger1,
        fJobStore.AcquireNextTrigger(null, trigger1.GetNextFireTimeUtc().Value.AddSeconds(10)));
      Assert.IsNull(
        fJobStore.AcquireNextTrigger(null, trigger1.GetNextFireTimeUtc().Value.AddSeconds(10)));

      // because of trigger2
      Assert.AreEqual(1, fSignaler.fMisfireCount);

      // release trigger3
      fJobStore.ReleaseAcquiredTrigger(null, trigger3);
      Assert.AreEqual(
        trigger3,
        fJobStore.AcquireNextTrigger(null, trigger1.GetNextFireTimeUtc().Value.AddSeconds(10)));
    }

    [Test]
    public void TestTriggerStates()
    {
      Trigger trigger =
        new SimpleTrigger("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group,
                                  DateTime.Now.AddSeconds(100), DateTime.Now.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
      trigger.ComputeFirstFireTimeUtc(null);
      Assert.AreEqual(TriggerState.None, fJobStore.GetTriggerState(null, trigger.Name, trigger.Group));
      fJobStore.StoreTrigger(null, trigger, false);
      Assert.AreEqual(TriggerState.Normal, fJobStore.GetTriggerState(null, trigger.Name, trigger.Group));

      fJobStore.PauseTrigger(null, trigger.Name, trigger.Group);
      Assert.AreEqual(TriggerState.Paused , fJobStore.GetTriggerState(null, trigger.Name, trigger.Group));

      fJobStore.ResumeTrigger(null, trigger.Name, trigger.Group);
      Assert.AreEqual(TriggerState.Normal, fJobStore.GetTriggerState(null, trigger.Name, trigger.Group));

      trigger = fJobStore.AcquireNextTrigger(null,
                                             trigger.GetNextFireTimeUtc().Value.AddSeconds(10));
      Assert.IsNotNull(trigger);
      fJobStore.ReleaseAcquiredTrigger(null, trigger);
      trigger = fJobStore.AcquireNextTrigger(null,
                                             trigger.GetNextFireTimeUtc().Value.AddSeconds(10));
      Assert.IsNotNull(trigger);
      Assert.IsNull(fJobStore.AcquireNextTrigger(null,
                                             trigger.GetNextFireTimeUtc().Value.AddSeconds(10)));
    }

        [Test]
        public void TestRemoveCalendarWhenTriggersPresent()
        {
            // QRTZNET-29

            Trigger trigger = new SimpleTrigger("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group,
                                  DateTime.Now.AddSeconds(100), DateTime.Now.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
            trigger.ComputeFirstFireTimeUtc(null);
            ICalendar cal = new MonthlyCalendar();
            fJobStore.StoreTrigger(null, trigger, false);
            fJobStore.StoreCalendar(null, "cal", cal, false, true);

            fJobStore.RemoveCalendar(null, "cal");
        }

        [Test]
        public void TestStoreTriggerReplacesTrigger()
        {

            string jobName = "StoreTriggerReplacesTrigger";
            string jobGroup = "StoreTriggerReplacesTriggerGroup";
            JobDetail detail = new JobDetail(jobName, jobGroup, typeof(NoOpJob));
            fJobStore.StoreJob(null, detail, false);

            string trName = "StoreTriggerReplacesTrigger";
            string trGroup = "StoreTriggerReplacesTriggerGroup";
            Trigger tr = new SimpleTrigger(trName, trGroup, DateTime.Now);
            tr.JobGroup = jobGroup;
            tr.JobName = jobName;
            tr.CalendarName = null;

            fJobStore.StoreTrigger(null, tr, false);
            Assert.AreEqual(tr, fJobStore.RetrieveTrigger(null, trName, trGroup));

            tr.CalendarName = "NonExistingCalendar";
            fJobStore.StoreTrigger(null, tr, true); 
            Assert.AreEqual(tr, fJobStore.RetrieveTrigger(null, trName, trGroup));
            Assert.AreEqual(tr.CalendarName, fJobStore.RetrieveTrigger(null, trName, trGroup).CalendarName, "StoreJob doesn't replace triggers");

            bool exeptionRaised = false;
            try
            {
                fJobStore.StoreTrigger(null, tr, false);
            }
            catch (ObjectAlreadyExistsException)
            {
                exeptionRaised = true;
            }
            Assert.IsTrue(exeptionRaised, "an attempt to store duplicate trigger succeeded");
        }

      [Test]
      public void PauseJobGroupPausesNewJob()
      {
            string jobName1 = "PauseJobGroupPausesNewJob";
            string jobName2 = "PauseJobGroupPausesNewJob2";
            string jobGroup = "PauseJobGroupPausesNewJobGroup";
            JobDetail detail = new JobDetail(jobName1, jobGroup, typeof(NoOpJob));
            detail.Durable = true;
            fJobStore.StoreJob(null, detail, false);
            fJobStore.PauseJobGroup(null, jobGroup);
            
          detail = new JobDetail(jobName2, jobGroup, typeof(NoOpJob));
            detail.Durable = true;
            fJobStore.StoreJob(null, detail, false);
          
          string trName = "PauseJobGroupPausesNewJobTrigger";
            string trGroup = "PauseJobGroupPausesNewJobTriggerGroup";
            Trigger tr = new SimpleTrigger(trName, trGroup, DateTime.UtcNow);
            tr.JobGroup = jobGroup;
            tr.JobName = jobName2;
          fJobStore.StoreTrigger(null, tr, false);
          Assert.AreEqual(TriggerState.Paused, fJobStore.GetTriggerState(null, tr.Name, tr.Group));
          
      }
    public class SampleSignaler : ISchedulerSignaler
    {
      internal int fMisfireCount = 0;

      public void NotifyTriggerListenersMisfired(Trigger trigger)
      {
        fMisfireCount++;
      }

        public void NotifySchedulerListenersFinalized(Trigger trigger)
        {
            
        }

        public void SignalSchedulingChange(NullableDateTime candidateNewNextFireTimeUtc)
      {
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.