Quartz.NET 0.9.1, syncing with latest CVS changes

This commit is contained in:
lahma
2008-06-10 08:26:01 +00:00
parent 26c254d5f1
commit fcbeb707ff
15 changed files with 158 additions and 35 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -54,7 +54,7 @@ namespace Spring.Scheduling.Quartz
{
private JobDetail jobDetail;
private string objectName;
private readonly Constants constants = new Constants(typeof(MisfirePolicy.CronTrigger), typeof(MisfirePolicy));
private readonly Constants constants = new Constants(typeof(MisfireInstruction.CronTrigger), typeof(MisfireInstruction));
/// <summary>
@@ -73,11 +73,11 @@ namespace Spring.Scheduling.Quartz
/// <summary>
/// Set the misfire instruction via the name of the corresponding
/// constant in the CronTrigger class.
/// Default is <code>MISFIRE_INSTRUCTION_SMART_POLICY</code>.
/// Default is <see cref="MisfireInstruction.SmartPolicy" />.
/// </summary>
/// <seealso cref="MisfirePolicy.CronTrigger.FireOnceNow" />
/// <seealso cref="MisfirePolicy.CronTrigger.DoNothing" />
/// <seealso cref="MisfirePolicy.SmartPolicy" />
/// <seealso cref="MisfireInstruction.CronTrigger.FireOnceNow" />
/// <seealso cref="MisfireInstruction.CronTrigger.DoNothing" />
/// <seealso cref="MisfireInstruction.SmartPolicy" />
public virtual string MisfireInstructionName
{
set
@@ -154,7 +154,7 @@ namespace Spring.Scheduling.Quartz
}
if (Group == null)
{
Group = SchedulerConstants.DEFAULT_GROUP;
Group = SchedulerConstants.DefaultGroup;
}
if (StartTimeUtc == DateTime.MinValue)
{

View File

@@ -33,7 +33,7 @@ namespace Spring.Scheduling.Quartz
/// <author>Juergen Hoeller</author>
/// <seealso cref="JobDetail.Name" />
/// <seealso cref="JobDetail.Group" />
/// <seealso cref="SchedulerConstants.DEFAULT_GROUP" />
/// <seealso cref="SchedulerConstants.DefaultGroup" />
public class JobDetailObject : JobDetail, IObjectNameAware, IApplicationContextAware, IInitializingObject
{
private Type actualJobType;
@@ -200,7 +200,7 @@ namespace Spring.Scheduling.Quartz
}
if (Group == null)
{
Group = SchedulerConstants.DEFAULT_GROUP;
Group = SchedulerConstants.DefaultGroup;
}
if (applicationContextJobDataKey != null)
{

View File

@@ -65,7 +65,7 @@ namespace Spring.Scheduling.Quartz
/// </summary>
public MethodInvokingJobDetailFactoryObject()
{
group = SchedulerConstants.DEFAULT_GROUP;
group = SchedulerConstants.DefaultGroup;
}
@@ -84,7 +84,7 @@ namespace Spring.Scheduling.Quartz
/// Default is the default group of the Scheduler.
/// </summary>
/// <seealso cref="JobDetail.Group" />
/// <seealso cref="SchedulerConstants.DEFAULT_GROUP" />
/// <seealso cref="SchedulerConstants.DefaultGroup" />
public virtual string Group
{
set { group = value; }

View File

@@ -679,12 +679,12 @@ namespace Spring.Scheduling.Quartz
// its default configuration when explicitly given properties.
if (taskExecutor != null)
{
mergedProps[StdSchedulerFactory.PROP_THREAD_POOL_CLASS] =
mergedProps[StdSchedulerFactory.PropertyThreadPoolType] =
typeof (LocalTaskExecutorThreadPool).FullName;
}
else
{
mergedProps.Set(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, typeof (SimpleThreadPool).Name);
mergedProps.Set(StdSchedulerFactory.PropertyThreadPoolType, typeof(SimpleThreadPool).Name);
mergedProps[PROP_THREAD_COUNT] = Convert.ToString(DEFAULT_THREAD_COUNT);
}
@@ -697,25 +697,29 @@ namespace Spring.Scheduling.Quartz
using (StreamReader sr = new StreamReader(configLocation.InputStream))
{
string line;
while ((line =sr.ReadLine()) != null)
while ((line = sr.ReadLine()) != null)
{
string[] lineItems = line.Split('=');
string[] lineItems = line.Split(new char[] { '=' }, 2);
if (lineItems.Length == 2)
{
mergedProps[lineItems[0]] = lineItems[1];
mergedProps[lineItems[0].Trim()] = lineItems[1].Trim();
}
}
}
}
MergePropertiesIntoMap(quartzProperties, mergedProps);
if (quartzProperties != null)
{
// if given quartz properties, merge to them to configuration
MergePropertiesIntoMap(quartzProperties, mergedProps);
}
// Make sure to set the scheduler name as configured in the Spring configuration.
if (schedulerName != null)
{
mergedProps.Add(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, schedulerName);
mergedProps.Add(StdSchedulerFactory.PropertySchedulerInstanceName, schedulerName);
}
((StdSchedulerFactory) schedulerFactory).Initialize(mergedProps);

View File

@@ -54,14 +54,14 @@ namespace Spring.Scheduling.Quartz
private long startDelay = 0;
private JobDetail jobDetail;
private string objectName;
private readonly Constants constants = new Constants(typeof(MisfirePolicy.SimpleTrigger), typeof(MisfirePolicy));
private readonly Constants constants = new Constants(typeof(MisfireInstruction.SimpleTrigger), typeof(MisfireInstruction));
/// <summary>
/// Initializes a new instance of the <see cref="SimpleTriggerObject"/> class.
/// </summary>
public SimpleTriggerObject()
{
RepeatCount = REPEAT_INDEFINITELY;
RepeatCount = RepeatIndefinitely;
}
/// <summary>
@@ -80,14 +80,14 @@ namespace Spring.Scheduling.Quartz
/// <summary>
/// Set the misfire instruction via the name of the corresponding
/// constant in the SimpleTrigger class.
/// Default is <see cref="MisfirePolicy.SmartPolicy" />.
/// Default is <see cref="MisfireInstruction.SmartPolicy" />.
/// </summary>
/// <seealso cref="MisfirePolicy.SimpleTrigger.FireNow" />
/// <seealso cref="MisfirePolicy.SimpleTrigger.RescheduleNextWithExistingCount" />
/// <seealso cref="MisfirePolicy.SimpleTrigger.RescheduleNextWithRemainingCount" />
/// <seealso cref="MisfirePolicy.SimpleTrigger.RescheduleNowWithExistingRepeatCount" />
/// <seealso cref="MisfirePolicy.SimpleTrigger.RescheduleNowWithRemainingRepeatCount" />
/// <seealso cref="MisfirePolicy.SmartPolicy" />
/// <seealso cref="MisfireInstruction.SimpleTrigger.FireNow" />
/// <seealso cref="MisfireInstruction.SimpleTrigger.RescheduleNextWithExistingCount" />
/// <seealso cref="MisfireInstruction.SimpleTrigger.RescheduleNextWithRemainingCount" />
/// <seealso cref="MisfireInstruction.SimpleTrigger.RescheduleNowWithExistingRepeatCount" />
/// <seealso cref="MisfireInstruction.SimpleTrigger.RescheduleNowWithRemainingRepeatCount" />
/// <seealso cref="MisfireInstruction.SmartPolicy" />
public virtual string MisfireInstructionName
{
set
@@ -179,7 +179,7 @@ namespace Spring.Scheduling.Quartz
}
if (Group == null)
{
Group = SchedulerConstants.DEFAULT_GROUP;
Group = SchedulerConstants.DefaultGroup;
}
if (StartTimeUtc == DateTime.MinValue)
{

View File

@@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -9,6 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
<AssemblyName>Spring.Scheduling.Quartz</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@@ -15,6 +15,7 @@
*/
using System;
using System.Collections;
using NUnit.Framework;
@@ -86,6 +87,15 @@ namespace Spring.Scheduling.Quartz
Assert.AreSame(jd, cronTrigger.JobDetail, "job details weren't same");
}
[Test]
public void TestJobDataAsMap()
{
Hashtable data = new Hashtable();
data["foo"] = "bar";
data["number"] = 123;
cronTrigger.JobDataAsMap = data;
CollectionAssert.AreEqual(data, cronTrigger.JobDataMap, "Data differed");
}
}

View File

@@ -90,7 +90,7 @@ namespace Spring.Scheduling.Quartz
jobDetail.ObjectName = objectName;
jobDetail.Group = null;
jobDetail.AfterPropertiesSet();
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, jobDetail.Group, "Groups differ");
Assert.AreEqual(SchedulerConstants.DefaultGroup, jobDetail.Group, "Groups differ");
Assert.AreEqual(objectName, jobDetail.Name, "Names differ");
}
@@ -113,9 +113,13 @@ namespace Spring.Scheduling.Quartz
{
const string objectName = "springJobDetailObject";
jobDetail.ObjectName = objectName;
jobDetail.ApplicationContext = new XmlApplicationContext();
jobDetail.ApplicationContextJobDataKey = "applicationContextJobDataKey";
XmlApplicationContext ctx = new XmlApplicationContext();
jobDetail.ApplicationContext = ctx;
string key = "applicationContextJobDataKey";
jobDetail.ApplicationContextJobDataKey = key;
jobDetail.AfterPropertiesSet();
Assert.AreSame(ctx, jobDetail.ApplicationContext, "ApplicationContext was not set correctly");
Assert.AreSame(ctx, jobDetail.JobDataMap[key], "ApplicationContext was not set to job data map");
}
[Test]

