ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-3349 .NET: Ignition.Start overload with a custom config file
Date Tue, 26 Jul 2016 12:33:49 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 3af756d71 -> e7547248b


IGNITE-3349 .NET: Ignition.Start overload with a custom config file


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e7547248
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e7547248
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e7547248

Branch: refs/heads/master
Commit: e7547248b077275ea2d7eb4bbd8382b054e95f2b
Parents: 3af756d
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Tue Jul 26 15:33:39 2016 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Tue Jul 26 15:33:39 2016 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Core.Tests.csproj             |  3 ++
 .../IgniteConfigurationSectionTest.cs           | 32 ++++++++++++++++
 .../IgniteStartStopTest.cs                      |  3 +-
 .../Apache.Ignite.Core.Tests/custom_app.config  | 34 +++++++++++++++++
 .../dotnet/Apache.Ignite.Core/Ignition.cs       | 40 +++++++++++++++++++-
 .../dotnet/Apache.Ignite/Config/Configurator.cs | 11 +++---
 6 files changed, 116 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 5c10612..4e33a91 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -291,6 +291,9 @@
   <ItemGroup>
     <None Include="Apache.Ignite.Core.Tests.nunit" />
     <None Include="Apache.Ignite.Core.Tests.snk" />
+    <None Include="custom_app.config">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="app.config" />
     <Content Include="Config\ignite-dotnet-cfg.xml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
index 29aea90..4e10a2b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
@@ -64,6 +64,38 @@ namespace Apache.Ignite.Core.Tests
             {
                 Assert.IsTrue(ignite.Name.StartsWith("myGrid"));
             }
+
+            using (var ignite = Ignition.StartFromApplicationConfiguration(
+                "igniteConfiguration3", "custom_app.config"))
+            {
+                Assert.AreEqual("myGrid3", ignite.Name);
+            }
+        }
+
+        /// <summary>
+        /// Tests the ignite start error.
+        /// </summary>
+        [Test]
+        public void TestIgniteStartError()
+        {
+            var ex = Assert.Throws<ConfigurationErrorsException>(() =>
+                Ignition.StartFromApplicationConfiguration("igniteConfiguration111"));
+
+            Assert.AreEqual("Could not find IgniteConfigurationSection with name 'igniteConfiguration111'",

+                ex.Message);
+
+
+            ex = Assert.Throws<ConfigurationErrorsException>(() =>
+                Ignition.StartFromApplicationConfiguration("igniteConfiguration", "somefile"));
+
+            Assert.AreEqual("Specified config file does not exist: somefile", ex.Message);
+
+
+            ex = Assert.Throws<ConfigurationErrorsException>(() =>
+                Ignition.StartFromApplicationConfiguration("igniteConfiguration", "custom_app.config"));
+
+            Assert.AreEqual("Could not find IgniteConfigurationSection with name 'igniteConfiguration'
" +
+                            "in file 'custom_app.config'", ex.Message);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
index 47212fc..b863308 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
@@ -125,6 +125,7 @@ namespace Apache.Ignite.Core.Tests
 
             Assert.AreSame(grid3, Ignition.GetIgnite(null));
             Assert.AreSame(grid3, Ignition.TryGetIgnite(null));
+            Assert.AreSame(grid3, Ignition.TryGetIgnite());
 
             Assert.Throws<IgniteException>(() => Ignition.GetIgnite("invalid_name"));
             Assert.IsNull(Ignition.TryGetIgnite("invalid_name"));
@@ -365,7 +366,7 @@ namespace Apache.Ignite.Core.Tests
             });
 
             // Wait for remote node to join
