You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/02/20 10:16:48 UTC
[06/12] ignite git commit: IGNITE-2679 .NET: Implemented
Ignition.TryGetIgnite,
returning null instead of exception if instance with the given name is not
found. This closes #497.
IGNITE-2679 .NET: Implemented Ignition.TryGetIgnite, returning null instead of exception if instance with the given name is not found. This closes #497.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/af17db5b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/af17db5b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/af17db5b
Branch: refs/heads/ignite-1786
Commit: af17db5bdd7c0dc0ddecd2f7b92359accfec4f1b
Parents: 88429f2
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Fri Feb 19 16:59:40 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Feb 19 16:59:40 2016 +0300
----------------------------------------------------------------------
.../IgniteStartStopTest.cs | 58 ++++----------------
.../dotnet/Apache.Ignite.Core/Ignition.cs | 56 +++++++++++++++----
2 files changed, 57 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/af17db5b/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 b589b2e..447c8b9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#pragma warning disable 618 // Deprecated SpringConfigUrl
namespace Apache.Ignite.Core.Tests
{
using System;
@@ -118,52 +119,26 @@ namespace Apache.Ignite.Core.Tests
Assert.IsNull(grid3.Name);
Assert.AreSame(grid1, Ignition.GetIgnite("grid1"));
+ Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1"));
Assert.AreSame(grid2, Ignition.GetIgnite("grid2"));
+ Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2"));
Assert.AreSame(grid3, Ignition.GetIgnite(null));
+ Assert.AreSame(grid3, Ignition.TryGetIgnite(null));
- try
- {
- Ignition.GetIgnite("invalid_name");
- }
- catch (IgniteException e)
- {
- Console.WriteLine("Expected exception: " + e);
- }
+ Assert.Throws<IgniteException>(() => Ignition.GetIgnite("invalid_name"));
+ Assert.IsNull(Ignition.TryGetIgnite("invalid_name"));
- Assert.IsTrue(Ignition.Stop("grid1", true));
- try
- {
- Ignition.GetIgnite("grid1");
- }
- catch (IgniteException e)
- {
- Console.WriteLine("Expected exception: " + e);
- }
+ Assert.IsTrue(Ignition.Stop("grid1", true));
+ Assert.Throws<IgniteException>(() => Ignition.GetIgnite("grid1"));
grid2.Dispose();
-
- try
- {
- Ignition.GetIgnite("grid2");
- }
- catch (IgniteException e)
- {
- Console.WriteLine("Expected exception: " + e);
- }
+ Assert.Throws<IgniteException>(() => Ignition.GetIgnite("grid2"));
grid3.Dispose();
-
- try
- {
- Ignition.GetIgnite(null);
- }
- catch (IgniteException e)
- {
- Console.WriteLine("Expected exception: " + e);
- }
+ Assert.Throws<IgniteException>(() => Ignition.GetIgnite("grid3"));
foreach (var cfgName in cfgs)
{
@@ -178,17 +153,8 @@ namespace Apache.Ignite.Core.Tests
Ignition.StopAll(true);
- foreach (var gridName in new List<string> { "grid1", "grid2", null })
- {
- try
- {
- Ignition.GetIgnite(gridName);
- }
- catch (IgniteException e)
- {
- Console.WriteLine("Expected exception: " + e);
- }
- }
+ foreach (var gridName in new List<string> {"grid1", "grid2", null})
+ Assert.Throws<IgniteException>(() => Ignition.GetIgnite(gridName));
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/af17db5b/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 70d7422..b1693e7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -473,7 +473,44 @@ namespace Apache.Ignite.Core
}
/// <summary>
- /// Gets a named Ignite instance. If Ignite name is {@code null} or empty string,
+ /// Gets a named Ignite instance. If Ignite name is <c>null</c> or empty string,
+ /// then default no-name Ignite will be returned. Note that caller of this method
+ /// should not assume that it will return the same instance every time.
+ /// <p />
+ /// Note that single process can run multiple Ignite instances and every Ignite instance (and its
+ /// node) can belong to a different grid. Ignite name defines what grid a particular Ignite
+ /// instance (and correspondingly its node) belongs to.
+ /// </summary>
+ /// <param name="name">Ignite name to which requested Ignite instance belongs. If <c>null</c>,
+ /// then Ignite instance belonging to a default no-name Ignite will be returned.</param>
+ /// <returns>
+ /// An instance of named grid.
+ /// </returns>
+ /// <exception cref="IgniteException">When there is no Ignite instance with specified name.</exception>
+ public static IIgnite GetIgnite(string name)
+ {
+ var ignite = TryGetIgnite(name);
+
+ if (ignite == null)
+ throw new IgniteException("Ignite instance was not properly started or was already stopped: " + name);
+
+ return ignite;
+ }
+
+ /// <summary>
+ /// Gets an instance of default no-name grid. Note that
+ /// caller of this method should not assume that it will return the same
+ /// instance every time.
+ /// </summary>
+ /// <returns>An instance of default no-name grid.</returns>
+ /// <exception cref="IgniteException">When there is no Ignite instance with specified name.</exception>
+ public static IIgnite GetIgnite()
+ {
+ return GetIgnite(null);
+ }
+
+ /// <summary>
+ /// Gets a named Ignite instance, or <c>null</c> if none found. If Ignite name is <c>null</c> or empty string,
/// then default no-name Ignite will be returned. Note that caller of this method
/// should not assume that it will return the same instance every time.
/// <p/>
@@ -484,29 +521,26 @@ namespace Apache.Ignite.Core
/// <param name="name">Ignite name to which requested Ignite instance belongs. If <c>null</c>,
/// then Ignite instance belonging to a default no-name Ignite will be returned.
/// </param>
- /// <returns>An instance of named grid.</returns>
- public static IIgnite GetIgnite(string name)
+ /// <returns>An instance of named grid, or null.</returns>
+ public static IIgnite TryGetIgnite(string name)
{
lock (SyncRoot)
{
Ignite result;
- if (!Nodes.TryGetValue(new NodeKey(name), out result))
- throw new IgniteException("Ignite instance was not properly started or was already stopped: " + name);
-
- return result;
+ return !Nodes.TryGetValue(new NodeKey(name), out result) ? null : result;
}
}
/// <summary>
- /// Gets an instance of default no-name grid. Note that
+ /// Gets an instance of default no-name grid, or <c>null</c> if none found. Note that
/// caller of this method should not assume that it will return the same
/// instance every time.
/// </summary>
- /// <returns>An instance of default no-name grid.</returns>
- public static IIgnite GetIgnite()
+ /// <returns>An instance of default no-name grid, or null.</returns>
+ public static IIgnite TryGetIgnite()
{
- return GetIgnite(null);
+ return TryGetIgnite(null);
}
/// <summary>