View File

@@ -92,6 +92,17 @@ namespace Spring.Scheduling.Quartz
Assert.AreEqual(1, job.CounterValue, "Job was not invoked once");
}
[Test]
public void TestMethodInvoker_PrivateMethod()
{
InvocationCountingJob job = new InvocationCountingJob();
MethodInvoker mi = new MethodInvoker();
mi.TargetObject = job;
mi.TargetMethod = "PrivateMethod";
mi.Prepare();
methodInvokingJob.MethodInvoker = mi;
methodInvokingJob.Execute(CreateMinimalJobExecutionContext());
}
private static JobExecutionContext CreateMinimalJobExecutionContext()
{
@@ -130,6 +141,9 @@ namespace Spring.Scheduling.Quartz
throw new Exception();
}
private void PrivateMethod()
{
}
public int CounterValue
{

View File

@@ -16,6 +16,10 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using NUnit.Framework;
@@ -25,6 +29,8 @@ using Quartz.Impl;
using Rhino.Mocks;
using Spring.Core.IO;
namespace Spring.Scheduling.Quartz
{
/// <summary>
@@ -34,7 +40,9 @@ namespace Spring.Scheduling.Quartz
[TestFixture]
public class SchedulerFactoryObjectTest
{
private MockRepository mockery = null;
private static readonly MethodInfo m_InitSchedulerFactory = typeof(SchedulerFactoryObject).GetMethod("InitSchedulerFactory",
BindingFlags.Instance | BindingFlags.NonPublic);
private MockRepository mockery;
private SchedulerFactoryObject factory;
[SetUp]
@@ -256,6 +264,48 @@ namespace Spring.Scheduling.Quartz
factory.SchedulerFactoryType = typeof(StdSchedulerFactory);
}
[Test]
public void TestInitSchedulerFactory_MinimalDefaults()
{
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerName = "testFactoryObject";
StdSchedulerFactory factoryToPass = new StdSchedulerFactory();
m_InitSchedulerFactory.Invoke(factory, new object[] { factoryToPass });
}
[Test]
public void TestInitSchedulerFactory_ConfigLocationReadingShouldPreserverExtraEqualsMarksAndTrimKeysAndValues()
{
const string ConnectionStringValue = "Server=(local);Database=quartz;Trusted_Connection=True;";
const string ConnectionStringKey = "quartz.dataSource.default.connectionString";
string configuration =
@"quartz.jobStore.type = Quartz.Impl.AdoJobStore.JobStoreTX, Quartz
quartz.jobStore.useProperties = false
quartz.jobStore.dataSource = default" + Environment.NewLine +
ConnectionStringKey+ " = " + ConnectionStringValue + Environment.NewLine +
"quartz.dataSource.default.provider = SqlServer-20";
// initialize data
MemoryStream ms = new MemoryStream();
byte[] data = Encoding.UTF8.GetBytes(configuration);
ms.Write(data, 0, data.Length);
ms.Seek(0, SeekOrigin.Begin);
ms.Position = 0;
// intercept call
InterceptingStdSChedulerFactory factoryToPass = new InterceptingStdSChedulerFactory();
TestSchedulerFactory.Mockery.ReplayAll();
factory.ConfigLocation = new TestConfigLocation(ms, "description");
m_InitSchedulerFactory.Invoke(factory, new object[] { factoryToPass });
Assert.AreEqual(ConnectionStringValue, factoryToPass.Properties[ConnectionStringKey]);
}
[TearDown]
public void TearDown()
{
@@ -269,6 +319,13 @@ namespace Spring.Scheduling.Quartz
}
internal class TestConfigLocation : InputStreamResource
{
public TestConfigLocation(Stream inputStream, string description) : base(inputStream, description)
{
}
}
public class TestSchedulerFactory : ISchedulerFactory
{
private static readonly MockRepository mockery = new MockRepository();
@@ -305,5 +362,18 @@ namespace Spring.Scheduling.Quartz
}
}
public class InterceptingStdSChedulerFactory : StdSchedulerFactory
{
private NameValueCollection properties;
public override void Initialize(NameValueCollection props)
{
this.properties = props;
}
public NameValueCollection Properties
{
get { return properties; }
}
}
}

