Skip to content

Commit

Permalink
IGNITE-3427 .NET: Moved examples from Spring XML to app.config. This c…
Browse files Browse the repository at this point in the history
…loses #897.
  • Loading branch information
ptupitsyn authored and vozerov-gridgain committed Jul 28, 2016
1 parent 8386dd8 commit fa81b4a
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="TestAppConfig.cs" />
<Compile Include="AspNet\IgniteOutputCacheProviderTest.cs" />
<Compile Include="Binary\BinaryBuilderSelfTestFullFooter.cs" />
<Compile Include="Binary\BinaryCompactFooterInteropTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Example
private Action _runAction;

/** Config url */
public string SpringConfigUrl { get; private set; }
public string ConfigPath { get; private set; }

/** Source path */
public string SourceFilePath { get; private set; }
Expand Down Expand Up @@ -90,7 +90,7 @@ public static IEnumerable<Example> GetExamples()
yield return new Example
{
SourceFilePath = sourceFile,
SpringConfigUrl = GetSpringConfigUrl(sourceCode),
ConfigPath = GetConfigPath(sourceCode),
NeedsTestDll = sourceCode.Contains(examplesDllName),
_runAction = GetRunAction(type),
Name = type.Name
Expand All @@ -109,9 +109,9 @@ private static Action GetRunAction(Type type)
/// <summary>
/// Gets the spring configuration URL.
/// </summary>
private static string GetSpringConfigUrl(string code)
private static string GetConfigPath(string code)
{
var match = Regex.Match(code, "-springConfigUrl=(.*?.xml)");
var match = Regex.Match(code, "-configFileName=(.*?.config)");

return match.Success ? match.Groups[1].Value : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace Apache.Ignite.Core.Tests.Examples
[Category(TestUtils.CategoryIntensive)]
public class ExamplesTest
{
/** */
private IDisposable _changedConfig;

/// <summary>
/// Tests the example in a single node mode.
/// </summary>
Expand Down Expand Up @@ -68,24 +71,14 @@ public void TestRemoteNodesClientMode(Example example)
private static void TestRemoteNodes(Example example, bool clientMode)
{
// Exclude LifecycleExample
if (string.IsNullOrEmpty(example.SpringConfigUrl))
if (string.IsNullOrEmpty(example.ConfigPath))
{
Assert.AreEqual("LifecycleExample", example.Name);

return;
}

// First node to start in current process defines JVM options.
var gridConfig = new IgniteConfiguration
{
SpringConfigUrl = example.SpringConfigUrl,
JvmOptions =
new[]
{
"-Xms512m", "-Xmx1024m", "-Xdebug", "-Xnoagent", "-Djava.compiler=NONE",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
}
};
var configPath = Path.Combine(PathUtil.IgniteHome, PathUtil.DevPrefix, example.ConfigPath);

// Try with multiple standalone nodes
for (var i = 0; i < 2; i++)
Expand All @@ -94,9 +87,10 @@ private static void TestRemoteNodes(Example example, bool clientMode)
// Stop it after topology check so we don't interfere with example
Ignition.ClientMode = false;

using (var ignite = Ignition.Start(gridConfig))
using (var ignite = Ignition.StartFromApplicationConfiguration(
"igniteConfiguration", configPath))
{
var args = new List<string> {"-springConfigUrl=" + example.SpringConfigUrl};
var args = new List<string> { "-configFileName=" + configPath};

if (example.NeedsTestDll)
args.Add(" -assembly=" + typeof(AverageSalaryJob).Assembly.Location);
Expand All @@ -122,34 +116,36 @@ private static void TestRemoteNodes(Example example, bool clientMode)
public void FixtureSetUp()
{
Environment.SetEnvironmentVariable("IGNITE_NATIVE_TEST_CLASSPATH", "true");
Environment.SetEnvironmentVariable(Ignition.EnvIgniteSpringConfigUrlPrefix,
PathUtil.SpringConfigUrlDevPrefix);

Directory.SetCurrentDirectory(PathUtil.IgniteHome);

_changedConfig = TestAppConfig.Change(PathUtil.ExamplesAppConfigPath);
}

/// <summary>
/// Test teardown.
/// Fixture teardown.
/// </summary>
[TearDown]
public void TearDown()
[TestFixtureTearDown]
public void FixtureTearDown()
{
Ignition.ClientMode = false;
IgniteProcess.KillAll();
_changedConfig.Dispose();
}

/// <summary>
/// Fixture tear down.
/// Test teardown.
/// </summary>
[TestFixtureTearDown]
public void FixtureTearDown()
[TearDown]
public void TearDown()
{
Environment.SetEnvironmentVariable(Ignition.EnvIgniteSpringConfigUrlPrefix, null);
Ignition.ClientMode = false;
IgniteProcess.KillAll();
}

/// <summary>
/// Gets the test cases.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once MemberCanBeMadeStatic.Global
public IEnumerable<Example> TestCases
{
get { return Example.GetExamples(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Apache.Ignite.Core.Tests.Examples
public static class PathUtil
{
/** */
public const string SpringConfigUrlDevPrefix = "modules\\";
public const string DevPrefix = "modules\\";

/** */
public static readonly string IgniteHome = Impl.Common.IgniteHome.Resolve(null);
Expand All @@ -36,6 +36,12 @@ public static class PathUtil
public static readonly string ExamplesSourcePath =
Path.Combine(IgniteHome, @"modules\platforms\dotnet\examples");

/// <summary>
/// Examples application configuration path.
/// </summary>
public static readonly string ExamplesAppConfigPath =
Path.Combine(ExamplesSourcePath, @"Apache.Ignite.Examples\App.config");

/// <summary>
/// Gets the full configuration path.
/// </summary>
Expand All @@ -44,7 +50,7 @@ public static string GetFullConfigPath(string springConfigUrl)
if (string.IsNullOrEmpty(springConfigUrl))
return springConfigUrl;

return Path.GetFullPath(Path.Combine(IgniteHome, SpringConfigUrlDevPrefix + springConfigUrl));
return Path.GetFullPath(Path.Combine(IgniteHome, DevPrefix + springConfigUrl));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void CheckConfigFilesExist()
{
var paths = Directory.GetFiles(PathUtil.ExamplesSourcePath, "*.cs", SearchOption.AllDirectories)
.Select(File.ReadAllText)
.SelectMany(src => Regex.Matches(src, @"platforms[^\s]+.xml").OfType<Match>())
.SelectMany(src => Regex.Matches(src, @"platforms[^\s]+.config").OfType<Match>())
.Where(match => match.Success)
.Select(match => PathUtil.GetFullConfigPath(match.Value))
.Distinct()
Expand Down
100 changes: 100 additions & 0 deletions modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestAppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

namespace Apache.Ignite.Core.Tests
{
using System;
using System.Linq;
using System.Configuration;
using System.Reflection;

/// <summary>
/// Replaces app.config at runtime for test purposes.
/// </summary>
public static class TestAppConfig
{
/// <summary>
/// Changes the current app config with the specified one.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>Disposable object that will revert the change when disposed.</returns>
public static IDisposable Change(string path)
{
return new ChangeAppConfig(path);
}

/// <summary>
/// Disposable config changer.
/// </summary>
private class ChangeAppConfig : IDisposable
{
/** */
private readonly string _oldConfig =
AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE").ToString();

/** */
private bool _isDisposed;

/// <summary>
/// Initializes a new instance of the <see cref="ChangeAppConfig"/> class.
/// </summary>
/// <param name="path">The path.</param>
public ChangeAppConfig(string path)
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
ResetConfigMechanism();
}

/** <inheritdoc /> */
public void Dispose()
{
if (!_isDisposed)
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", _oldConfig);
ResetConfigMechanism();


_isDisposed = true;
}
GC.SuppressFinalize(this);
}

/// <summary>
/// Resets the internal configuration mechanism.
/// </summary>
private static void ResetConfigMechanism()
{
// ReSharper disable PossibleNullReferenceException

typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, 0);

typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, null);

typeof(ConfigurationManager)
.Assembly.GetTypes().First(x => x.FullName == "System.Configuration.ClientConfigPaths")
.GetField("s_current", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, null);

// ReSharper restore PossibleNullReferenceException
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class TcpDiscoveryMulticastIpFinder : TcpDiscoveryStaticIpFinder
/// </summary>
public const int DefaultAddressRequestAttempts = 2;

/// <summary>
/// Default multicast group.
/// </summary>
public const string DefaultMulticastGroup = "228.1.2.4";

/// <summary>
/// Default response timeout.
/// </summary>
Expand All @@ -53,6 +58,7 @@ public TcpDiscoveryMulticastIpFinder()
MulticastPort = DefaultMulticastPort;
AddressRequestAttempts = DefaultAddressRequestAttempts;
ResponseTimeout = DefaultResponseTimeout;
MulticastGroup = DefaultMulticastGroup;
}

/// <summary>
Expand All @@ -66,6 +72,7 @@ public TcpDiscoveryMulticastIpFinder()
/// <summary>
/// Gets or sets the IP address of the multicast group.
/// </summary>
[DefaultValue(DefaultMulticastGroup)]
public string MulticastGroup { get; set; }

/// <summary>
Expand Down
9 changes: 1 addition & 8 deletions modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ namespace Apache.Ignite.Core
/// </summary>
public static class Ignition
{
/** */
internal const string EnvIgniteSpringConfigUrlPrefix = "IGNITE_SPRING_CONFIG_URL_PREFIX";

/** */
private static readonly object SyncRoot = new object();

Expand Down Expand Up @@ -216,10 +213,6 @@ public static unsafe IIgnite Start(IgniteConfiguration cfg)

var gridName = cfg.GridName;

var cfgPath = cfg.SpringConfigUrl == null
? null
: Environment.GetEnvironmentVariable(EnvIgniteSpringConfigUrlPrefix) + cfg.SpringConfigUrl;

// 3. Create startup object which will guide us through the rest of the process.
_startup = new Startup(cfg, cbs);

Expand All @@ -228,7 +221,7 @@ public static unsafe IIgnite Start(IgniteConfiguration cfg)
try
{
// 4. Initiate Ignite start.
UU.IgnitionStart(cbs.Context, cfgPath, gridName, ClientMode);
UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl, gridName, ClientMode);

// 5. At this point start routine is finished. We expect STARTUP object to have all necessary data.
var node = _startup.Ignite;
Expand Down
1 change: 0 additions & 1 deletion modules/platforms/dotnet/Apache.Ignite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Apache.Ignite.sln.DotSettings = Apache.Ignite.sln.DotSettings
Apache.Ignite.sln.TeamCity.DotSettings = Apache.Ignite.sln.TeamCity.DotSettings
DEVNOTES.txt = DEVNOTES.txt
examples\Config\examples-config.xml = examples\Config\examples-config.xml
README.txt = README.txt
EndProjectSection
EndProject
Expand Down
8 changes: 0 additions & 8 deletions modules/platforms/dotnet/examples/Apache.Ignite.Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.Examples", "A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.ExamplesDll", "Apache.Ignite.ExamplesDll\Apache.Ignite.ExamplesDll.csproj", "{DFB08363-202E-412D-8812-349EF10A8702}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{F1491682-C798-4C23-8239-16C5BC2C5A02}"
ProjectSection(SolutionItems) = preProject
Config\example-cache-query.xml = Config\example-cache-query.xml
Config\example-cache-store.xml = Config\example-cache-store.xml
Config\example-cache.xml = Config\example-cache.xml
Config\example-compute.xml = Config\example-compute.xml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,34 @@
-->

<configuration>
<runtime>
<gcServer enabled="true" />
</runtime>
<configSections>
<section name="igniteConfiguration" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" />
</configSections>

<runtime>
<gcServer enabled="true" />
</runtime>

<igniteConfiguration xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection">
<binaryConfiguration>
<typeConfigurations>
<binaryTypeConfiguration typeName="Apache.Ignite.ExamplesDll.Binary.OrganizationType" isEnum="true" />
</typeConfigurations>
<types>
<string>Apache.Ignite.ExamplesDll.Binary.Account</string>
<string>Apache.Ignite.ExamplesDll.Binary.Address</string>
<string>Apache.Ignite.ExamplesDll.Binary.Employee</string>
<string>Apache.Ignite.ExamplesDll.Binary.EmployeeKey</string>
<string>Apache.Ignite.ExamplesDll.Binary.Organization</string>
</types>
</binaryConfiguration>

<discoverySpi type="TcpDiscoverySpi">
<ipFinder type="TcpDiscoveryMulticastIpFinder">
<endpoints>
<string>127.0.0.1:47500</string>
</endpoints>
</ipFinder>
</discoverySpi>
</igniteConfiguration>
</configuration>
Loading

0 comments on commit fa81b4a

Please sign in to comment.