-            Assert.IsTrue(grid.WaitTopology(2, 30000));
+            Assert.IsTrue(grid.WaitTopology(2));
 
             // Wait some more for initialization
             Thread.Sleep(1000);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite.Core.Tests/custom_app.config
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/custom_app.config b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/custom_app.config
new file mode 100644
index 0000000..41ea39e
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/custom_app.config
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  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.
+-->
+
+<configuration>
+    <configSections>
+        <section name="igniteConfiguration3" type="Apache.Ignite.Core.IgniteConfigurationSection,
Apache.Ignite.Core" />
+    </configSections>
+
+    <igniteConfiguration3 gridName="myGrid3" localhost="127.0.0.1">
+        <discoverySpi type="TcpDiscoverySpi">
+            <ipFinder type="TcpDiscoveryStaticIpFinder">
+                <endpoints>
+                    <string>127.0.0.1:47500</string>
+                </endpoints>
+            </ipFinder>
+        </discoverySpi>
+    </igniteConfiguration3>
+</configuration>

http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
index 7fbd100..c9ff3ff 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -157,10 +157,48 @@ namespace Apache.Ignite.Core
         }
 
         /// <summary>
+        /// Reads <see cref="IgniteConfiguration" /> from application configuration
+        /// <see cref="IgniteConfigurationSection" /> with specified name and starts
Ignite.
+        /// </summary>
+        /// <param name="sectionName">Name of the section.</param>
+        /// <param name="configPath">Path to the configuration file.</param>
+        /// <returns>Started Ignite.</returns>
+        public static IIgnite StartFromApplicationConfiguration(string sectionName, string
configPath)
+        {
+            IgniteArgumentCheck.NotNullOrEmpty(sectionName, "sectionName");
+            IgniteArgumentCheck.NotNullOrEmpty(configPath, "configPath");
+
+            var fileMap = GetConfigMap(configPath);
+            var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
+
+            var section = config.GetSection(sectionName) as IgniteConfigurationSection;
+
+            if (section == null)
+                throw new ConfigurationErrorsException(
+                    string.Format("Could not find {0} with name '{1}' in file '{2}'",
+                        typeof(IgniteConfigurationSection).Name, sectionName, configPath));
+
+            return Start(section.IgniteConfiguration);
+        }
+
+        /// <summary>
+        /// Gets the configuration file map.
+        /// </summary>
+        private static ExeConfigurationFileMap GetConfigMap(string fileName)
+        {
+            var fullFileName = Path.GetFullPath(fileName);
+
+            if (!File.Exists(fullFileName))
+                throw new ConfigurationErrorsException("Specified config file does not exist:
" + fileName);
+
+            return new ExeConfigurationFileMap { ExeConfigFilename = fullFileName };
+        }
+
+        /// <summary>
         /// Starts Ignite with given configuration.
         /// </summary>
         /// <returns>Started Ignite.</returns>
-        public unsafe static IIgnite Start(IgniteConfiguration cfg)
+        public static unsafe IIgnite Start(IgniteConfiguration cfg)
         {
             IgniteArgumentCheck.NotNull(cfg, "cfg");
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/e7547248/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs b/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
index c595de1..5f73a6d 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
@@ -75,7 +75,8 @@ namespace Apache.Ignite.Config
 
             foreach (var arg in args)
             {
-                Func<string, bool> argIs = x => arg.Item1.Equals(x, StringComparison.OrdinalIgnoreCase);
+                var arg0 = arg;  // copy captured variable
+                Func<string, bool> argIs = x => arg0.Item1.Equals(x, StringComparison.OrdinalIgnoreCase);
 
                 if (argIs(CmdIgniteHome))
                     cfg.IgniteHome = arg.Item2;
@@ -152,12 +153,12 @@ namespace Apache.Ignite.Config
         /// </summary>
         private static ExeConfigurationFileMap GetConfigMap(string fileName)
         {
-            fileName = Path.GetFullPath(fileName);
+            var fullFileName = Path.GetFullPath(fileName);
 
-            if (!File.Exists(fileName))
-                throw new InvalidOperationException("Specified config file does not exist:
" + fileName);
+            if (!File.Exists(fullFileName))
+                throw new ConfigurationErrorsException("Specified config file does not exist:
" + fileName);
 
-            return new ExeConfigurationFileMap {ExeConfigFilename = fileName};
+            return new ExeConfigurationFileMap {ExeConfigFilename = fullFileName};
         }
 
         /// <summary>


Mime
View raw message