Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3F44E171EA for ; Tue, 22 Sep 2015 07:19:05 +0000 (UTC) Received: (qmail 16337 invoked by uid 500); 22 Sep 2015 07:19:05 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 16261 invoked by uid 500); 22 Sep 2015 07:19:05 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 14931 invoked by uid 99); 22 Sep 2015 07:19:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Sep 2015 07:19:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0931EE060F; Tue, 22 Sep 2015 07:19:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Tue, 22 Sep 2015 07:19:18 -0000 Message-Id: <5d4869ad37794db6af593178ae47d9c9@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/37] ignite git commit: IGNITE-1513: WIP on .Net. http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs deleted file mode 100644 index 0f4ba5e..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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; - - /// - /// Tests all examples in various modes. - /// - [Category(TestUtils.CategoryIntensive)] - public class ExamplesTest - { - /// - /// Tests the example in a single node mode. - /// - /// The example to run. - [Test, TestCaseSource("TestCases")] - public void TestLocalNode(Example example) - { - example.Run(); - } - - /// - /// Tests the example with standalone Apache.Ignite.exe nodes. - /// - /// The example to run. - [Test, TestCaseSource("TestCases")] - public void TestRemoteNodes(Example example) - { - TestRemoteNodes(example, false); - } - - /// - /// Tests the example with standalone Apache.Ignite.exe nodes while local node is in client mode. - /// - /// The example to run. - [Test, TestCaseSource("TestCases")] - public void TestRemoteNodesClientMode(Example example) - { - TestRemoteNodes(example, true); - } - - /// - /// Tests the example with standalone Apache.Ignite.exe nodes. - /// - /// The example to run. - /// Client mode flag. - 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 {"-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(); - } - } - - /// - /// Fixture setup. - /// - [TestFixtureSetUp] - public void FixtureSetUp() - { - Environment.SetEnvironmentVariable("IGNITE_NATIVE_TEST_CLASSPATH", "true"); - - Directory.SetCurrentDirectory(PathUtil.IgniteHome); - } - - /// - /// Test teardown. - /// - [TearDown] - public void TearDown() - { - Ignition.ClientMode = false; - IgniteProcess.KillAll(); - } - - /// - /// Gets the test cases. - /// - public IEnumerable TestCases - { - get { return Example.All; } - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs deleted file mode 100644 index 4f9625f..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/PathUtil.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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; - - /// - /// Grid path resolver. - /// - public static class PathUtil - { - public static readonly string IgniteHome = IgniteManager.GetIgniteHome(null); - - /// - /// Full Apache.Ignite.exe path. - /// - public static readonly string IgniteExePath = typeof(IgniteRunner).Assembly.Location; - - /// - /// Examples source code path. - /// - public static readonly string ExamplesSourcePath = Path.Combine(IgniteHome, @"platforms\dotnet\Examples"); - - /// - /// Gets the full configuration path. - /// - 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/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs deleted file mode 100644 index 24bd663..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Examples/ProjectFilesTest.cs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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; - - /// - /// Tests project files. - /// - public class ProjectFilesTest - { - /// - /// Checks config files in examples comments for existence. - /// - [Test] - public void CheckConfigFilesExist() - { - Directory.GetFiles(PathUtil.ExamplesSourcePath, "*.cs", SearchOption.AllDirectories) - .Select(File.ReadAllText) - .SelectMany(src => Regex.Matches(src, @"modules\\platform[^\s]+.xml").OfType()) - .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/src/test/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs deleted file mode 100644 index 7a5a725..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs +++ /dev/null @@ -1,352 +0,0 @@ -/* - * 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; - - /// - /// Tests grid exceptions propagation. - /// - public class ExceptionsTest - { - /// - /// Before test. - /// - [SetUp] - public void SetUp() - { - TestUtils.KillProcesses(); - } - - /// - /// After test. - /// - [TearDown] - public void TearDown() - { - Ignition.StopAll(true); - } - - /// - /// Tests exceptions. - /// - [Test] - public void TestExceptions() - { - var grid = StartGrid(); - - try - { - grid.GetCache("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("cache1"); - - Assert.Fail(); - } - catch (Exception e) - { - Assert.IsTrue(e is InvalidOperationException); - } - } - - /// - /// Tests CachePartialUpdateException keys propagation. - /// - [Test] - [Category(TestUtils.CategoryIntensive)] - public void TestPartialUpdateException() - { - // Primitive type - TestPartialUpdateException(false, (x, g) => x); - - // User type - TestPartialUpdateException(false, (x, g) => new PortableEntry(x)); - } - - /// - /// Tests CachePartialUpdateException keys propagation in portable mode. - /// - [Test] - [Category(TestUtils.CategoryIntensive)] - public void TestPartialUpdateExceptionPortable() - { - // User type - TestPartialUpdateException(false, (x, g) => g.GetPortables().ToPortable(new PortableEntry(x))); - } - - /// - /// Tests CachePartialUpdateException serialization. - /// - [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) - })); - } - - /// - /// Tests CachePartialUpdateException serialization. - /// - 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(), - ((CachePartialUpdateException)ex0).GetFailedKeys()); - } - 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); - } - - /// - /// Tests CachePartialUpdateException keys propagation. - /// - [Test] - [Category(TestUtils.CategoryIntensive)] - public void TestPartialUpdateExceptionAsync() - { - // Primitive type - TestPartialUpdateException(true, (x, g) => x); - - // User type - TestPartialUpdateException(true, (x, g) => new PortableEntry(x)); - } - - /// - /// Tests CachePartialUpdateException keys propagation in portable mode. - /// - [Test] - [Category(TestUtils.CategoryIntensive)] - public void TestPartialUpdateExceptionAsyncPortable() - { - TestPartialUpdateException(true, (x, g) => g.GetPortables().ToPortable(new PortableEntry(x))); - } - - /// - /// Tests CachePartialUpdateException keys propagation. - /// - private static void TestPartialUpdateException(bool async, Func keyFunc) - { - using (var grid = StartGrid()) - { - var cache = grid.GetCache("partitioned_atomic").WithNoRetries(); - - if (async) - cache = cache.WithAsync(); - - if (typeof (TK) == typeof (IPortableObject)) - cache = cache.WithKeepPortable(); - - // 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(); - - Assert.IsTrue(failedKeys.Any()); - - var failedKeysObj = ex.GetFailedKeys(); - - 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; - } - } - } - - /// - /// Starts the grid. - /// - 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)) - } - } - }); - } - - /// - /// Portable entry. - /// - private class PortableEntry - { - /** Value. */ - private readonly int _val; - - /** */ - public override int GetHashCode() - { - return _val; - } - - /// - /// Constructor. - /// - /// Value. - public PortableEntry(int val) - { - _val = val; - } - - /** */ - public override bool Equals(object obj) - { - return obj is PortableEntry && ((PortableEntry)obj)._val == _val; - } - } - - /// - /// Portable entry. - /// - [Serializable] - private class SerializableEntry - { - /** Value. */ - private readonly int _val; - - /** */ - public override int GetHashCode() - { - return _val; - } - - /// - /// Constructor. - /// - /// Value. - public SerializableEntry(int val) - { - _val = val; - } - - /** */ - 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/src/test/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs deleted file mode 100644 index abb296c..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs +++ /dev/null @@ -1,443 +0,0 @@ -/* - * 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; - - /// - /// Tests for executable. - /// - 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; - - /// - /// Test fixture set-up routine. - /// - [TestFixtureSetUp] - public void TestFixtureSetUp() - { - TestUtils.KillProcesses(); - - _grid = Ignition.Start(Configuration(SpringCfgPath)); - } - - /// - /// Test fixture tear-down routine. - /// - [TestFixtureTearDown] - public void TestFixtureTearDown() - { - Ignition.StopAll(true); - - TestUtils.KillProcesses(); - } - - /// - /// Set-up routine. - /// - [SetUp] - public void SetUp() - { - TestUtils.KillProcesses(); - - Assert.IsTrue(_grid.WaitTopology(1, 30000)); - - IgniteProcess.SaveConfigurationBackup(); - } - - /// - /// Tear-down routine. - /// - [TearDown] - public void TearDown() - { - IgniteProcess.RestoreConfigurationBackup(); - } - - /// - /// Test data pass through configuration file. - /// - [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); - } - - /// - /// Test assemblies passing through command-line. - /// - [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")); - } - - /// - /// Test JVM options passing through command-line. - /// - [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")); - } - - /// - /// Test JVM memory options passing through command-line: raw java options. - /// - [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(MinMemTask, null); - Assert.AreEqual((long) 506*1024*1024, minMem); - - var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask(MaxMemTask, null); - AssertJvmMaxMemory((long) 607*1024*1024, maxMem); - } - - /// - /// Test JVM memory options passing through command-line: custom options. - /// - [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(MinMemTask, null); - Assert.AreEqual((long) 615*1024*1024, minMem); - - var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask(MaxMemTask, null); - AssertJvmMaxMemory((long) 863*1024*1024, maxMem); - } - - /// - /// Test JVM memory options passing from application configuration. - /// - [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(MinMemTask, null); - Assert.AreEqual((long) 601*1024*1024, minMem); - - var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask(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(MinMemTask, null); - Assert.AreEqual((long) 605*1024*1024, minMem); - - maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask(MaxMemTask, null); - AssertJvmMaxMemory((long) 706*1024*1024, maxMem); - } - - /// - /// Test JVM memory options passing through command-line: custom options + raw options. - /// - [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(MinMemTask, null); - Assert.AreEqual((long) 555*1024*1024, minMem); - - var maxMem = _grid.GetCluster().ForRemotes().GetCompute().ExecuteJavaTask(MaxMemTask, null); - AssertJvmMaxMemory((long) 666*1024*1024, maxMem); - } - - /// - /// Get remote node configuration. - /// - /// Configuration. - private RemoteConfiguration RemoteConfig() - { - return _grid.GetCluster().ForRemotes().GetCompute().Call(new RemoteConfigurationClosure()); - } - - /// - /// Configuration for node. - /// - /// Path to Java XML configuration. - /// Node configuration. - private static IgniteConfiguration Configuration(string path) - { - var cfg = new IgniteConfiguration(); - - - var portCfg = new PortableConfiguration(); - - ICollection portTypeCfgs = new List(); - - 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 - { - "-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; - } - - /// - /// - /// - /// - 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); - } - - /// - /// Asserts that JVM maximum memory corresponds to Xmx parameter value. - /// - 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); - } - - /// - /// Closure which extracts configuration and passes it back. - /// - public class RemoteConfigurationClosure : IComputeFunc - { - -#pragma warning disable 0649 - - /** Grid. */ - [InstanceResource] private IIgnite _grid; - -#pragma warning restore 0649 - - /** */ - - 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; - } - } - - /// - /// Configuration. - /// - public class RemoteConfiguration - { - /// - /// GG home. - /// - public string IgniteHome { get; set; } - - /// - /// Spring config URL. - /// - public string SpringConfigUrl { get; set; } - - /// - /// JVM DLL. - /// - public string JvmDll { get; set; } - - /// - /// JVM classpath. - /// - public string JvmClasspath { get; set; } - - /// - /// JVM options. - /// - public ICollection JvmOptions { get; set; } - - /// - /// Assemblies. - /// - public ICollection Assemblies { get; set; } - - /// - /// Minimum JVM memory (Xms). - /// - public int JvmInitialMemoryMb { get; set; } - - /// - /// Maximum JVM memory (Xms). - /// - public int JvmMaxMemoryMb { get; set; } - - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs deleted file mode 100644 index 993c604..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs +++ /dev/null @@ -1,278 +0,0 @@ -/* - * 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; - - /// - /// Future tests. - /// - public class FutureTest - { - /** */ - private ICache _cache; - - /** */ - private ICompute _compute; - - /// - /// Test fixture set-up routine. - /// - [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 { new PortableTypeConfiguration(typeof(Portable)) } - } - }); - - _cache = grid.GetCache(null).WithAsync(); - - _compute = grid.GetCompute().WithAsync(); - } - - /// - /// Test fixture tear-down routine. - /// - [TestFixtureTearDown] - public void TestFixtureTearDown() - { - TestUtils.KillProcesses(); - } - - [Test] - public void TestListen() - { - // Listen(Action callback) - TestListen((fut, act) => fut.Listen(act)); - - // Listen(Action callback) - TestListen((fut, act) => ((IFuture)fut).Listen(f => - { - Assert.AreEqual(f, fut); - act(); - })); - - // Listen(Action> callback) - TestListen((fut, act) => fut.Listen(f => - { - Assert.AreEqual(f, fut); - act(); - })); - } - - private void TestListen(Action, Action> listenAction) - { - _compute.Broadcast(new SleepAction()); - - var fut = _compute.GetFuture(); - - 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().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(() => 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" }); - } - - /// - /// Tests future type. - /// - private void TestType(T value) - { - var key = typeof(T).Name; - - _cache.Put(key, value); - - _cache.GetFuture().Get(); - - _cache.Get(key); - - Assert.AreEqual(value, _cache.GetFuture().Get()); - } - - /// - /// Portable test class. - /// - private class Portable : IPortableMarshalAware - { - public int A; - public string B; - - /** */ - public void WritePortable(IPortableWriter writer) - { - writer.WriteInt("a", A); - writer.RawWriter().WriteString(B); - } - - /** */ - public void ReadPortable(IPortableReader reader) - { - A = reader.ReadInt("a"); - B = reader.RawReader().ReadString(); - } - - /** */ - 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); - } - - /** */ - public override int GetHashCode() - { - unchecked - { - // ReSharper disable NonReadonlyMemberInGetHashCode - return (A * 397) ^ (B != null ? B.GetHashCode() : 0); - // ReSharper restore NonReadonlyMemberInGetHashCode - } - } - } - - /// - /// Compute action with a delay to ensure lengthy future execution. - /// - [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/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs deleted file mode 100644 index 5a90c20..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteManagerTest.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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; - - /// - /// Tests IgniteManager class. - /// - public class IgniteManagerTest - { - /// - /// Tests home dir resolver. - /// - [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/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs deleted file mode 100644 index bd776ce..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs +++ /dev/null @@ -1,422 +0,0 @@ -/* - * 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; - - /// - /// Ignite start/stop tests. - /// - [Category(TestUtils.CategoryIntensive)] - public class IgniteStartStopTest - { - /// - /// - /// - [SetUp] - public void SetUp() - { - TestUtils.KillProcesses(); - } - - /// - /// - /// - [TearDown] - public void TearDown() - { - TestUtils.KillProcesses(); - Ignition.StopAll(true); - } - - /// - /// - /// - [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); - } - - /// - /// - /// - [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); - } - - /// - /// - /// - [Test] - public void TestStartGetStop() - { - var cfgs = new List { "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 { "grid1", "grid2", null }) - Assert.IsNotNull(Ignition.GetIgnite(gridName)); - - Ignition.StopAll(true); - - foreach (var gridName in new List { "grid1", "grid2", null }) - { - try - { - Ignition.GetIgnite(gridName); - } - catch (IgniteException e) - { - Console.WriteLine("Expected exception: " + e); - } - } - } - - /// - /// - /// - [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); - } - } - - /// - /// - /// - [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("cache1")); - - grid.Dispose(); - - try - { - grid.GetCache("cache1"); - - Assert.Fail(); - } - catch (InvalidOperationException e) - { - Console.WriteLine("Expected exception: " + e); - } - } - - /// - /// - /// - [Test] - public void TestStartStopLeak() - { - var cfg = new IgniteConfiguration - { - SpringConfigUrl = "config\\start-test-grid1.xml", - JvmOptions = new List {"-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. - } - } - - /// - /// Tests the client mode flag. - /// - [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; - } - } - - /// - /// Uses the ignite. - /// - /// The ignite. - 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("cache1"); - - Assert.IsNotNull(cache); - - cache.GetAndPut(1, 1); - - Assert.AreEqual(1, cache.Get(1)); - } - - /// - /// Tests the processor initialization and grid usage right after topology enter. - /// - [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)); - } - - /// - /// Noop message filter. - /// - [Serializable] - private class MessageFilter : IMessageFilter - { - /** */ - public bool Invoke(Guid nodeId, int message) - { - return true; - } - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/65bb69da/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs deleted file mode 100644 index 84f446c..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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; - - /// - /// Lifecycle beans test. - /// - 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 BeforeStartEvts; - - /** Events: after start. */ - internal static IList AfterStartEvts; - - /** Events: before stop. */ - internal static IList BeforeStopEvts; - - /** Events: after stop. */ - internal static IList AfterStopEvts; - - /// - /// Set up routine. - /// - [SetUp] - public void SetUp() - { - ThrowErr = false; - - BeforeStartEvts = new List(); - AfterStartEvts = new List(); - BeforeStopEvts = new List(); - AfterStopEvts = new List(); - } - - /// - /// Tear down routine. - /// - [TearDown] - public void TearDown() - { - Ignition.StopAll(true); - } - - /// - /// Test without Java beans. - /// - [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); - } - - /// - /// Test with Java beans. - /// - [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 res = grid.GetCompute().ExecuteJavaTask>( - "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); - } - - /// - /// Test behavior when error is thrown from lifecycle beans. - /// - [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()); - } - } - - /// - /// Start grid. - /// - /// Spring configuration path. - /// Grid. - 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 { new Bean(), new Bean() }; - - return Ignition.Start(cfg); - } - - /// - /// Check event. - /// - /// Event. - /// Expected grid 1. - /// Expected grid 2. - /// Expected property 1. - /// Expected property 2. - 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; - } - - /** */ - 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/src/test/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs deleted file mode 100644 index 25ffab3..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/LoadDllTest.cs +++ /dev/null @@ -1,243 +0,0 @@ -/* - * 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; - - /// - /// Dll loading test. - /// - public class LoadDllTest - { - /// - /// - /// - [SetUp] - public void SetUp() - { - TestUtils.KillProcesses(); - } - - /// - /// - /// - [TearDown] - public void TearDown() - { - Ignition.StopAll(true); - } - - /// - /// - /// - [Test] - public void TestLoadFromGac() - { - Assert.False(IsLoaded("System.Data.Linq")); - - var cfg = new IgniteConfiguration - { - SpringConfigUrl = "config\\start-test-grid3.xml", - Assemblies = - new List - { - "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")); - } - - /// - /// - /// - [Test] - public void TestLoadFromCurrentDir() - { - Assert.False(IsLoaded("testDll")); - - GenerateDll("testDll.dll"); - - var cfg = new IgniteConfiguration - { - SpringConfigUrl = "config\\start-test-grid3.xml", - Assemblies = new List {"testDll.dll"}, - JvmClasspath = TestUtils.CreateTestClasspath() - }; - - var grid = Ignition.Start(cfg); - - Assert.IsNotNull(grid); - - Assert.True(IsLoaded("testDll")); - } - - /// - /// - /// - [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 {dirInfo.FullName}, - JvmClasspath = TestUtils.CreateTestClasspath() - }; - - var grid = Ignition.Start(cfg); - - Assert.IsNotNull(grid); - - Assert.True(IsLoaded("dllFromDir1")); - Assert.True(IsLoaded("dllFromDir2")); - } - - /// - /// - /// - [Test] - public void TestLoadFromCurrentDirByName() - { - Assert.False(IsLoaded("testDllByName")); - - GenerateDll("testDllByName.dll"); - - var cfg = new IgniteConfiguration - { - SpringConfigUrl = "config\\start-test-grid3.xml", - Assemblies = new List {"testDllByName"}, - JvmClasspath = TestUtils.CreateTestClasspath() - }; - - var grid = Ignition.Start(cfg); - - Assert.IsNotNull(grid); - - Assert.True(IsLoaded("testDllByName")); - } - - /// - /// - /// - [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 {dllPath}, - JvmClasspath = TestUtils.CreateTestClasspath() - }; - - var grid = Ignition.Start(cfg); - - Assert.IsNotNull(grid); - - Assert.True(IsLoaded("tempDll")); - } - - /// - /// - /// - [Test] - public void TestLoadUnexistingLibrary() - { - var cfg = new IgniteConfiguration - { - SpringConfigUrl = "config\\start-test-grid3.xml", - Assemblies = new List {"unexistingAssembly.820482.dll"}, - JvmClasspath = TestUtils.CreateTestClasspath() - }; - - try - { - Ignition.Start(cfg); - - Assert.Fail("Grid has been started with broken configuration."); - } - catch (IgniteException) - { - - } - } - - /// - /// - /// - /// - 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); - } - - /// - /// Determines whether the specified assembly is loaded. - /// - /// Name of the assembly. - 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/src/test/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs deleted file mode 100644 index d3af288..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/MarshallerTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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; - - /// - /// Test marshaller initialization. - /// - public class MarshallerTest - { - /// - /// Tests the default marhsaller. - /// By default, portable marshaller is used. - /// - [Test] - public void TestDefaultMarhsaller() - { - using (var grid = Ignition.Start("config\\marshaller-default.xml")) - { - var cache = grid.GetOrCreateCache(null); - - cache.Put(1, 1); - - Assert.AreEqual(1, cache.Get(1)); - } - } - - /// - /// Tests the portable marhsaller. - /// PortableMarshaller can be specified explicitly in config. - /// - [Test] - public void TestPortableMarhsaller() - { - using (var grid = Ignition.Start("config\\marshaller-portable.xml")) - { - var cache = grid.GetOrCreateCache(null); - - cache.Put(1, 1); - - Assert.AreEqual(1, cache.Get(1)); - } - } - - /// - /// Tests the invalid marshaller. - /// - [Test] - public void TestInvalidMarshaller() - { - Assert.Throws(() => 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/src/test/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs deleted file mode 100644 index e32e622..0000000 --- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Memory/InteropMemoryTest.cs +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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; - - /// - /// Tests for interop memory. - /// - public class InteropMemoryTest - { - /// - /// Test pooled memory. - /// - [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(); - } - } - - /// - /// Test unpooled memory. - /// - [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(); - } - - /// - /// Test pooled memory stream reallocation initiated from stream. - /// - [Test] - public void TestPooledStreamReallocate() - { - IPlatformMemory mem = new PlatformMemoryManager(256).Allocate(); - - try - { - Assert.IsTrue(mem is PlatformPooledMemory); - - CheckStreamReallocate(mem); - } - finally - { - mem.Release(); - } - } - - /// - /// Test unpooled memory stream reallocation initiated from stream. - /// - [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(); - } - } - - /// - /// Check stream reallocation. - /// - /// Memory. - 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); - } - } -}