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 2015/09/22 09:19:31 UTC
[29/37] ignite git commit: IGNITE-1513: WIP on .Net.
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
new file mode 100644
index 0000000..0f4ba5e
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
@@ -0,0 +1,137 @@
+/*
+ * 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.Examples
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using Apache.Ignite.Core.Tests.Process;
+ using Apache.Ignite.ExamplesDll.Compute;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests all examples in various modes.
+ /// </summary>
+ [Category(TestUtils.CategoryIntensive)]
+ public class ExamplesTest
+ {
+ /// <summary>
+ /// Tests the example in a single node mode.
+ /// </summary>
+ /// <param name="example">The example to run.</param>
+ [Test, TestCaseSource("TestCases")]
+ public void TestLocalNode(Example example)
+ {
+ example.Run();
+ }
+
+ /// <summary>
+ /// Tests the example with standalone Apache.Ignite.exe nodes.
+ /// </summary>
+ /// <param name="example">The example to run.</param>
+ [Test, TestCaseSource("TestCases")]
+ public void TestRemoteNodes(Example example)
+ {
+ TestRemoteNodes(example, false);
+ }
+
+ /// <summary>
+ /// Tests the example with standalone Apache.Ignite.exe nodes while local node is in client mode.
+ /// </summary>
+ /// <param name="example">The example to run.</param>
+ [Test, TestCaseSource("TestCases")]
+ public void TestRemoteNodesClientMode(Example example)
+ {
+ TestRemoteNodes(example, true);
+ }
+
+ /// <summary>
+ /// Tests the example with standalone Apache.Ignite.exe nodes.
+ /// </summary>
+ /// <param name="example">The example to run.</param>
+ /// <param name="clientMode">Client mode flag.</param>
+ private static void TestRemoteNodes(Example example, bool clientMode)
+ {
+ // Exclude CrossPlatformExample and LifecycleExample
+ if (string.IsNullOrEmpty(example.SpringConfigUrl))
+ {
+ Assert.IsTrue(new[] {"CrossPlatformExample", "LifecycleExample"}.Contains(example.Name));
+
+ return;
+ }
+
+ Assert.IsTrue(File.Exists(example.SpringConfigUrl));
+
+ var gridConfig = new IgniteConfiguration {SpringConfigUrl = example.SpringConfigUrl};
+
+ // Try with multiple standalone nodes
+ for (var i = 0; i < 2; i++)
+ {
+ // Start a grid to monitor topology
+ // Stop it after topology check so we don't interfere with example
+ Ignition.ClientMode = false;
+
+ using (var ignite = Ignition.Start(gridConfig))
+ {
+ var args = new List<string> {"-springConfigUrl=" + example.SpringConfigUrl};
+
+ if (example.NeedsTestDll)
+ args.Add(" -assembly=" + typeof(AverageSalaryJob).Assembly.Location);
+
+ // ReSharper disable once UnusedVariable
+ var proc = new IgniteProcess(args.ToArray());
+
+ Assert.IsTrue(ignite.WaitTopology(i + 2, 30000));
+ }
+
+ Ignition.ClientMode = clientMode;
+ example.Run();
+ }
+ }
+
+ /// <summary>
+ /// Fixture setup.
+ /// </summary>
+ [TestFixtureSetUp]
+ public void FixtureSetUp()
+ {
+ Environment.SetEnvironmentVariable("IGNITE_NATIVE_TEST_CLASSPATH", "true");
+
+ Directory.SetCurrentDirectory(PathUtil.IgniteHome);
+ }
+
+ /// <summary>
+ /// Test teardown.
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ Ignition.ClientMode = false;
+ IgniteProcess.KillAll();
+ }
+
+ /// <summary>
+ /// Gets the test cases.
+ /// </summary>
+ public IEnumerable<Example> TestCases
+ {
+ get { return Example.All; }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs
new file mode 100644
index 0000000..4f9625f
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs
@@ -0,0 +1,51 @@
+/*
+ * 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.Examples
+{
+ using System.IO;
+ using Apache.Ignite.Core.Impl;
+
+ /// <summary>
+ /// Grid path resolver.
+ /// </summary>
+ public static class PathUtil
+ {
+ public static readonly string IgniteHome = IgniteManager.GetIgniteHome(null);
+
+ /// <summary>
+ /// Full Apache.Ignite.exe path.
+ /// </summary>
+ public static readonly string IgniteExePath = typeof(IgniteRunner).Assembly.Location;
+
+ /// <summary>
+ /// Examples source code path.
+ /// </summary>
+ public static readonly string ExamplesSourcePath = Path.Combine(IgniteHome, @"platforms\dotnet\Examples");
+
+ /// <summary>
+ /// Gets the full configuration path.
+ /// </summary>
+ public static string GetFullConfigPath(string springConfigUrl)
+ {
+ if (string.IsNullOrEmpty(springConfigUrl))
+ return springConfigUrl;
+
+ return Path.GetFullPath(Path.Combine(IgniteHome, springConfigUrl));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs
new file mode 100644
index 0000000..24bd663
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs
@@ -0,0 +1,45 @@
+/*
+ * 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.Examples
+{
+ using System.IO;
+ using System.Linq;
+ using System.Text.RegularExpressions;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests project files.
+ /// </summary>
+ public class ProjectFilesTest
+ {
+ /// <summary>
+ /// Checks config files in examples comments for existence.
+ /// </summary>
+ [Test]
+ public void CheckConfigFilesExist()
+ {
+ Directory.GetFiles(PathUtil.ExamplesSourcePath, "*.cs", SearchOption.AllDirectories)
+ .Select(File.ReadAllText)
+ .SelectMany(src => Regex.Matches(src, @"modules\\platform[^\s]+.xml").OfType<Match>())
+ .Where(match => match.Success)
+ .Select(match => Path.Combine(PathUtil.IgniteHome, match.Value))
+ .ToList()
+ .ForEach(path => Assert.IsTrue(File.Exists(path), "Config file does not exist: " + path));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
new file mode 100644
index 0000000..7a5a725
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
@@ -0,0 +1,352 @@
+/*
+ * 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.IO;
+ using System.Linq;
+ using System.Runtime.Serialization.Formatters.Binary;
+ using System.Threading.Tasks;
+ using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Cluster;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Impl;
+ using Apache.Ignite.Core.Portable;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests grid exceptions propagation.
+ /// </summary>
+ public class ExceptionsTest
+ {
+ /// <summary>
+ /// Before test.
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ TestUtils.KillProcesses();
+ }
+
+ /// <summary>
+ /// After test.
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ Ignition.StopAll(true);
+ }
+
+ /// <summary>
+ /// Tests exceptions.
+ /// </summary>
+ [Test]
+ public void TestExceptions()
+ {
+ var grid = StartGrid();
+
+ try
+ {
+ grid.GetCache<object, object>("invalidCacheName");
+
+ Assert.Fail();
+ }
+ catch (Exception e)
+ {
+ Assert.IsTrue(e is ArgumentException);
+ }
+
+ try
+ {
+ grid.GetCluster().ForRemotes().GetMetrics();
+
+ Assert.Fail();
+ }
+ catch (Exception e)
+ {
+ Assert.IsTrue(e is ClusterGroupEmptyException);
+ }
+
+ grid.Dispose();
+
+ try
+ {
+ grid.GetCache<object, object>("cache1");
+
+ Assert.Fail();
+ }
+ catch (Exception e)
+ {
+ Assert.IsTrue(e is InvalidOperationException);
+ }
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException keys propagation.
+ /// </summary>
+ [Test]
+ [Category(TestUtils.CategoryIntensive)]
+ public void TestPartialUpdateException()
+ {
+ // Primitive type
+ TestPartialUpdateException(false, (x, g) => x);
+
+ // User type
+ TestPartialUpdateException(false, (x, g) => new PortableEntry(x));
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException keys propagation in portable mode.
+ /// </summary>
+ [Test]
+ [Category(TestUtils.CategoryIntensive)]
+ public void TestPartialUpdateExceptionPortable()
+ {
+ // User type
+ TestPartialUpdateException(false, (x, g) => g.GetPortables().ToPortable<IPortableObject>(new PortableEntry(x)));
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException serialization.
+ /// </summary>
+ [Test]
+ public void TestPartialUpdateExceptionSerialization()
+ {
+ // Inner exception
+ TestPartialUpdateExceptionSerialization(new CachePartialUpdateException("Msg",
+ new IgniteException("Inner msg")));
+
+ // Primitive keys
+ TestPartialUpdateExceptionSerialization(new CachePartialUpdateException("Msg", new object[] {1, 2, 3}));
+
+ // User type keys
+ TestPartialUpdateExceptionSerialization(new CachePartialUpdateException("Msg",
+ new object[]
+ {
+ new SerializableEntry(1),
+ new SerializableEntry(2),
+ new SerializableEntry(3)
+ }));
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException serialization.
+ /// </summary>
+ private static void TestPartialUpdateExceptionSerialization(Exception ex)
+ {
+ var formatter = new BinaryFormatter();
+
+ var stream = new MemoryStream();
+
+ formatter.Serialize(stream, ex);
+
+ stream.Seek(0, SeekOrigin.Begin);
+
+ var ex0 = (Exception) formatter.Deserialize(stream);
+
+ var updateEx = ((CachePartialUpdateException) ex);
+
+ try
+ {
+ Assert.AreEqual(updateEx.GetFailedKeys<object>(),
+ ((CachePartialUpdateException)ex0).GetFailedKeys<object>());
+ }
+ catch (Exception e)
+ {
+ if (typeof (IgniteException) != e.GetType())
+ throw;
+ }
+
+ while (ex != null && ex0 != null)
+ {
+ Assert.AreEqual(ex0.GetType(), ex.GetType());
+ Assert.AreEqual(ex.Message, ex0.Message);
+
+ ex = ex.InnerException;
+ ex0 = ex0.InnerException;
+ }
+
+ Assert.AreEqual(ex, ex0);
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException keys propagation.
+ /// </summary>
+ [Test]
+ [Category(TestUtils.CategoryIntensive)]
+ public void TestPartialUpdateExceptionAsync()
+ {
+ // Primitive type
+ TestPartialUpdateException(true, (x, g) => x);
+
+ // User type
+ TestPartialUpdateException(true, (x, g) => new PortableEntry(x));
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException keys propagation in portable mode.
+ /// </summary>
+ [Test]
+ [Category(TestUtils.CategoryIntensive)]
+ public void TestPartialUpdateExceptionAsyncPortable()
+ {
+ TestPartialUpdateException(true, (x, g) => g.GetPortables().ToPortable<IPortableObject>(new PortableEntry(x)));
+ }
+
+ /// <summary>
+ /// Tests CachePartialUpdateException keys propagation.
+ /// </summary>
+ private static void TestPartialUpdateException<TK>(bool async, Func<int, IIgnite, TK> keyFunc)
+ {
+ using (var grid = StartGrid())
+ {
+ var cache = grid.GetCache<TK, int>("partitioned_atomic").WithNoRetries();
+
+ if (async)
+ cache = cache.WithAsync();
+
+ if (typeof (TK) == typeof (IPortableObject))
+ cache = cache.WithKeepPortable<TK, int>();
+
+ // Do cache puts in parallel
+ var putTask = Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ // Do a lot of puts so that one fails during Ignite stop
+ for (var i = 0; i < 1000000; i++)
+ {
+ cache.PutAll(Enumerable.Range(1, 100).ToDictionary(k => keyFunc(k, grid), k => i));
+
+ if (async)
+ cache.GetFuture().Get();
+ }
+ }
+ catch (CachePartialUpdateException ex)
+ {
+ var failedKeys = ex.GetFailedKeys<TK>();
+
+ Assert.IsTrue(failedKeys.Any());
+
+ var failedKeysObj = ex.GetFailedKeys<object>();
+
+ Assert.IsTrue(failedKeysObj.Any());
+
+ return;
+ }
+
+ Assert.Fail("CachePartialUpdateException has not been thrown.");
+ });
+
+ while (true)
+ {
+ Ignition.Stop("grid_2", true);
+ StartGrid("grid_2");
+
+ if (putTask.Exception != null)
+ throw putTask.Exception;
+
+ if (putTask.IsCompleted)
+ return;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Starts the grid.
+ /// </summary>
+ private static IIgnite StartGrid(string gridName = null)
+ {
+ return Ignition.Start(new IgniteConfigurationEx
+ {
+ SpringConfigUrl = "config\\native-client-test-cache.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath(),
+ GridName = gridName,
+ PortableConfiguration = new PortableConfiguration
+ {
+ TypeConfigurations = new[]
+ {
+ new PortableTypeConfiguration(typeof (PortableEntry))
+ }
+ }
+ });
+ }
+
+ /// <summary>
+ /// Portable entry.
+ /// </summary>
+ private class PortableEntry
+ {
+ /** Value. */
+ private readonly int _val;
+
+ /** <inheritDot /> */
+ public override int GetHashCode()
+ {
+ return _val;
+ }
+
+ /// <summary>
+ /// Constructor.
+ /// </summary>
+ /// <param name="val">Value.</param>
+ public PortableEntry(int val)
+ {
+ _val = val;
+ }
+
+ /** <inheritDoc /> */
+ public override bool Equals(object obj)
+ {
+ return obj is PortableEntry && ((PortableEntry)obj)._val == _val;
+ }
+ }
+
+ /// <summary>
+ /// Portable entry.
+ /// </summary>
+ [Serializable]
+ private class SerializableEntry
+ {
+ /** Value. */
+ private readonly int _val;
+
+ /** <inheritDot /> */
+ public override int GetHashCode()
+ {
+ return _val;
+ }
+
+ /// <summary>
+ /// Constructor.
+ /// </summary>
+ /// <param name="val">Value.</param>
+ public SerializableEntry(int val)
+ {
+ _val = val;
+ }
+
+ /** <inheritDoc /> */
+ public override bool Equals(object obj)
+ {
+ return obj is SerializableEntry && ((SerializableEntry)obj)._val == _val;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
new file mode 100644
index 0000000..abb296c
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
@@ -0,0 +1,443 @@
+/*
+ * 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.
+ */
+
+// ReSharper disable UnusedVariable
+// ReSharper disable UnusedAutoPropertyAccessor.Global
+namespace Apache.Ignite.Core.Tests
+{
+ using System;
+ using System.CodeDom.Compiler;
+ using System.Collections.Generic;
+ using Apache.Ignite.Core.Compute;
+ using Apache.Ignite.Core.Impl;
+ using Apache.Ignite.Core.Portable;
+ using Apache.Ignite.Core.Resource;
+ using Apache.Ignite.Core.Tests.Process;
+ using Microsoft.CSharp;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests for executable.
+ /// </summary>
+ public class ExecutableTest
+ {
+ /** Spring configuration path. */
+ private static readonly string SpringCfgPath = "config\\compute\\compute-standalone.xml";
+
+ /** Min memory Java task. */
+ private const string MinMemTask = "org.apache.ignite.platform.PlatformMinMemoryTask";
+
+ /** Max memory Java task. */
+ private const string MaxMemTask = "org.apache.ignite.platform.PlatformMaxMemoryTask";
+
+ /** Grid. */
+ private IIgnite _grid;
+
+ /// <summary>
+ /// Test fixture set-up routine.
+ /// </summary>
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ TestUtils.KillProcesses();
+
+ _grid = Ignition.Start(Configuration(SpringCfgPath));
+ }
+
+ /// <summary>
+ /// Test fixture tear-down routine.
+ /// </summary>
+ [TestFixtureTearDown]
+ public void TestFixtureTearDown()
+ {
+ Ignition.StopAll(true);
+
+ TestUtils.KillProcesses();
+ }
+
+ /// <summary>
+ /// Set-up routine.
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ TestUtils.KillProcesses();
+
+ Assert.IsTrue(_grid.WaitTopology(1, 30000));
+
+ IgniteProcess.SaveConfigurationBackup();
+ }
+
+ /// <summary>
+ /// Tear-down routine.
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ IgniteProcess.RestoreConfigurationBackup();
+ }
+
+ /// <summary>
+ /// Test data pass through configuration file.
+ /// </summary>
+ [Test]
+ public void TestConfig()
+ {
+ IgniteProcess.ReplaceConfiguration("config\\Apache.Ignite.exe.config.test");
+
+ GenerateDll("test-1.dll");
+ GenerateDll("test-2.dll");
+
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath()
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var cfg = RemoteConfig();
+
+ Assert.AreEqual(SpringCfgPath, cfg.SpringConfigUrl);
+ Assert.IsTrue(cfg.JvmOptions.Contains("-DOPT1") && cfg.JvmOptions.Contains("-DOPT2"));
+ Assert.IsTrue(cfg.Assemblies.Contains("test-1.dll") && cfg.Assemblies.Contains("test-2.dll"));
+ Assert.AreEqual(601, cfg.JvmInitialMemoryMb);
+ Assert.AreEqual(702, cfg.JvmMaxMemoryMb);
+ }
+
+ /// <summary>
+ /// Test assemblies passing through command-line.
+ /// </summary>
+ [Test]
+ public void TestAssemblyCmd()
+ {
+ GenerateDll("test-1.dll");
+ GenerateDll("test-2.dll");
+
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + SpringCfgPath,
+ "-assembly=test-1.dll",
+ "-assembly=test-2.dll"
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var cfg = RemoteConfig();
+
+ Assert.IsTrue(cfg.Assemblies.Contains("test-1.dll") && cfg.Assemblies.Contains("test-2.dll"));
+ }
+
+ /// <summary>
+ /// Test JVM options passing through command-line.
+ /// </summary>
+ [Test]
+ public void TestJvmOptsCmd()
+ {
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + SpringCfgPath,
+ "-J-DOPT1",
+ "-J-DOPT2"
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var cfg = RemoteConfig();
+
+ Assert.IsTrue(cfg.JvmOptions.Contains("-DOPT1") && cfg.JvmOptions.Contains("-DOPT2"));
+ }
+
+ /// <summary>
+ /// Test JVM memory options passing through command-line: raw java options.
+ /// </summary>
+ [Test]
+ public void TestJvmMemoryOptsCmdRaw()
+ {
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + SpringCfgPath,
+ "-J-Xms506m",
+ "-J-Xmx607m"
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var minMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MinMemTask, null);
+ Assert.AreEqual((long) 506*1024*1024, minMem);
+
+ var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MaxMemTask, null);
+ AssertJvmMaxMemory((long) 607*1024*1024, maxMem);
+ }
+
+ /// <summary>
+ /// Test JVM memory options passing through command-line: custom options.
+ /// </summary>
+ [Test]
+ public void TestJvmMemoryOptsCmdCustom()
+ {
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + SpringCfgPath,
+ "-JvmInitialMemoryMB=615",
+ "-JvmMaxMemoryMB=863"
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var minMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MinMemTask, null);
+ Assert.AreEqual((long) 615*1024*1024, minMem);
+
+ var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MaxMemTask, null);
+ AssertJvmMaxMemory((long) 863*1024*1024, maxMem);
+ }
+
+ /// <summary>
+ /// Test JVM memory options passing from application configuration.
+ /// </summary>
+ [Test]
+ public void TestJvmMemoryOptsAppConfig()
+ {
+ IgniteProcess.ReplaceConfiguration("config\\Apache.Ignite.exe.config.test");
+
+ GenerateDll("test-1.dll");
+ GenerateDll("test-2.dll");
+
+ var proc = new IgniteProcess("-jvmClasspath=" + TestUtils.CreateTestClasspath());
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ var minMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MinMemTask, null);
+ Assert.AreEqual((long) 601*1024*1024, minMem);
+
+ var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MaxMemTask, null);
+ AssertJvmMaxMemory((long) 702*1024*1024, maxMem);
+
+ proc.Kill();
+
+ Assert.IsTrue(_grid.WaitTopology(1, 30000));
+
+ // Command line options overwrite config file options
+ // ReSharper disable once RedundantAssignment
+ proc = new IgniteProcess("-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-J-Xms605m", "-J-Xmx706m");
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ minMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MinMemTask, null);
+ Assert.AreEqual((long) 605*1024*1024, minMem);
+
+ maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MaxMemTask, null);
+ AssertJvmMaxMemory((long) 706*1024*1024, maxMem);
+ }
+
+ /// <summary>
+ /// Test JVM memory options passing through command-line: custom options + raw options.
+ /// </summary>
+ [Test]
+ public void TestJvmMemoryOptsCmdCombined()
+ {
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + SpringCfgPath,
+ "-J-Xms555m",
+ "-J-Xmx666m",
+ "-JvmInitialMemoryMB=128",
+ "-JvmMaxMemoryMB=256"
+ );
+
+ Assert.IsTrue(_grid.WaitTopology(2, 30000));
+
+ // Raw JVM options (Xms/Xmx) should override custom options
+ var minMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MinMemTask, null);
+ Assert.AreEqual((long) 555*1024*1024, minMem);
+
+ var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask<long>(MaxMemTask, null);
+ AssertJvmMaxMemory((long) 666*1024*1024, maxMem);
+ }
+
+ /// <summary>
+ /// Get remote node configuration.
+ /// </summary>
+ /// <returns>Configuration.</returns>
+ private RemoteConfiguration RemoteConfig()
+ {
+ return _grid.GetCluster().ForRemotes().GetCompute().Call(new RemoteConfigurationClosure());
+ }
+
+ /// <summary>
+ /// Configuration for node.
+ /// </summary>
+ /// <param name="path">Path to Java XML configuration.</param>
+ /// <returns>Node configuration.</returns>
+ private static IgniteConfiguration Configuration(string path)
+ {
+ var cfg = new IgniteConfiguration();
+
+
+ var portCfg = new PortableConfiguration();
+
+ ICollection<PortableTypeConfiguration> portTypeCfgs = new List<PortableTypeConfiguration>();
+
+ portTypeCfgs.Add(new PortableTypeConfiguration(typeof (RemoteConfiguration)));
+ portTypeCfgs.Add(new PortableTypeConfiguration(typeof (RemoteConfigurationClosure)));
+
+ portCfg.TypeConfigurations = portTypeCfgs;
+
+ cfg.PortableConfiguration = portCfg;
+
+ cfg.JvmClasspath = TestUtils.CreateTestClasspath();
+
+ cfg.JvmOptions = new List<string>
+ {
+ "-ea",
+ "-Xcheck:jni",
+ "-Xms4g",
+ "-Xmx4g",
+ "-DIGNITE_QUIET=false",
+ "-Xnoagent",
+ "-Djava.compiler=NONE",
+ "-Xdebug",
+ "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005",
+ "-XX:+HeapDumpOnOutOfMemoryError"
+ };
+
+ cfg.SpringConfigUrl = path;
+
+ return cfg;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="outputPath"></param>
+ private static void GenerateDll(string outputPath)
+ {
+ var codeProvider = new CSharpCodeProvider();
+
+#pragma warning disable 0618
+
+ var icc = codeProvider.CreateCompiler();
+
+#pragma warning restore 0618
+
+ var parameters = new CompilerParameters();
+ parameters.GenerateExecutable = false;
+ parameters.OutputAssembly = outputPath;
+
+ var src = "namespace Apache.Ignite.Client.Test { public class Foo {}}";
+
+ var results = icc.CompileAssemblyFromSource(parameters, src);
+
+ Assert.False(results.Errors.HasErrors);
+ }
+
+ /// <summary>
+ /// Asserts that JVM maximum memory corresponds to Xmx parameter value.
+ /// </summary>
+ private static void AssertJvmMaxMemory(long expected, long actual)
+ {
+ // allow 20% tolerance because max memory in Java is not exactly equal to Xmx parameter value
+ Assert.LessOrEqual(actual, expected);
+ Assert.Greater(actual, expected/5*4);
+ }
+
+ /// <summary>
+ /// Closure which extracts configuration and passes it back.
+ /// </summary>
+ public class RemoteConfigurationClosure : IComputeFunc<RemoteConfiguration>
+ {
+
+#pragma warning disable 0649
+
+ /** Grid. */
+ [InstanceResource] private IIgnite _grid;
+
+#pragma warning restore 0649
+
+ /** <inheritDoc /> */
+
+ public RemoteConfiguration Invoke()
+ {
+ var grid0 = (Ignite) ((IgniteProxy) _grid).Target;
+
+ var cfg = grid0.Configuration;
+
+ var res = new RemoteConfiguration
+ {
+ IgniteHome = cfg.IgniteHome,
+ SpringConfigUrl = cfg.SpringConfigUrl,
+ JvmDll = cfg.JvmDllPath,
+ JvmClasspath = cfg.JvmClasspath,
+ JvmOptions = cfg.JvmOptions,
+ Assemblies = cfg.Assemblies,
+ JvmInitialMemoryMb = cfg.JvmInitialMemoryMb,
+ JvmMaxMemoryMb = cfg.JvmMaxMemoryMb
+ };
+
+ Console.WriteLine("RETURNING CFG: " + cfg);
+
+ return res;
+ }
+ }
+
+ /// <summary>
+ /// Configuration.
+ /// </summary>
+ public class RemoteConfiguration
+ {
+ /// <summary>
+ /// GG home.
+ /// </summary>
+ public string IgniteHome { get; set; }
+
+ /// <summary>
+ /// Spring config URL.
+ /// </summary>
+ public string SpringConfigUrl { get; set; }
+
+ /// <summary>
+ /// JVM DLL.
+ /// </summary>
+ public string JvmDll { get; set; }
+
+ /// <summary>
+ /// JVM classpath.
+ /// </summary>
+ public string JvmClasspath { get; set; }
+
+ /// <summary>
+ /// JVM options.
+ /// </summary>
+ public ICollection<string> JvmOptions { get; set; }
+
+ /// <summary>
+ /// Assemblies.
+ /// </summary>
+ public ICollection<string> Assemblies { get; set; }
+
+ /// <summary>
+ /// Minimum JVM memory (Xms).
+ /// </summary>
+ public int JvmInitialMemoryMb { get; set; }
+
+ /// <summary>
+ /// Maximum JVM memory (Xms).
+ /// </summary>
+ public int JvmMaxMemoryMb { get; set; }
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
new file mode 100644
index 0000000..993c604
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
@@ -0,0 +1,278 @@
+/*
+ * 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.Collections.Generic;
+ using System.Threading;
+ using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Compute;
+ using Apache.Ignite.Core.Portable;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Future tests.
+ /// </summary>
+ public class FutureTest
+ {
+ /** */
+ private ICache<object, object> _cache;
+
+ /** */
+ private ICompute _compute;
+
+ /// <summary>
+ /// Test fixture set-up routine.
+ /// </summary>
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ TestUtils.KillProcesses();
+
+ var grid = Ignition.Start(new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\compute\\compute-standalone.xml",
+ JvmClasspath = TestUtils.CreateTestClasspath(),
+ JvmOptions = TestUtils.TestJavaOptions(),
+ PortableConfiguration = new PortableConfiguration
+ {
+ TypeConfigurations =
+ new List<PortableTypeConfiguration> { new PortableTypeConfiguration(typeof(Portable)) }
+ }
+ });
+
+ _cache = grid.GetCache<object, object>(null).WithAsync();
+
+ _compute = grid.GetCompute().WithAsync();
+ }
+
+ /// <summary>
+ /// Test fixture tear-down routine.
+ /// </summary>
+ [TestFixtureTearDown]
+ public void TestFixtureTearDown()
+ {
+ TestUtils.KillProcesses();
+ }
+
+ [Test]
+ public void TestListen()
+ {
+ // Listen(Action callback)
+ TestListen((fut, act) => fut.Listen(act));
+
+ // Listen(Action<IFuture> callback)
+ TestListen((fut, act) => ((IFuture)fut).Listen(f =>
+ {
+ Assert.AreEqual(f, fut);
+ act();
+ }));
+
+ // Listen(Action<IFuture<T>> callback)
+ TestListen((fut, act) => fut.Listen(f =>
+ {
+ Assert.AreEqual(f, fut);
+ act();
+ }));
+ }
+
+ private void TestListen(Action<IFuture<object>, Action> listenAction)
+ {
+ _compute.Broadcast(new SleepAction());
+
+ var fut = _compute.GetFuture<object>();
+
+ var listenCount = 0;
+
+ // Multiple subscribers before completion
+ for (var i = 0; i < 10; i++)
+ listenAction(fut, () => Interlocked.Increment(ref listenCount));
+
+ Assert.IsFalse(fut.IsDone);
+
+ Assert.IsNull(fut.Get());
+
+ Thread.Sleep(100); // wait for future completion thread
+
+ Assert.AreEqual(10, listenCount);
+
+ // Multiple subscribers after completion
+ for (var i = 0; i < 10; i++)
+ listenAction(fut, () => Interlocked.Decrement(ref listenCount));
+
+ Assert.AreEqual(0, listenCount);
+ }
+
+ [Test]
+ public void TestToTask()
+ {
+ _cache.Put(1, 1);
+
+ _cache.GetFuture().ToTask().Wait();
+
+ _cache.Get(1);
+
+ var task1 = _cache.GetFuture<int>().ToTask();
+
+ Assert.AreEqual(1, task1.Result);
+
+ Assert.IsTrue(task1.IsCompleted);
+
+ _compute.Broadcast(new SleepAction());
+
+ var task2 = _compute.GetFuture().ToTask();
+
+ Assert.IsFalse(task2.IsCompleted);
+
+ Assert.IsFalse(task2.Wait(100));
+
+ task2.Wait();
+
+ Assert.IsTrue(task2.IsCompleted);
+
+ Assert.AreEqual(null, task2.Result);
+ }
+
+ [Test]
+ public void TestGetWithTimeout()
+ {
+ _compute.Broadcast(new SleepAction());
+
+ var fut = _compute.GetFuture();
+
+ Assert.Throws<TimeoutException>(() => fut.Get(TimeSpan.FromMilliseconds(100)));
+
+ fut.Get(TimeSpan.FromSeconds(1));
+
+ Assert.IsTrue(fut.IsDone);
+ }
+
+ [Test]
+ public void TestToAsyncResult()
+ {
+ _compute.Broadcast(new SleepAction());
+
+ IFuture fut = _compute.GetFuture();
+
+ var asyncRes = fut.ToAsyncResult();
+
+ Assert.IsFalse(asyncRes.IsCompleted);
+
+ Assert.IsTrue(asyncRes.AsyncWaitHandle.WaitOne(1000));
+
+ Assert.IsTrue(asyncRes.IsCompleted);
+ }
+
+ [Test]
+ public void TestFutureTypes()
+ {
+ TestType(false);
+ TestType((byte)11);
+ TestType('x'); // char
+ TestType(2.7d); // double
+ TestType(3.14f); // float
+ TestType(16); // int
+ TestType(17L); // long
+ TestType((short)18);
+
+ TestType(18m); // decimal
+
+ TestType(new Portable { A = 10, B = "foo" });
+ }
+
+ /// <summary>
+ /// Tests future type.
+ /// </summary>
+ private void TestType<T>(T value)
+ {
+ var key = typeof(T).Name;
+
+ _cache.Put(key, value);
+
+ _cache.GetFuture().Get();
+
+ _cache.Get(key);
+
+ Assert.AreEqual(value, _cache.GetFuture<T>().Get());
+ }
+
+ /// <summary>
+ /// Portable test class.
+ /// </summary>
+ private class Portable : IPortableMarshalAware
+ {
+ public int A;
+ public string B;
+
+ /** <inheritDoc /> */
+ public void WritePortable(IPortableWriter writer)
+ {
+ writer.WriteInt("a", A);
+ writer.RawWriter().WriteString(B);
+ }
+
+ /** <inheritDoc /> */
+ public void ReadPortable(IPortableReader reader)
+ {
+ A = reader.ReadInt("a");
+ B = reader.RawReader().ReadString();
+ }
+
+ /** <inheritDoc /> */
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+
+ if (ReferenceEquals(this, obj))
+ return true;
+
+ if (obj.GetType() != GetType())
+ return false;
+
+ var other = (Portable)obj;
+
+ return A == other.A && string.Equals(B, other.B);
+ }
+
+ /** <inheritDoc /> */
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ // ReSharper disable NonReadonlyMemberInGetHashCode
+ return (A * 397) ^ (B != null ? B.GetHashCode() : 0);
+ // ReSharper restore NonReadonlyMemberInGetHashCode
+ }
+ }
+ }
+
+ /// <summary>
+ /// Compute action with a delay to ensure lengthy future execution.
+ /// </summary>
+ [Serializable]
+ private class SleepAction : IComputeAction
+ {
+ public void Invoke()
+ {
+ Thread.Sleep(500);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs
new file mode 100644
index 0000000..5a90c20
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs
@@ -0,0 +1,51 @@
+/*
+ * 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.IO;
+ using Apache.Ignite.Core.Impl;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests IgniteManager class.
+ /// </summary>
+ public class IgniteManagerTest
+ {
+ /// <summary>
+ /// Tests home dir resolver.
+ /// </summary>
+ [Test]
+ public void TestIgniteHome()
+ {
+ var env = Environment.GetEnvironmentVariable(IgniteManager.EnvIgniteHome);
+
+ Environment.SetEnvironmentVariable(IgniteManager.EnvIgniteHome, null);
+
+ try
+ {
+ Assert.IsTrue(Directory.Exists(IgniteManager.GetIgniteHome(null)));
+ }
+ finally
+ {
+ // Restore
+ Environment.SetEnvironmentVariable(IgniteManager.EnvIgniteHome, env);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
new file mode 100644
index 0000000..bd776ce
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
@@ -0,0 +1,422 @@
+/*
+ * 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.Collections.Generic;
+ using System.IO;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Messaging;
+ using Apache.Ignite.Core.Tests.Process;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Ignite start/stop tests.
+ /// </summary>
+ [Category(TestUtils.CategoryIntensive)]
+ public class IgniteStartStopTest
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ TestUtils.KillProcesses();
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ TestUtils.KillProcesses();
+ Ignition.StopAll(true);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestStartDefault()
+ {
+ var cfg = new IgniteConfiguration {JvmClasspath = TestUtils.CreateTestClasspath()};
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.AreEqual(1, grid.GetCluster().GetNodes().Count);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestStartWithConfigPath()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config/default-config.xml",
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.AreEqual(1, grid.GetCluster().GetNodes().Count);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestStartGetStop()
+ {
+ var cfgs = new List<string> { "config\\start-test-grid1.xml", "config\\start-test-grid2.xml", "config\\start-test-grid3.xml" };
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = cfgs[0],
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid1 = Ignition.Start(cfg);
+
+ Assert.AreEqual("grid1", grid1.Name);
+
+ cfg.SpringConfigUrl = cfgs[1];
+
+ var grid2 = Ignition.Start(cfg);
+
+ Assert.AreEqual("grid2", grid2.Name);
+
+ cfg.SpringConfigUrl = cfgs[2];
+
+ var grid3 = Ignition.Start(cfg);
+
+ Assert.IsNull(grid3.Name);
+
+ Assert.AreSame(grid1, Ignition.GetIgnite("grid1"));
+
+ Assert.AreSame(grid2, Ignition.GetIgnite("grid2"));
+
+ Assert.AreSame(grid3, Ignition.GetIgnite(null));
+
+ try
+ {
+ Ignition.GetIgnite("invalid_name");
+ }
+ catch (IgniteException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+
+ Assert.IsTrue(Ignition.Stop("grid1", true));
+
+ try
+ {
+ Ignition.GetIgnite("grid1");
+ }
+ catch (IgniteException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+
+ grid2.Dispose();
+
+ try
+ {
+ Ignition.GetIgnite("grid2");
+ }
+ catch (IgniteException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+
+ grid3.Dispose();
+
+ try
+ {
+ Ignition.GetIgnite(null);
+ }
+ catch (IgniteException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+
+ foreach (var cfgName in cfgs)
+ {
+ cfg.SpringConfigUrl = cfgName;
+ cfg.JvmOptions = TestUtils.TestJavaOptions();
+
+ Ignition.Start(cfg);
+ }
+
+ foreach (var gridName in new List<string> { "grid1", "grid2", null })
+ Assert.IsNotNull(Ignition.GetIgnite(gridName));
+
+ 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);
+ }
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestStartTheSameName()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid1.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid1 = Ignition.Start(cfg);
+
+ Assert.AreEqual("grid1", grid1.Name);
+
+ try
+ {
+ Ignition.Start(cfg);
+
+ Assert.Fail("Start should fail.");
+ }
+ catch (IgniteException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestUsageAfterStop()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid1.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid.GetCache<int, int>("cache1"));
+
+ grid.Dispose();
+
+ try
+ {
+ grid.GetCache<int, int>("cache1");
+
+ Assert.Fail();
+ }
+ catch (InvalidOperationException e)
+ {
+ Console.WriteLine("Expected exception: " + e);
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestStartStopLeak()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid1.xml",
+ JvmOptions = new List<string> {"-Xcheck:jni", "-Xms256m", "-Xmx256m", "-XX:+HeapDumpOnOutOfMemoryError"},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ for (var i = 0; i < 20; i++)
+ {
+ Console.WriteLine("Iteration: " + i);
+
+ var grid = Ignition.Start(cfg);
+
+ UseIgnite(grid);
+
+ if (i % 2 == 0) // Try to stop ignite from another thread.
+ {
+ var t = new Thread(() => {
+ grid.Dispose();
+ });
+
+ t.Start();
+
+ t.Join();
+ }
+ else
+ grid.Dispose();
+
+ GC.Collect(); // At the time of writing java references are cleaned from finalizer, so GC is needed.
+ }
+ }
+
+ /// <summary>
+ /// Tests the client mode flag.
+ /// </summary>
+ [Test]
+ public void TestClientMode()
+ {
+ var servCfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid1.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var clientCfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid2.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ try
+ {
+ using (Ignition.Start(servCfg)) // start server-mode ignite first
+ {
+ Ignition.ClientMode = true;
+
+ using (var grid = Ignition.Start(clientCfg))
+ {
+ UseIgnite(grid);
+ }
+ }
+ }
+ finally
+ {
+ Ignition.ClientMode = false;
+ }
+ }
+
+ /// <summary>
+ /// Uses the ignite.
+ /// </summary>
+ /// <param name="ignite">The ignite.</param>
+ private static void UseIgnite(IIgnite ignite)
+ {
+ // Create objects holding references to java objects.
+ var comp = ignite.GetCompute();
+
+ // ReSharper disable once RedundantAssignment
+ comp = comp.WithKeepPortable();
+
+ var prj = ignite.GetCluster().ForOldest();
+
+ Assert.IsTrue(prj.GetNodes().Count > 0);
+
+ Assert.IsNotNull(prj.GetCompute());
+
+ var cache = ignite.GetCache<int, int>("cache1");
+
+ Assert.IsNotNull(cache);
+
+ cache.GetAndPut(1, 1);
+
+ Assert.AreEqual(1, cache.Get(1));
+ }
+
+ /// <summary>
+ /// Tests the processor initialization and grid usage right after topology enter.
+ /// </summary>
+ [Test]
+ public void TestProcessorInit()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid1.xml",
+ JvmOptions = TestUtils.TestJavaOptions(),
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ // Start local node
+ var grid = Ignition.Start(cfg);
+
+ // Start remote node in a separate process
+ // ReSharper disable once UnusedVariable
+ var proc = new IgniteProcess(
+ "-jvmClasspath=" + TestUtils.CreateTestClasspath(),
+ "-springConfigUrl=" + Path.GetFullPath(cfg.SpringConfigUrl),
+ "-J-Xms512m", "-J-Xmx512m");
+
+ var cts = new CancellationTokenSource();
+ var token = cts.Token;
+
+ // Spam message subscriptions on a separate thread
+ // to test race conditions during processor init on remote node
+ var listenTask = Task.Factory.StartNew(() =>
+ {
+ var filter = new MessageFilter();
+
+ while (!token.IsCancellationRequested)
+ {
+ var listenId = grid.GetMessaging().RemoteListen(filter);
+
+ grid.GetMessaging().StopRemoteListen(listenId);
+ }
+ // ReSharper disable once FunctionNeverReturns
+ });
+
+ // Wait for remote node to join
+ Assert.IsTrue(grid.WaitTopology(2, 30000));
+
+ // Wait some more for initialization
+ Thread.Sleep(1000);
+
+ // Cancel listen task and check that it finishes
+ cts.Cancel();
+ Assert.IsTrue(listenTask.Wait(5000));
+ }
+
+ /// <summary>
+ /// Noop message filter.
+ /// </summary>
+ [Serializable]
+ private class MessageFilter : IMessageFilter<int>
+ {
+ /** <inheritdoc /> */
+ public bool Invoke(Guid nodeId, int message)
+ {
+ return true;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs
new file mode 100644
index 0000000..84f446c
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs
@@ -0,0 +1,288 @@
+/*
+ * 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.Collections.Generic;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Impl;
+ using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Resource;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Lifecycle beans test.
+ /// </summary>
+ public class LifecycleTest
+ {
+ /** Configuration: without Java beans. */
+ private const string CfgNoBeans = "config//lifecycle//lifecycle-no-beans.xml";
+
+ /** Configuration: with Java beans. */
+ private const string CfgBeans = "config//lifecycle//lifecycle-beans.xml";
+
+ /** Whether to throw an error on lifecycle event. */
+ internal static bool ThrowErr;
+
+ /** Events: before start. */
+ internal static IList<Event> BeforeStartEvts;
+
+ /** Events: after start. */
+ internal static IList<Event> AfterStartEvts;
+
+ /** Events: before stop. */
+ internal static IList<Event> BeforeStopEvts;
+
+ /** Events: after stop. */
+ internal static IList<Event> AfterStopEvts;
+
+ /// <summary>
+ /// Set up routine.
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ ThrowErr = false;
+
+ BeforeStartEvts = new List<Event>();
+ AfterStartEvts = new List<Event>();
+ BeforeStopEvts = new List<Event>();
+ AfterStopEvts = new List<Event>();
+ }
+
+ /// <summary>
+ /// Tear down routine.
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ Ignition.StopAll(true);
+ }
+
+ /// <summary>
+ /// Test without Java beans.
+ /// </summary>
+ [Test]
+ public void TestWithoutBeans()
+ {
+ // 1. Test start events.
+ IIgnite grid = Start(CfgNoBeans);
+
+ Assert.AreEqual(2, BeforeStartEvts.Count);
+ CheckEvent(BeforeStartEvts[0], null, null, 0, null);
+ CheckEvent(BeforeStartEvts[1], null, null, 0, null);
+
+ Assert.AreEqual(2, AfterStartEvts.Count);
+ CheckEvent(AfterStartEvts[0], grid, grid, 0, null);
+ CheckEvent(AfterStartEvts[1], grid, grid, 0, null);
+
+ // 2. Test stop events.
+ Ignition.Stop(grid.Name, false);
+
+ Assert.AreEqual(2, BeforeStartEvts.Count);
+ Assert.AreEqual(2, AfterStartEvts.Count);
+
+ Assert.AreEqual(2, BeforeStopEvts.Count);
+ CheckEvent(BeforeStopEvts[0], grid, grid, 0, null);
+ CheckEvent(BeforeStopEvts[1], grid, grid, 0, null);
+
+ Assert.AreEqual(2, AfterStopEvts.Count);
+ CheckEvent(AfterStopEvts[0], grid, grid, 0, null);
+ CheckEvent(AfterStopEvts[1], grid, grid, 0, null);
+ }
+
+ /// <summary>
+ /// Test with Java beans.
+ /// </summary>
+ [Test]
+ public void TestWithBeans()
+ {
+ // 1. Test .Net start events.
+ IIgnite grid = Start(CfgBeans);
+
+ Assert.AreEqual(4, BeforeStartEvts.Count);
+ CheckEvent(BeforeStartEvts[0], null, null, 0, null);
+ CheckEvent(BeforeStartEvts[1], null, null, 1, "1");
+ CheckEvent(BeforeStartEvts[2], null, null, 0, null);
+ CheckEvent(BeforeStartEvts[3], null, null, 0, null);
+
+ Assert.AreEqual(4, AfterStartEvts.Count);
+ CheckEvent(AfterStartEvts[0], grid, grid, 0, null);
+ CheckEvent(AfterStartEvts[1], grid, grid, 1, "1");
+ CheckEvent(AfterStartEvts[2], grid, grid, 0, null);
+ CheckEvent(AfterStartEvts[3], grid, grid, 0, null);
+
+ // 2. Test Java start events.
+ IList<int> res = grid.GetCompute().ExecuteJavaTask<IList<int>>(
+ "org.apache.ignite.platform.lifecycle.PlatformJavaLifecycleTask", null);
+
+ Assert.AreEqual(2, res.Count);
+ Assert.AreEqual(3, res[0]);
+ Assert.AreEqual(3, res[1]);
+
+ // 3. Test .Net stop events.
+ Ignition.Stop(grid.Name, false);
+
+ Assert.AreEqual(4, BeforeStartEvts.Count);
+ Assert.AreEqual(4, AfterStartEvts.Count);
+
+ Assert.AreEqual(4, BeforeStopEvts.Count);
+ CheckEvent(BeforeStopEvts[0], grid, grid, 0, null);
+ CheckEvent(BeforeStopEvts[1], grid, grid, 1, "1");
+ CheckEvent(BeforeStopEvts[2], grid, grid, 0, null);
+ CheckEvent(BeforeStopEvts[3], grid, grid, 0, null);
+
+ Assert.AreEqual(4, AfterStopEvts.Count);
+ CheckEvent(AfterStopEvts[0], grid, grid, 0, null);
+ CheckEvent(AfterStopEvts[1], grid, grid, 1, "1");
+ CheckEvent(AfterStopEvts[2], grid, grid, 0, null);
+ CheckEvent(AfterStopEvts[3], grid, grid, 0, null);
+ }
+
+ /// <summary>
+ /// Test behavior when error is thrown from lifecycle beans.
+ /// </summary>
+ [Test]
+ public void TestError()
+ {
+ ThrowErr = true;
+
+ try
+ {
+ Start(CfgNoBeans);
+
+ Assert.Fail("Should not reach this place.");
+ }
+ catch (Exception e)
+ {
+ Assert.AreEqual(typeof(IgniteException), e.GetType());
+ }
+ }
+
+ /// <summary>
+ /// Start grid.
+ /// </summary>
+ /// <param name="cfgPath">Spring configuration path.</param>
+ /// <returns>Grid.</returns>
+ private static IIgnite Start(string cfgPath)
+ {
+ TestUtils.JvmDebug = true;
+
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.JvmClasspath = TestUtils.CreateTestClasspath();
+ cfg.JvmOptions = TestUtils.TestJavaOptions();
+ cfg.SpringConfigUrl = cfgPath;
+
+ cfg.LifecycleBeans = new List<ILifecycleBean> { new Bean(), new Bean() };
+
+ return Ignition.Start(cfg);
+ }
+
+ /// <summary>
+ /// Check event.
+ /// </summary>
+ /// <param name="evt">Event.</param>
+ /// <param name="expGrid1">Expected grid 1.</param>
+ /// <param name="expGrid2">Expected grid 2.</param>
+ /// <param name="expProp1">Expected property 1.</param>
+ /// <param name="expProp2">Expected property 2.</param>
+ private static void CheckEvent(Event evt, IIgnite expGrid1, IIgnite expGrid2, int expProp1, string expProp2)
+ {
+ if (evt.Grid1 != null && evt.Grid1 is IgniteProxy)
+ evt.Grid1 = (evt.Grid1 as IgniteProxy).Target;
+
+ if (evt.Grid2 != null && evt.Grid2 is IgniteProxy)
+ evt.Grid2 = (evt.Grid2 as IgniteProxy).Target;
+
+ Assert.AreEqual(expGrid1, evt.Grid1);
+ Assert.AreEqual(expGrid2, evt.Grid2);
+ Assert.AreEqual(expProp1, evt.Prop1);
+ Assert.AreEqual(expProp2, evt.Prop2);
+ }
+ }
+
+ public abstract class AbstractBean
+ {
+ [InstanceResource]
+ public IIgnite Grid1;
+
+ public int Property1
+ {
+ get;
+ set;
+ }
+ }
+
+ public class Bean : AbstractBean, ILifecycleBean
+ {
+ [InstanceResource]
+ public IIgnite Grid2;
+
+ public string Property2
+ {
+ get;
+ set;
+ }
+
+ /** <inheritDoc /> */
+ public void OnLifecycleEvent(LifecycleEventType evtType)
+ {
+ if (LifecycleTest.ThrowErr)
+ throw new Exception("Lifecycle exception.");
+
+ Event evt = new Event();
+
+ evt.Grid1 = Grid1;
+ evt.Grid2 = Grid2;
+ evt.Prop1 = Property1;
+ evt.Prop2 = Property2;
+
+ switch (evtType)
+ {
+ case LifecycleEventType.BeforeNodeStart:
+ LifecycleTest.BeforeStartEvts.Add(evt);
+
+ break;
+
+ case LifecycleEventType.AfterNodeStart:
+ LifecycleTest.AfterStartEvts.Add(evt);
+
+ break;
+
+ case LifecycleEventType.BeforeNodeStop:
+ LifecycleTest.BeforeStopEvts.Add(evt);
+
+ break;
+
+ case LifecycleEventType.AfterNodeStop:
+ LifecycleTest.AfterStopEvts.Add(evt);
+
+ break;
+ }
+ }
+ }
+
+ public class Event
+ {
+ public IIgnite Grid1;
+ public IIgnite Grid2;
+ public int Prop1;
+ public string Prop2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs
new file mode 100644
index 0000000..25ffab3
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs
@@ -0,0 +1,243 @@
+/*
+ * 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.CodeDom.Compiler;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using Apache.Ignite.Core.Common;
+ using Microsoft.CSharp;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Dll loading test.
+ /// </summary>
+ public class LoadDllTest
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ TestUtils.KillProcesses();
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ Ignition.StopAll(true);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadFromGac()
+ {
+ Assert.False(IsLoaded("System.Data.Linq"));
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies =
+ new List<string>
+ {
+ "System.Data.Linq,Culture=neutral,Version=1.0.0.0,PublicKeyToken=b77a5c561934e089"
+ },
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.True(IsLoaded("System.Data.Linq"));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadFromCurrentDir()
+ {
+ Assert.False(IsLoaded("testDll"));
+
+ GenerateDll("testDll.dll");
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies = new List<string> {"testDll.dll"},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.True(IsLoaded("testDll"));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadAllDllInDir()
+ {
+ var dirInfo = Directory.CreateDirectory(Path.GetTempPath() + "/testDlls");
+
+ Assert.False(IsLoaded("dllFromDir1"));
+ Assert.False(IsLoaded("dllFromDir2"));
+
+ GenerateDll(dirInfo.FullName + "/dllFromDir1.dll");
+ GenerateDll(dirInfo.FullName + "/dllFromDir2.dll");
+ File.WriteAllText(dirInfo.FullName + "/notADll.txt", "notADll");
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies = new List<string> {dirInfo.FullName},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.True(IsLoaded("dllFromDir1"));
+ Assert.True(IsLoaded("dllFromDir2"));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadFromCurrentDirByName()
+ {
+ Assert.False(IsLoaded("testDllByName"));
+
+ GenerateDll("testDllByName.dll");
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies = new List<string> {"testDllByName"},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.True(IsLoaded("testDllByName"));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadByAbsoluteUri()
+ {
+ var dllPath = Path.GetTempPath() + "/tempDll.dll";
+ Assert.False(IsLoaded("tempDll"));
+
+ GenerateDll(dllPath);
+
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies = new List<string> {dllPath},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ var grid = Ignition.Start(cfg);
+
+ Assert.IsNotNull(grid);
+
+ Assert.True(IsLoaded("tempDll"));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Test]
+ public void TestLoadUnexistingLibrary()
+ {
+ var cfg = new IgniteConfiguration
+ {
+ SpringConfigUrl = "config\\start-test-grid3.xml",
+ Assemblies = new List<string> {"unexistingAssembly.820482.dll"},
+ JvmClasspath = TestUtils.CreateTestClasspath()
+ };
+
+ try
+ {
+ Ignition.Start(cfg);
+
+ Assert.Fail("Grid has been started with broken configuration.");
+ }
+ catch (IgniteException)
+ {
+
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="outputPath"></param>
+ private void GenerateDll(string outputPath)
+ {
+ var codeProvider = new CSharpCodeProvider();
+
+#pragma warning disable 0618
+
+ var icc = codeProvider.CreateCompiler();
+
+#pragma warning restore 0618
+
+ var parameters = new CompilerParameters
+ {
+ GenerateExecutable = false,
+ OutputAssembly = outputPath
+ };
+
+ var src = "namespace Apache.Ignite.Client.Test { public class Foo {}}";
+
+ var results = icc.CompileAssemblyFromSource(parameters, src);
+
+ Assert.False(results.Errors.HasErrors);
+ }
+
+ /// <summary>
+ /// Determines whether the specified assembly is loaded.
+ /// </summary>
+ /// <param name="asmName">Name of the assembly.</param>
+ private static bool IsLoaded(string asmName)
+ {
+ return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == asmName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs
new file mode 100644
index 0000000..d3af288
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs
@@ -0,0 +1,71 @@
+/*
+ * 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 Apache.Ignite.Core.Common;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Test marshaller initialization.
+ /// </summary>
+ public class MarshallerTest
+ {
+ /// <summary>
+ /// Tests the default marhsaller.
+ /// By default, portable marshaller is used.
+ /// </summary>
+ [Test]
+ public void TestDefaultMarhsaller()
+ {
+ using (var grid = Ignition.Start("config\\marshaller-default.xml"))
+ {
+ var cache = grid.GetOrCreateCache<int, int>(null);
+
+ cache.Put(1, 1);
+
+ Assert.AreEqual(1, cache.Get(1));
+ }
+ }
+
+ /// <summary>
+ /// Tests the portable marhsaller.
+ /// PortableMarshaller can be specified explicitly in config.
+ /// </summary>
+ [Test]
+ public void TestPortableMarhsaller()
+ {
+ using (var grid = Ignition.Start("config\\marshaller-portable.xml"))
+ {
+ var cache = grid.GetOrCreateCache<int, int>(null);
+
+ cache.Put(1, 1);
+
+ Assert.AreEqual(1, cache.Get(1));
+ }
+ }
+
+ /// <summary>
+ /// Tests the invalid marshaller.
+ /// </summary>
+ [Test]
+ public void TestInvalidMarshaller()
+ {
+ Assert.Throws<IgniteException>(() => Ignition.Start("config\\marshaller-invalid.xml"));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs
new file mode 100644
index 0000000..e32e622
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs
@@ -0,0 +1,213 @@
+/*
+ * 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.Memory
+{
+ using System;
+ using Apache.Ignite.Core.Impl.Memory;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests for interop memory.
+ /// </summary>
+ public class InteropMemoryTest
+ {
+ /// <summary>
+ /// Test pooled memory.
+ /// </summary>
+ [Test]
+ public void TestPooled()
+ {
+ PlatformMemoryManager mgr = new PlatformMemoryManager(256);
+
+ var mem1 = mgr.Allocate();
+ Assert.IsTrue(mem1 is PlatformPooledMemory);
+ Assert.IsTrue(mem1.Capacity >= 256);
+ Assert.IsTrue(mem1.Pointer > 0);
+ Assert.IsTrue(mem1.Data > 0);
+ Assert.AreEqual(0, mem1.Length);
+
+ mem1.Reallocate(512);
+
+ Assert.IsTrue(mem1.Capacity >= 512);
+ Assert.IsTrue(mem1.Pointer > 0);
+ Assert.IsTrue(mem1.Data > 0);
+ Assert.AreEqual(0, mem1.Length);
+
+ mem1.Length = 128;
+ Assert.AreEqual(128, mem1.Length);
+
+ mem1.Release();
+
+ Assert.AreSame(mem1, mgr.Allocate());
+ Assert.IsTrue(mem1.Capacity >= 512);
+ Assert.IsTrue(mem1.Pointer > 0);
+ Assert.IsTrue(mem1.Data > 0);
+ Assert.AreEqual(128, mem1.Length);
+
+ IPlatformMemory mem2 = mgr.Allocate();
+ Assert.IsTrue(mem2 is PlatformPooledMemory);
+
+ IPlatformMemory mem3 = mgr.Allocate();
+ Assert.IsTrue(mem3 is PlatformPooledMemory);
+
+ mem1.Release();
+ Assert.AreSame(mem1, mgr.Allocate());
+
+ mem2.Release();
+ Assert.AreSame(mem2, mgr.Allocate());
+
+ mem3.Release();
+ Assert.AreSame(mem3, mgr.Allocate());
+
+ mem1.Release();
+ mem2.Release();
+
+ Assert.AreSame(mem1, mgr.Allocate());
+ Assert.AreSame(mem2, mgr.Allocate());
+
+ IPlatformMemory unpooled = mgr.Allocate();
+
+ try
+ {
+ Assert.IsTrue(unpooled is PlatformUnpooledMemory);
+ }
+ finally
+ {
+ unpooled.Release();
+ }
+ }
+
+ /// <summary>
+ /// Test unpooled memory.
+ /// </summary>
+ [Test]
+ public void TestUnpooled()
+ {
+ PlatformMemoryManager mgr = new PlatformMemoryManager(256);
+
+ for (int i = 0; i < 3; i++)
+ mgr.Allocate();
+
+ IPlatformMemory mem1 = mgr.Allocate();
+ Assert.IsTrue(mem1 is PlatformUnpooledMemory);
+ Assert.IsTrue(mem1.Capacity >= 256);
+ Assert.IsTrue(mem1.Pointer > 0);
+ Assert.IsTrue(mem1.Data > 0);
+ Assert.AreEqual(0, mem1.Length);
+
+ mem1.Reallocate(512);
+ Assert.IsTrue(mem1.Capacity >= 512);
+ Assert.IsTrue(mem1.Pointer > 0);
+ Assert.IsTrue(mem1.Data > 0);
+ Assert.AreEqual(0, mem1.Length);
+
+ mem1.Length = 128;
+ Assert.AreEqual(128, mem1.Length);
+
+ mem1.Release();
+
+ IPlatformMemory mem2 = mgr.Allocate();
+ Assert.AreNotSame(mem1, mem2);
+ Assert.IsTrue(mem2.Capacity >= 256);
+ Assert.IsTrue(mem2.Pointer > 0);
+ Assert.IsTrue(mem2.Data > 0);
+ Assert.AreEqual(0, mem2.Length);
+
+ mem2.Release();
+ }
+
+ /// <summary>
+ /// Test pooled memory stream reallocation initiated from stream.
+ /// </summary>
+ [Test]
+ public void TestPooledStreamReallocate()
+ {
+ IPlatformMemory mem = new PlatformMemoryManager(256).Allocate();
+
+ try
+ {
+ Assert.IsTrue(mem is PlatformPooledMemory);
+
+ CheckStreamReallocate(mem);
+ }
+ finally
+ {
+ mem.Release();
+ }
+ }
+
+ /// <summary>
+ /// Test unpooled memory stream reallocation initiated from stream.
+ /// </summary>
+ [Test]
+ public void TestUnpooledStreamReallocate()
+ {
+ PlatformMemoryManager mgr = new PlatformMemoryManager(256);
+
+ for (int i = 0; i < 3; i++)
+ mgr.Allocate();
+
+ IPlatformMemory mem = mgr.Allocate();
+
+ try
+ {
+ Assert.IsTrue(mem is PlatformUnpooledMemory);
+
+ CheckStreamReallocate(mem);
+ }
+ finally
+ {
+ mem.Release();
+ }
+ }
+
+ /// <summary>
+ /// Check stream reallocation.
+ /// </summary>
+ /// <param name="mem">Memory.</param>
+ private void CheckStreamReallocate(IPlatformMemory mem)
+ {
+ Assert.IsTrue(mem.Capacity >= 256);
+
+ int dataLen = 2048 + 13;
+
+ Random rand = new Random();
+
+ byte[] data = new byte[dataLen];
+
+ for (int i = 0; i < data.Length; i++)
+ data[i] = (byte)rand.Next(0, 255);
+
+ PlatformMemoryStream stream = mem.Stream();
+
+ stream.WriteByteArray(data);
+
+ stream.SynchronizeOutput();
+
+ Assert.IsTrue(mem.Capacity >= dataLen);
+
+ stream.Reset();
+
+ stream.SynchronizeInput();
+
+ byte[] data0 = stream.ReadByteArray(dataLen);
+
+ Assert.AreEqual(data, data0);
+ }
+ }
+}