View File

@@ -15,6 +15,7 @@
*/
using System;
using System.Collections;
using NUnit.Framework;
@@ -92,6 +93,16 @@ namespace Spring.Scheduling.Quartz
Assert.AreSame(jd, simpleTrigger.JobDetail, "job details weren't same");
}
[Test]
public void TestJobDataAsMap()
{
Hashtable data = new Hashtable();
data["foo"] = "bar";
data["number"] = 123;
simpleTrigger.JobDataAsMap = data;
CollectionAssert.AreEqual(data, simpleTrigger.JobDataMap, "Data differed");
}
}
}

View File

@@ -41,10 +41,10 @@ namespace Spring.Scheduling.Quartz
public virtual void TestAfterPropertiesSet_Defaults()
{
Assert.AreEqual(TRIGGER_NAME, trigger.Name, "trigger name mismatch");
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, trigger.Group, "trigger group name mismatch");
Assert.AreEqual(SchedulerConstants.DefaultGroup, trigger.Group, "trigger group name mismatch");
AssertDateTimesEqualityWithAllowedDelta(DateTime.UtcNow, trigger.StartTimeUtc, 1000);
Assert.IsNull(trigger.JobName, "trigger job name not null");
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, trigger.JobGroup, "trigger job group was not default");
Assert.AreEqual(SchedulerConstants.DefaultGroup, trigger.JobGroup, "trigger job group was not default");
}
[Test]

View File

@@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -9,6 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
<AssemblyName>Spring.Scheduling.Quartz.Tests</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>