Skip to content

Commit

Permalink
fix QRTZNET-246 Setting environment variables does not override confi…
Browse files Browse the repository at this point in the history
…guration files values
  • Loading branch information
jvilalta committed Feb 24, 2011
1 parent 53a0c28 commit 291e23d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/Quartz.Tests.Unit/Impl/StdSchedulerFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using NUnit.Framework;

using Quartz.Impl;
using System;

namespace Quartz.Tests.Unit.Impl
{
Expand All @@ -46,7 +47,7 @@ public void TestFactoryCanBeUsedWithEmptyProperties()
StdSchedulerFactory factory = new StdSchedulerFactory(new NameValueCollection());
factory.GetScheduler();
}

[Test]
[ExpectedException(
ExpectedException = typeof(SchedulerConfigException),
Expand Down Expand Up @@ -85,5 +86,20 @@ public void TestFactoryShouldNotThrowConfigurationErrorIfNotQuartzPrefixedProper
properties["my.unknown.property"] = "1";
new StdSchedulerFactory(properties);
}
[Test]
public void TestFactoryShouldOverrideConfigurationWithSysProperties()
{
NameValueCollection properties = new NameValueCollection();
var factory = new StdSchedulerFactory();
factory.Initialize();
var scheduler=factory.GetScheduler();
Assert.AreEqual("DefaultQuartzScheduler",scheduler.SchedulerName);

Environment.SetEnvironmentVariable("quartz.scheduler.instanceName", "fromSystemProperties");
factory = new StdSchedulerFactory();
scheduler = factory.GetScheduler();
Assert.AreEqual("fromSystemProperties", scheduler.SchedulerName);

}
}
}
6 changes: 3 additions & 3 deletions src/Quartz/Impl/StdSchedulerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ public void Initialize()
private static NameValueCollection OverrideWithSysProps(NameValueCollection props)
{
NameValueCollection retValue = new NameValueCollection(props);
ICollection keys = Environment.GetEnvironmentVariables().Keys;
IDictionary vars = Environment.GetEnvironmentVariables();

foreach (string key in keys)
foreach (string key in vars.Keys)
{
retValue.Set(key, props[key]);
retValue.Set(key, vars[key] as string);
}
return retValue;
}
Expand Down

0 comments on commit 291e23d

Please sign in to comment.