Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5046E200B77 for ; Fri, 19 Aug 2016 13:48:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4ED49160AAC; Fri, 19 Aug 2016 11:48:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 73371160ACA for ; Fri, 19 Aug 2016 13:48:22 +0200 (CEST) Received: (qmail 80568 invoked by uid 500); 19 Aug 2016 11:48:21 -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 78839 invoked by uid 99); 19 Aug 2016 11:48:19 -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; Fri, 19 Aug 2016 11:48:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 64368E2EF2; Fri, 19 Aug 2016 11:48:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Fri, 19 Aug 2016 11:49:00 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [43/53] [abbrv] ignite git commit: IGNITE-3368 .NET: Improve test coverage archived-at: Fri, 19 Aug 2016 11:48:26 -0000 IGNITE-3368 .NET: Improve test coverage This closes #953 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e4eda7cf Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e4eda7cf Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e4eda7cf Branch: refs/heads/ignite-3299 Commit: e4eda7cf3a0de5ed3c6e4aaff4180ca80b1a981a Parents: ecc734c Author: Pavel Tupitsyn Authored: Tue Aug 16 18:11:34 2016 +0300 Committer: Pavel Tupitsyn Committed: Tue Aug 16 18:11:34 2016 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests.csproj | 10 + .../Binary/BinaryBuilderSelfTest.cs | 24 ++- .../Binary/BinaryReaderWriterTest.cs | 171 +++++++++++++++++ .../Binary/IO/BinaryStreamsTest.cs | 151 +++++++++++++++ .../Cache/Affinity/AffinityKeyTest.cs | 66 +++++++ .../Affinity/AffinityTopologyVersionTest.cs | 59 ++++++ .../Cache/CacheAbstractTest.cs | 62 +++++- .../Cache/CacheResultTest.cs | 75 ++++++++ .../Continuous/ContinuousQueryAbstractTest.cs | 42 ++-- .../Cache/Store/CacheParallelLoadStoreTest.cs | 2 +- .../Cache/Store/CacheStoreAdapterTest.cs | 90 +++++++++ .../Cache/Store/CacheTestParallelLoadStore.cs | 9 + .../Collections/MultiValueDictionaryTest.cs | 58 ++++++ .../Collections/ReadOnlyCollectionTest.cs | 59 ++++++ .../Collections/ReadOnlyDictionaryTest.cs | 70 +++++++ .../Common/IgniteGuidTest.cs | 62 ++++++ .../Compute/AbstractTaskTest.cs | 40 ++-- .../Compute/BinarizableClosureTaskTest.cs | 18 +- .../Compute/BinarizableTaskTest.cs | 18 +- .../Compute/CancellationTest.cs | 10 + .../Compute/ClosureTaskTest.cs | 192 +++++-------------- .../Compute/ComputeApiTest.cs | 53 +++-- .../Compute/FailoverTaskSelfTest.cs | 5 +- .../Compute/IgniteExceptionTaskSelfTest.cs | 43 ++--- .../Compute/ResourceTaskTest.cs | 51 +++++ .../Compute/SerializableClosureTaskTest.cs | 5 + .../Compute/TaskAdapterTest.cs | 5 +- .../Compute/TaskResultTest.cs | 14 +- .../Config/Compute/compute-standalone.xml | 1 + .../Apache.Ignite.Core.Tests/EventsTest.cs | 192 +++++++++++++++---- .../Examples/ExamplesTest.cs | 2 +- .../Apache.Ignite.Core.Tests/ExceptionsTest.cs | 46 +++++ .../Apache.Ignite.Core.Tests/TestUtils.cs | 3 + .../Apache.Ignite.Core.csproj | 3 - .../Cache/Affinity/AffinityKey.cs | 11 ++ .../Cache/CachePartialUpdateException.cs | 6 +- .../Store/CacheParallelLoadStoreAdapter.cs | 7 + .../Apache.Ignite.Core/Common/JavaException.cs | 1 + .../Impl/Binary/BinaryObject.cs | 2 + .../Impl/Binary/BinaryObjectBuilder.cs | 2 +- .../Impl/Binary/BinaryObjectHandle.cs | 59 ------ .../Impl/Binary/BinaryObjectHeader.cs | 5 +- .../Binary/BinarySurrogateTypeDescriptor.cs | 2 +- .../Impl/Binary/BinaryWriter.cs | 20 -- .../Impl/Binary/Io/BinaryStreamAdapter.cs | 5 + .../Impl/Binary/Io/BinaryStreamBase.cs | 11 +- .../Impl/Binary/Io/IBinaryStream.cs | 2 +- .../Apache.Ignite.Core/Impl/Binary/JavaTypes.cs | 11 -- .../Cache/Event/JavaCacheEntryEventFilter.cs | 2 + .../Impl/Collections/MultiValueDictionary.cs | 26 --- .../Impl/Collections/ReadOnlyDictionary.cs | 2 +- .../Impl/Common/ResizeableArray.cs | 64 ------- .../Impl/Events/EventTypeConverter.cs | 3 + .../Apache.Ignite.Core/Impl/Events/Events.cs | 3 + .../Apache.Ignite.Core/Impl/ExceptionUtils.cs | 1 + .../Apache.Ignite.Core/Impl/Handle/Handle.cs | 12 +- .../Impl/Handle/HandleRegistry.cs | 20 +- .../Apache.Ignite.Core/Impl/Handle/IHandle.cs | 5 - .../Apache.Ignite.Core/Impl/IgniteProxy.cs | 1 + .../Apache.Ignite.Core/Impl/IgniteUtils.cs | 22 +-- .../Impl/InteropExceptionHolder.cs | 88 --------- .../Impl/Memory/PlatformMemoryUtils.cs | 30 --- .../Impl/Memory/PlatformRawMemory.cs | 4 + .../Apache.Ignite.Core/Impl/PlatformTarget.cs | 8 - 64 files changed, 1464 insertions(+), 682 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj index 29dc81b..c4dcbae 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj @@ -56,6 +56,16 @@ + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs index 80788a6..c280255 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs @@ -24,6 +24,7 @@ namespace Apache.Ignite.Core.Tests.Binary using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.RegularExpressions; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.Impl.Binary; @@ -590,6 +591,23 @@ namespace Apache.Ignite.Core.Tests.Binary } /// + /// Tests equality and formatting members. + /// + [Test] + public void TestEquality() + { + var bin = _grid.GetBinary(); + + var obj1 = bin.GetBuilder("myType").SetStringField("str", "foo").SetIntField("int", 1).Build(); + var obj2 = bin.GetBuilder("myType").SetStringField("str", "foo").SetIntField("int", 1).Build(); + + Assert.AreEqual(obj1, obj2); + Assert.AreEqual(obj1.GetHashCode(), obj2.GetHashCode()); + + Assert.IsTrue(Regex.IsMatch(obj1.ToString(), @"myType \[idHash=[0-9]+, str=foo, int=1\]")); + } + + /// /// Test primitive fields setting. /// [Test] @@ -1617,9 +1635,13 @@ namespace Apache.Ignite.Core.Tests.Binary foreach (var binEnum in binEnums) { Assert.IsTrue(binEnum.GetBinaryType().IsEnum); + Assert.AreEqual(val, binEnum.EnumValue); - Assert.AreEqual((TestEnumRegistered)val, binEnum.Deserialize()); + + Assert.AreEqual((TestEnumRegistered) val, binEnum.Deserialize()); } + + Assert.AreEqual(binEnums[0], binEnums[1]); } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryReaderWriterTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryReaderWriterTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryReaderWriterTest.cs new file mode 100644 index 0000000..e4cff1b --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryReaderWriterTest.cs @@ -0,0 +1,171 @@ +/* + * 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.Binary +{ + using System; + using Apache.Ignite.Core.Binary; + using Apache.Ignite.Core.Impl.Binary; + using NUnit.Framework; + + /// + /// Tests the and classes. + /// + public class BinaryReaderWriterTest + { + /// + /// Tests all read/write methods. + /// + [Test] + public void TestWriteRead() + { + var marsh = new Marshaller(new BinaryConfiguration(typeof(ReadWriteAll))); + + marsh.Unmarshal(marsh.Marshal(new ReadWriteAll())); + } + + private class ReadWriteAll : IBinarizable + { + private static readonly DateTime Date = DateTime.UtcNow; + + private static readonly Guid Guid = Guid.NewGuid(); + + public void WriteBinary(IBinaryWriter writer) + { + writer.WriteByte("Byte", 1); + writer.WriteByteArray("ByteArray", new byte[] {1}); + writer.WriteChar("Char", '1'); + writer.WriteCharArray("CharArray", new[] {'1'}); + writer.WriteShort("Short", 1); + writer.WriteShortArray("ShortArray", new short[] {1}); + writer.WriteInt("Int", 1); + writer.WriteIntArray("IntArray", new[] {1}); + writer.WriteLong("Long", 1); + writer.WriteLongArray("LongArray", new long[] {1}); + writer.WriteBoolean("Boolean", true); + writer.WriteBooleanArray("BooleanArray", new[] {true}); + writer.WriteFloat("Float", 1); + writer.WriteFloatArray("FloatArray", new float[] {1}); + writer.WriteDouble("Double", 1); + writer.WriteDoubleArray("DoubleArray", new double[] {1}); + writer.WriteDecimal("Decimal", 1); + writer.WriteDecimalArray("DecimalArray", new decimal?[] {1}); + writer.WriteTimestamp("Timestamp", Date); + writer.WriteTimestampArray("TimestampArray", new DateTime?[] {Date}); + writer.WriteString("String", "1"); + writer.WriteStringArray("StringArray", new[] {"1"}); + writer.WriteGuid("Guid", Guid); + writer.WriteGuidArray("GuidArray", new Guid?[] {Guid}); + writer.WriteEnum("Enum", MyEnum.Bar); + writer.WriteEnumArray("EnumArray", new[] {MyEnum.Bar}); + + var raw = writer.GetRawWriter(); + + raw.WriteByte(1); + raw.WriteByteArray(new byte[] {1}); + raw.WriteChar('1'); + raw.WriteCharArray(new[] {'1'}); + raw.WriteShort(1); + raw.WriteShortArray(new short[] {1}); + raw.WriteInt(1); + raw.WriteIntArray(new[] {1}); + raw.WriteLong(1); + raw.WriteLongArray(new long[] {1}); + raw.WriteBoolean(true); + raw.WriteBooleanArray(new[] {true}); + raw.WriteFloat(1); + raw.WriteFloatArray(new float[] {1}); + raw.WriteDouble(1); + raw.WriteDoubleArray(new double[] {1}); + raw.WriteDecimal(1); + raw.WriteDecimalArray(new decimal?[] {1}); + raw.WriteTimestamp(Date); + raw.WriteTimestampArray(new DateTime?[] {Date}); + raw.WriteString("1"); + raw.WriteStringArray(new[] {"1"}); + raw.WriteGuid(Guid); + raw.WriteGuidArray(new Guid?[] {Guid}); + raw.WriteEnum(MyEnum.Bar); + raw.WriteEnumArray(new[] {MyEnum.Bar}); + } + + public void ReadBinary(IBinaryReader reader) + { + Assert.AreEqual(1, reader.ReadByte("Byte")); + Assert.AreEqual(new byte[] {1}, reader.ReadByteArray("ByteArray")); + Assert.AreEqual('1', reader.ReadChar("Char")); + Assert.AreEqual(new[] {'1'}, reader.ReadCharArray("CharArray")); + Assert.AreEqual(1, reader.ReadShort("Short")); + Assert.AreEqual(new short[] {1}, reader.ReadShortArray("ShortArray")); + Assert.AreEqual(1, reader.ReadInt("Int")); + Assert.AreEqual(new[] {1}, reader.ReadIntArray("IntArray")); + Assert.AreEqual(1, reader.ReadLong("Long")); + Assert.AreEqual(new long[] {1}, reader.ReadLongArray("LongArray")); + Assert.AreEqual(true, reader.ReadBoolean("Boolean")); + Assert.AreEqual(new[] {true}, reader.ReadBooleanArray("BooleanArray")); + Assert.AreEqual(1, reader.ReadFloat("Float")); + Assert.AreEqual(new float[] {1}, reader.ReadFloatArray("FloatArray")); + Assert.AreEqual(1, reader.ReadDouble("Double")); + Assert.AreEqual(new double[] {1}, reader.ReadDoubleArray("DoubleArray")); + Assert.AreEqual(1, reader.ReadDecimal("Decimal")); + Assert.AreEqual(new decimal?[] {1}, reader.ReadDecimalArray("DecimalArray")); + Assert.AreEqual(Date, reader.ReadTimestamp("Timestamp")); + Assert.AreEqual(new DateTime?[] {Date}, reader.ReadTimestampArray("TimestampArray")); + Assert.AreEqual("1", reader.ReadString("String")); + Assert.AreEqual(new[] {"1"}, reader.ReadStringArray("StringArray")); + Assert.AreEqual(Guid, reader.ReadGuid("Guid")); + Assert.AreEqual(new Guid?[] {Guid}, reader.ReadGuidArray("GuidArray")); + Assert.AreEqual(MyEnum.Bar, reader.ReadEnum("Enum")); + Assert.AreEqual(new[] {MyEnum.Bar}, reader.ReadEnumArray("EnumArray")); + + var raw = reader.GetRawReader(); + + Assert.AreEqual(1, raw.ReadByte()); + Assert.AreEqual(new byte[] { 1 }, raw.ReadByteArray()); + Assert.AreEqual('1', raw.ReadChar()); + Assert.AreEqual(new[] { '1' }, raw.ReadCharArray()); + Assert.AreEqual(1, raw.ReadShort()); + Assert.AreEqual(new short[] { 1 }, raw.ReadShortArray()); + Assert.AreEqual(1, raw.ReadInt()); + Assert.AreEqual(new[] { 1 }, raw.ReadIntArray()); + Assert.AreEqual(1, raw.ReadLong()); + Assert.AreEqual(new long[] { 1 }, raw.ReadLongArray()); + Assert.AreEqual(true, raw.ReadBoolean()); + Assert.AreEqual(new[] { true }, raw.ReadBooleanArray()); + Assert.AreEqual(1, raw.ReadFloat()); + Assert.AreEqual(new float[] { 1 }, raw.ReadFloatArray()); + Assert.AreEqual(1, raw.ReadDouble()); + Assert.AreEqual(new double[] { 1 }, raw.ReadDoubleArray()); + Assert.AreEqual(1, raw.ReadDecimal()); + Assert.AreEqual(new decimal?[] { 1 }, raw.ReadDecimalArray()); + Assert.AreEqual(Date, raw.ReadTimestamp()); + Assert.AreEqual(new DateTime?[] { Date }, raw.ReadTimestampArray()); + Assert.AreEqual("1", raw.ReadString()); + Assert.AreEqual(new[] { "1" }, raw.ReadStringArray()); + Assert.AreEqual(Guid, raw.ReadGuid()); + Assert.AreEqual(new Guid?[] { Guid }, raw.ReadGuidArray()); + Assert.AreEqual(MyEnum.Bar, raw.ReadEnum()); + Assert.AreEqual(new[] { MyEnum.Bar }, raw.ReadEnumArray()); + } + } + + private enum MyEnum + { + Bar + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/IO/BinaryStreamsTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/IO/BinaryStreamsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/IO/BinaryStreamsTest.cs new file mode 100644 index 0000000..ad5358d --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/IO/BinaryStreamsTest.cs @@ -0,0 +1,151 @@ +/* + * 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.Binary.IO +{ + using System; + using System.IO; + using System.Text; + using Apache.Ignite.Core.Impl.Binary.IO; + using Apache.Ignite.Core.Impl.Memory; + using NUnit.Framework; + + /// + /// Tests binary streams. + /// + public class BinaryStreamsTest + { + /// + /// Tests the platform memory stream. + /// + [Test] + public void TestPlatformMemoryStream() + { + var stream = new PlatformMemoryStream(GetMemory()); + TestStream(stream, false, () => stream.SynchronizeOutput()); + } + + /// + /// Tests the platform big endian memory stream. + /// + [Test] + public void TestPlatformBigEndianMemoryStream() + { + var stream = new PlatformBigEndianMemoryStream(GetMemory()); + TestStream(stream, false, () => stream.SynchronizeOutput()); + } + + /// + /// Tests the binary heap stream. + /// + [Test] + public void TestBinaryHeapStream() + { + TestStream(new BinaryHeapStream(1), true, () => { }); + } + + /// + /// Gets the memory. + /// + private static PlatformMemory GetMemory() + { + return new PlatformMemoryPool().Allocate(10); + } + + /// + /// Tests the stream. + /// + private static unsafe void TestStream(IBinaryStream stream, bool sameArr, Action flush) + { + Action seek = () => Assert.AreEqual(0, stream.Seek(0, SeekOrigin.Begin)); + + Action, object> check = (write, read, expectedResult) => + { + seek(); + write(); + flush(); + seek(); + Assert.AreEqual(expectedResult, read()); + }; + + // Arrays. + Assert.AreEqual(sameArr, stream.IsSameArray(stream.GetArray())); + Assert.IsFalse(stream.IsSameArray(new byte[1])); + Assert.IsFalse(stream.IsSameArray(stream.GetArrayCopy())); + + // byte* + byte* bytes = stackalloc byte[10]; + *bytes = 1; + *(bytes + 1) = 2; + + stream.Write(bytes, 2); + Assert.AreEqual(2, stream.Position); + flush(); + + seek(); + Assert.AreEqual(sameArr ? 256 : 2, stream.Remaining); + byte* bytes2 = stackalloc byte[2]; + stream.Read(bytes2, 2); + Assert.AreEqual(1, *bytes2); + Assert.AreEqual(2, *(bytes2 + 1)); + + // char* + seek(); + char* chars = stackalloc char[10]; + *chars = 'a'; + *(chars + 1) = 'b'; + + Assert.AreEqual(2, stream.WriteString(chars, 2, 2, Encoding.ASCII)); + flush(); + + seek(); + stream.Read(bytes2, 2); + Assert.AreEqual('a', *bytes2); + Assert.AreEqual('b', *(bytes2 + 1)); + + // Others. + check(() => stream.Write(new byte[] {3, 4, 5}, 1, 2), () => stream.ReadByteArray(2), new byte[] {4, 5}); + + check(() => stream.WriteBool(true), () => stream.ReadBool(), true); + check(() => stream.WriteBoolArray(new[] {true, false}), () => stream.ReadBoolArray(2), + new[] {true, false}); + + check(() => stream.WriteByte(4), () => stream.ReadByte(), 4); + check(() => stream.WriteByteArray(new byte[] {4, 5, 6}), () => stream.ReadByteArray(3), + new byte[] {4, 5, 6}); + + check(() => stream.WriteChar('x'), () => stream.ReadChar(), 'x'); + check(() => stream.WriteCharArray(new[] {'a', 'b'}), () => stream.ReadCharArray(2), new[] {'a', 'b'}); + + check(() => stream.WriteDouble(4), () => stream.ReadDouble(), 4d); + check(() => stream.WriteDoubleArray(new[] {4d}), () => stream.ReadDoubleArray(1), new[] {4d}); + + check(() => stream.WriteFloat(4), () => stream.ReadFloat(), 4f); + check(() => stream.WriteFloatArray(new[] {4f}), () => stream.ReadFloatArray(1), new[] {4f}); + + check(() => stream.WriteInt(4), () => stream.ReadInt(), 4); + check(() => stream.WriteInt(0, 4), () => stream.ReadInt(), 4); + check(() => stream.WriteIntArray(new[] {4}), () => stream.ReadIntArray(1), new[] {4}); + + check(() => stream.WriteLong(4), () => stream.ReadLong(), 4L); + check(() => stream.WriteLongArray(new[] {4L}), () => stream.ReadLongArray(1), new[] {4L}); + + check(() => stream.WriteShort(4), () => stream.ReadShort(), (short)4); + check(() => stream.WriteShortArray(new short[] {4}), () => stream.ReadShortArray(1), new short[] {4}); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityKeyTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityKeyTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityKeyTest.cs new file mode 100644 index 0000000..cf86273 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityKeyTest.cs @@ -0,0 +1,66 @@ +/* + * 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.Cache.Affinity +{ + using Apache.Ignite.Core.Cache.Affinity; + using NUnit.Framework; + + /// + /// Tests for + /// + public class AffinityKeyTest + { + /// + /// Tests the equality. + /// + [Test] + public void TestEquality() + { + // Default. + var key = new AffinityKey(); + + Assert.IsNull(key.Key); + Assert.IsNull(key.Affinity); + Assert.AreEqual(0, key.GetHashCode()); + Assert.AreEqual(new AffinityKey(), key); + + // Ctor 1. + const string myKey = "myKey"; + key = new AffinityKey(myKey); + + Assert.AreEqual(myKey, key.Key); + Assert.AreEqual(myKey, key.Affinity); + Assert.AreNotEqual(0, key.GetHashCode()); + + // Ctor 2. + var ver1 = new AffinityKey(long.MaxValue, int.MaxValue); + var ver2 = new AffinityKey(long.MaxValue, int.MaxValue); + + Assert.AreEqual(ver1, ver2); + Assert.IsTrue(ver1 == ver2); + Assert.IsFalse(ver1 != ver2); + + Assert.AreNotEqual(key, ver1); + Assert.IsTrue(key != ver1); + Assert.IsFalse(key == ver1); + + // ToString. + Assert.AreEqual("AffinityKey [Key=1, Affinity=2]", new AffinityKey(1, 2).ToString()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTopologyVersionTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTopologyVersionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTopologyVersionTest.cs new file mode 100644 index 0000000..de25ea4 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityTopologyVersionTest.cs @@ -0,0 +1,59 @@ +/* + * 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.Cache.Affinity +{ + using Apache.Ignite.Core.Cache.Affinity; + using NUnit.Framework; + + /// + /// Tests for + /// + public class AffinityTopologyVersionTest + { + /// + /// Tests the equality. + /// + [Test] + public void TestEquality() + { + // Default. + var ver = new AffinityTopologyVersion(); + + Assert.AreEqual(0, ver.Version); + Assert.AreEqual(0, ver.MinorVersion); + Assert.AreEqual(0, ver.GetHashCode()); + Assert.AreEqual(new AffinityTopologyVersion(), ver); + + // Custom. + var ver1 = new AffinityTopologyVersion(long.MaxValue, int.MaxValue); + var ver2 = new AffinityTopologyVersion(long.MaxValue, int.MaxValue); + + Assert.AreEqual(ver1, ver2); + Assert.IsTrue(ver1 == ver2); + Assert.IsFalse(ver1 != ver2); + + Assert.AreNotEqual(ver, ver1); + Assert.IsTrue(ver != ver1); + Assert.IsFalse(ver == ver1); + + // ToString. + Assert.AreEqual("AffinityTopologyVersion [Version=1, MinorVersion=2]", + new AffinityTopologyVersion(1, 2).ToString()); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs index 62dc2df..5fb2cdd 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs @@ -29,7 +29,6 @@ namespace Apache.Ignite.Core.Tests.Cache using Apache.Ignite.Core.Cache.Expiry; using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Common; - using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.Impl.Cache; using Apache.Ignite.Core.Tests.Query; using Apache.Ignite.Core.Transactions; @@ -991,10 +990,8 @@ namespace Apache.Ignite.Core.Tests.Cache key1 = PrimaryKeyForCache(Cache(1)); } - var cache = cache0.WithExpiryPolicy(new ExpiryPolicy(null, null, null)); - // Test zero expiration. - cache = cache0.WithExpiryPolicy(new ExpiryPolicy(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero)); + var cache = cache0.WithExpiryPolicy(new ExpiryPolicy(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero)); cache.Put(key0, key0); cache.Put(key1, key1); @@ -1889,6 +1886,50 @@ namespace Apache.Ignite.Core.Tests.Cache }, threads); } + /// + /// Simple cache lock test (while is ignored). + /// + [Test] + public void TestLockSimple() + { + if (!LockingEnabled()) + return; + + var cache = Cache(); + + const int key = 7; + + Action checkLock = lck => + { + using (lck) + { + Assert.Throws(lck.Exit); // can't exit if not entered + + lck.Enter(); + + Assert.IsTrue(cache.IsLocalLocked(key, true)); + Assert.IsTrue(cache.IsLocalLocked(key, false)); + + lck.Exit(); + + Assert.IsFalse(cache.IsLocalLocked(key, true)); + Assert.IsFalse(cache.IsLocalLocked(key, false)); + + Assert.IsTrue(lck.TryEnter()); + + Assert.IsTrue(cache.IsLocalLocked(key, true)); + Assert.IsTrue(cache.IsLocalLocked(key, false)); + + lck.Exit(); + } + + Assert.Throws(lck.Enter); // Can't enter disposed lock + }; + + checkLock(cache.Lock(key)); + checkLock(cache.LockAll(new[] {key, 1, 2, 3})); + } + [Test] [Ignore("IGNITE-835")] public void TestLock() @@ -1994,7 +2035,7 @@ namespace Apache.Ignite.Core.Tests.Cache } /// - /// ENsure taht lock cannot be obtained by other threads. + /// Ensure that lock cannot be obtained by other threads. /// /// Get lock function. /// Shared lock. @@ -2375,10 +2416,15 @@ namespace Apache.Ignite.Core.Tests.Cache return; var tx = Transactions.TxStart(); - + Assert.AreEqual(TransactionState.Active, tx.State); + Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, tx.ThreadId); - tx.Rollback(); + tx.AddMeta("myMeta", 42); + Assert.AreEqual(42, tx.Meta("myMeta")); + Assert.AreEqual(42, tx.RemoveMeta("myMeta")); + + tx.RollbackAsync().Wait(); Assert.AreEqual(TransactionState.RolledBack, tx.State); @@ -3302,7 +3348,7 @@ namespace Apache.Ignite.Core.Tests.Cache return true; } - protected virtual bool LockingEnabled() + protected bool LockingEnabled() { return TxEnabled(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheResultTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheResultTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheResultTest.cs new file mode 100644 index 0000000..6be26bf --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheResultTest.cs @@ -0,0 +1,75 @@ +/* + * 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.Cache +{ + using System.Collections.Generic; + using Apache.Ignite.Core.Cache; + using NUnit.Framework; + + /// + /// tests. + /// + public class CacheResultTest + { + /// + /// Tests equality members. + /// + [Test] + public void TestEquality() + { + var entry1 = new CacheResult(2); + var entry2 = new CacheResult(2); + var entry3 = new CacheResult(3); + + Assert.AreEqual(entry1, entry2); + Assert.AreNotEqual(entry1, entry3); + + Assert.IsTrue(entry1 == entry2); + Assert.IsFalse(entry1 != entry2); + + Assert.IsTrue(entry1 != entry3); + Assert.IsFalse(entry1 == entry3); + + var boxedEntry1 = (object) entry1; + var boxedEntry2 = (object) entry2; + var boxedEntry3 = (object) entry3; + + Assert.IsFalse(ReferenceEquals(boxedEntry1, boxedEntry2)); + + Assert.AreEqual(boxedEntry1, boxedEntry2); + Assert.AreNotEqual(boxedEntry1, boxedEntry3); + } + + /// + /// Tests with hash data structures. + /// + [Test] + public void TestHashCode() + { + var entry1 = new CacheResult(2); + var entry2 = new CacheResult(2); + var entry3 = new CacheResult(3); + + var set = new HashSet {entry1}; + + Assert.IsTrue(set.Contains(entry1)); + Assert.IsTrue(set.Contains(entry2)); + Assert.IsFalse(set.Contains(entry3)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs index 4b285f9..270c3fc 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryAbstractTest.cs @@ -181,11 +181,11 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous { // Put from local node. cache1.GetAndPut(key1, Entry(key1)); - CheckCallbackSingle(key1, null, Entry(key1)); + CheckCallbackSingle(key1, null, Entry(key1), CacheEntryEventType.Created); // Put from remote node. cache2.GetAndPut(key2, Entry(key2)); - CheckCallbackSingle(key2, null, Entry(key2)); + CheckCallbackSingle(key2, null, Entry(key2), CacheEntryEventType.Created); } qryHnd.Dispose(); @@ -217,13 +217,13 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous { // Put from local node. cache1.GetAndPut(key1, Entry(key1)); - CheckCallbackSingle(key1, null, Entry(key1)); + CheckCallbackSingle(key1, null, Entry(key1), CacheEntryEventType.Created); cache1.GetAndPut(key1, Entry(key1 + 1)); - CheckCallbackSingle(key1, Entry(key1), Entry(key1 + 1)); + CheckCallbackSingle(key1, Entry(key1), Entry(key1 + 1), CacheEntryEventType.Updated); cache1.Remove(key1); - CheckCallbackSingle(key1, Entry(key1 + 1), null); + CheckCallbackSingle(key1, Entry(key1 + 1), null, CacheEntryEventType.Removed); // Put from remote node. cache2.GetAndPut(key2, Entry(key2)); @@ -231,21 +231,21 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous if (loc) CheckNoCallback(100); else - CheckCallbackSingle(key2, null, Entry(key2)); + CheckCallbackSingle(key2, null, Entry(key2), CacheEntryEventType.Created); cache1.GetAndPut(key2, Entry(key2 + 1)); if (loc) CheckNoCallback(100); else - CheckCallbackSingle(key2, Entry(key2), Entry(key2 + 1)); + CheckCallbackSingle(key2, Entry(key2), Entry(key2 + 1), CacheEntryEventType.Updated); cache1.Remove(key2); if (loc) CheckNoCallback(100); else - CheckCallbackSingle(key2, Entry(key2 + 1), null); + CheckCallbackSingle(key2, Entry(key2 + 1), null, CacheEntryEventType.Removed); } cache1.Put(key1, Entry(key1)); @@ -310,7 +310,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous int key1 = PrimaryKey(cache1); cache1.GetAndPut(key1, Entry(key1)); CheckFilterSingle(key1, null, Entry(key1)); - CheckCallbackSingle(key1, null, Entry(key1)); + CheckCallbackSingle(key1, null, Entry(key1), CacheEntryEventType.Created); // Put from remote node. int key2 = PrimaryKey(cache2); @@ -324,7 +324,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous else { CheckFilterSingle(key2, null, Entry(key2)); - CheckCallbackSingle(key2, null, Entry(key2)); + CheckCallbackSingle(key2, null, Entry(key2), CacheEntryEventType.Created); } AbstractFilter.res = false; @@ -755,12 +755,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous { // Put from local node. cache1.GetAndPut(key1, Entry(key1)); - CheckCallbackSingle(key1, null, Entry(key1)); + CheckCallbackSingle(key1, null, Entry(key1), CacheEntryEventType.Created); // Put from remote node. cache1.GetAndPut(key2, Entry(key2)); CheckNoCallback(100); - CheckCallbackSingle(key2, null, Entry(key2), 1000); + CheckCallbackSingle(key2, null, Entry(key2), CacheEntryEventType.Created); } } @@ -851,7 +851,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous // Check continuous query cache1.Put(44, Entry(44)); - CheckCallbackSingle(44, null, Entry(44)); + CheckCallbackSingle(44, null, Entry(44), CacheEntryEventType.Created); } Assert.Throws(() => contQry.GetInitialQueryCursor()); @@ -922,19 +922,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous /// Expected key. /// Expected old value. /// Expected new value. - private static void CheckCallbackSingle(int expKey, BinarizableEntry expOldVal, BinarizableEntry expVal) - { - CheckCallbackSingle(expKey, expOldVal, expVal, 1000); - } - - /// - /// Check single callback event. - /// - /// Expected key. - /// Expected old value. - /// Expected new value. + /// Expected type. /// Timeout. - private static void CheckCallbackSingle(int expKey, BinarizableEntry expOldVal, BinarizableEntry expVal, int timeout) + private static void CheckCallbackSingle(int expKey, BinarizableEntry expOldVal, BinarizableEntry expVal, + CacheEntryEventType expType, int timeout = 1000) { CallbackEvent evt; @@ -946,6 +937,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous Assert.AreEqual(expKey, e.Key); Assert.AreEqual(expOldVal, e.OldValue); Assert.AreEqual(expVal, e.Value); + Assert.AreEqual(expType, e.EventType); } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs index 4aa910c..105dea2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheParallelLoadStoreTest.cs @@ -96,7 +96,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store } // check that items were processed in parallel - Assert.GreaterOrEqual(CacheTestParallelLoadStore.UniqueThreadCount, Environment.ProcessorCount); + Assert.GreaterOrEqual(CacheTestParallelLoadStore.UniqueThreadCount, Environment.ProcessorCount - 1); } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreAdapterTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreAdapterTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreAdapterTest.cs new file mode 100644 index 0000000..6690584 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreAdapterTest.cs @@ -0,0 +1,90 @@ +/* + * 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.Cache.Store +{ + using System.Collections.Generic; + using System.Linq; + using Apache.Ignite.Core.Cache.Store; + using NUnit.Framework; + + /// + /// Tests for . + /// + public class CacheStoreAdapterTest + { + /// + /// Tests the load write delete. + /// + [Test] + public void TestLoadWriteDelete() + { + var store = new Store(); + + store.LoadCache(null); + Assert.IsEmpty(store.Map); + + var data = Enumerable.Range(1, 5).ToDictionary(x => x, x => x.ToString()); + + // Write. + store.WriteAll(data); + Assert.AreEqual(data, store.Map); + + // Load. + CollectionAssert.AreEqual(data, store.LoadAll(data.Keys)); + CollectionAssert.AreEqual(data.Where(x => x.Key < 3).ToDictionary(x => x.Key, x => x.Value), + store.LoadAll(data.Keys.Where(x => x < 3).ToList())); + + // Delete. + var removed = new[] {3, 5}; + + foreach (var key in removed) + data.Remove(key); + + store.DeleteAll(removed); + CollectionAssert.AreEqual(data, store.LoadAll(data.Keys)); + } + + /// + /// Test store. + /// + private class Store : CacheStoreAdapter + { + /** */ + public readonly Dictionary Map = new Dictionary(); + + /** */ + public override object Load(object key) + { + object res; + return Map.TryGetValue(key, out res) ? res : null; + } + + /** */ + public override void Write(object key, object val) + { + Map[key] = val; + } + + /** */ + public override void Delete(object key) + { + Map.Remove(key); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestParallelLoadStore.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestParallelLoadStore.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestParallelLoadStore.cs index 770ca83..81b4697 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestParallelLoadStore.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheTestParallelLoadStore.cs @@ -17,6 +17,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store { + using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; @@ -36,6 +37,14 @@ namespace Apache.Ignite.Core.Tests.Cache.Store private static readonly ConcurrentDictionary ThreadIds = new ConcurrentDictionary(); /// + /// Initializes a new instance of the class. + /// + public CacheTestParallelLoadStore() + { + MaxDegreeOfParallelism -= 1; + } + + /// /// Gets the count of unique threads that entered Parse method. /// public static int UniqueThreadCount http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/MultiValueDictionaryTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/MultiValueDictionaryTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/MultiValueDictionaryTest.cs new file mode 100644 index 0000000..aa3e2aa --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/MultiValueDictionaryTest.cs @@ -0,0 +1,58 @@ +/* + * 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.Collections +{ + using Apache.Ignite.Core.Impl.Collections; + using NUnit.Framework; + + /// + /// Tests the . + /// + public class MultiValueDictionaryTest + { + /// + /// Tests the dictionary. + /// + [Test] + public void TestMultiValueDictionary() + { + var dict = new MultiValueDictionary(); + + dict.Add(1, 1); + dict.Add(1, 2); + + int val; + + Assert.IsTrue(dict.TryRemove(1, out val)); + Assert.AreEqual(2, val); + + Assert.IsTrue(dict.TryRemove(1, out val)); + Assert.AreEqual(1, val); + + Assert.IsFalse(dict.TryRemove(1, out val)); + + dict.Add(2, 1); + dict.Add(2, 2); + dict.Remove(2, 3); + dict.Remove(2, 2); + + Assert.IsTrue(dict.TryRemove(2, out val)); + Assert.AreEqual(1, val); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyCollectionTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyCollectionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyCollectionTest.cs new file mode 100644 index 0000000..27991a3 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyCollectionTest.cs @@ -0,0 +1,59 @@ +/* + * 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.Collections +{ + using System; + using System.Collections; + using System.Linq; + using Apache.Ignite.Core.Impl.Collections; + using NUnit.Framework; + + /// + /// Tests for + /// + public class ReadOnlyCollectionTest + { + /// + /// Tests the disctionary. + /// + [Test] + public void TestCollection() + { + // Default ctor. + var data = Enumerable.Range(1, 5).ToArray(); + var col = new ReadOnlyCollection(data); + + Assert.AreEqual(5, col.Count); + Assert.IsTrue(col.IsReadOnly); + CollectionAssert.AreEqual(data, col); + + Assert.IsTrue(col.GetEnumerator().MoveNext()); + Assert.IsTrue(((IEnumerable) col).GetEnumerator().MoveNext()); + + Assert.IsTrue(col.Contains(4)); + + var arr = new int[5]; + col.CopyTo(arr, 0); + CollectionAssert.AreEqual(data, arr); + + Assert.Throws(() => col.Add(1)); + Assert.Throws(() => col.Clear()); + Assert.Throws(() => col.Remove(1)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyDictionaryTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyDictionaryTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyDictionaryTest.cs new file mode 100644 index 0000000..294251a --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Collections/ReadOnlyDictionaryTest.cs @@ -0,0 +1,70 @@ +/* + * 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.Collections +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + using Apache.Ignite.Core.Impl.Collections; + using NUnit.Framework; + + /// + /// Tests for + /// + public class ReadOnlyDictionaryTest + { + /// + /// Tests the disctionary. + /// + [Test] + public void TestDictionary() + { + // Default ctor. + var data = Enumerable.Range(1, 5).ToDictionary(x => x, x => x.ToString()); + var dict = new ReadOnlyDictionary(data); + + Assert.AreEqual(5, dict.Count); + Assert.IsTrue(dict.IsReadOnly); + CollectionAssert.AreEqual(data, dict); + CollectionAssert.AreEqual(data.Keys, dict.Keys); + CollectionAssert.AreEqual(data.Values, dict.Values); + + Assert.IsTrue(dict.GetEnumerator().MoveNext()); + Assert.IsTrue(((IEnumerable) dict).GetEnumerator().MoveNext()); + + Assert.IsTrue(dict.ContainsKey(1)); + Assert.IsTrue(dict.Contains(new KeyValuePair(4, "4"))); + Assert.AreEqual("3", dict[3]); + + string val; + Assert.IsTrue(dict.TryGetValue(2, out val)); + Assert.AreEqual("2", val); + + var arr = new KeyValuePair[5]; + dict.CopyTo(arr, 0); + CollectionAssert.AreEqual(data, arr); + + Assert.Throws(() => dict.Add(1, "2")); + Assert.Throws(() => dict.Add(new KeyValuePair(1, "2"))); + Assert.Throws(() => dict.Clear()); + Assert.Throws(() => dict.Remove(1)); + Assert.Throws(() => dict.Remove(new KeyValuePair(1, "2"))); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Common/IgniteGuidTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Common/IgniteGuidTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Common/IgniteGuidTest.cs new file mode 100644 index 0000000..705faf4 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Common/IgniteGuidTest.cs @@ -0,0 +1,62 @@ +/* + * 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.Common +{ + using System; + using Apache.Ignite.Core.Common; + using NUnit.Framework; + + /// + /// Tests the . + /// + public class IgniteGuidTest + { + /// + /// Tests the . + /// + [Test] + public void TestIgniteGuid() + { + var guid = Guid.NewGuid(); + + var id1 = new IgniteGuid(guid, 1); + var id2 = new IgniteGuid(guid, 1); + var id3 = new IgniteGuid(guid, 2); + var id4 = new IgniteGuid(Guid.NewGuid(), 2); + + // Properties. + Assert.AreEqual(guid, id1.GlobalId); + Assert.AreEqual(1, id1.LocalId); + Assert.AreEqual(id1.GetHashCode(), id2.GetHashCode()); + + // Equality. + Assert.AreEqual(id1, id2); + Assert.IsTrue(id1 == id2); + Assert.IsFalse(id1 != id2); + + // Inequality. + Assert.AreNotEqual(id1, id3); + Assert.IsFalse(id1 == id3); + Assert.IsTrue(id1 != id3); + + Assert.AreNotEqual(id4, id3); + Assert.IsFalse(id4 == id3); + Assert.IsTrue(id4 != id3); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/AbstractTaskTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/AbstractTaskTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/AbstractTaskTest.cs index d31ad43..6bcd010 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/AbstractTaskTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/AbstractTaskTest.cs @@ -162,30 +162,21 @@ namespace Apache.Ignite.Core.Tests.Compute /// /// Path to Java XML configuration. /// Node configuration. - protected IgniteConfiguration Configuration(string path) + private IgniteConfiguration Configuration(string path) { - IgniteConfiguration cfg = new IgniteConfiguration(); - - if (!_fork) + return new IgniteConfiguration { - BinaryConfiguration portCfg = new BinaryConfiguration(); - - ICollection portTypeCfgs = new List(); - - GetBinaryTypeConfigurations(portTypeCfgs); - - portCfg.TypeConfigurations = portTypeCfgs; - - cfg.BinaryConfiguration = portCfg; - } - - cfg.JvmClasspath = TestUtils.CreateTestClasspath(); - - cfg.JvmOptions = TestUtils.TestJavaOptions(); - - cfg.SpringConfigUrl = path; - - return cfg; + JvmClasspath = TestUtils.CreateTestClasspath(), + JvmOptions = TestUtils.TestJavaOptions(), + SpringConfigUrl = path, + BinaryConfiguration = _fork + ? null + : new BinaryConfiguration + { + TypeConfigurations = + (GetBinaryTypes() ?? new Type[0]).Select(t => new BinaryTypeConfiguration(t)).ToList() + } + }; } /// @@ -209,10 +200,9 @@ namespace Apache.Ignite.Core.Tests.Compute /// /// Define binary types. /// - /// Binary type configurations. - protected virtual void GetBinaryTypeConfigurations(ICollection portTypeCfgs) + protected virtual ICollection GetBinaryTypes() { - // No-op. + return null; } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableClosureTaskTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableClosureTaskTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableClosureTaskTest.cs index b881582..c169f1e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableClosureTaskTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableClosureTaskTest.cs @@ -40,12 +40,15 @@ namespace Apache.Ignite.Core.Tests.Compute protected BinarizableClosureTaskTest(bool fork) : base(fork) { } /** */ - protected override void GetBinaryTypeConfigurations(ICollection portTypeCfgs) + protected override ICollection GetBinaryTypes() { - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableOutFunc))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableFunc))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableResult))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableException))); + return new [] + { + typeof(BinarizableOutFunc), + typeof(BinarizableFunc), + typeof(BinarizableResult), + typeof(BinarizableException) + }; } /** */ @@ -76,6 +79,11 @@ namespace Apache.Ignite.Core.Tests.Compute { Assert.IsTrue(err != null); + var aggregate = err as AggregateException; + + if (aggregate != null) + err = aggregate.InnerException; + BinarizableException err0 = err as BinarizableException; Assert.IsTrue(err0 != null); http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableTaskTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableTaskTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableTaskTest.cs index 8aa28de..6bdfd9c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableTaskTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/BinarizableTaskTest.cs @@ -17,6 +17,7 @@ namespace Apache.Ignite.Core.Tests.Compute { + using System; using System.Collections.Generic; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cluster; @@ -71,14 +72,17 @@ namespace Apache.Ignite.Core.Tests.Compute } /** */ - override protected void GetBinaryTypeConfigurations(ICollection portTypeCfgs) + protected override ICollection GetBinaryTypes() { - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableJobArgument))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableJobResult))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableTaskArgument))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableTaskResult))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableJob))); - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(BinarizableWrapper))); + return new[] + { + typeof(BinarizableJobResult), + typeof(BinarizableTaskArgument), + typeof(BinarizableTaskResult), + typeof(BinarizableJobArgument), + typeof(BinarizableJob), + typeof(BinarizableWrapper) + }; } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs index bbd1169..19bb40d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs @@ -68,11 +68,21 @@ namespace Apache.Ignite.Core.Tests.Compute public void TestClosures() { TestClosure((c, t) => c.BroadcastAsync(new ComputeAction(), t)); + TestClosure((c, t) => c.BroadcastAsync(new ComputeFunc(), t)); + TestClosure((c, t) => c.BroadcastAsync(new ComputeBiFunc(), 10, t)); + TestClosure((c, t) => c.AffinityRunAsync(null, 0, new ComputeAction(), t)); + TestClosure((c, t) => c.RunAsync(new ComputeAction(), t)); TestClosure((c, t) => c.RunAsync(Enumerable.Range(1, 10).Select(x => new ComputeAction()), t)); + TestClosure((c, t) => c.CallAsync(new ComputeFunc(), t)); + TestClosure((c, t) => c.CallAsync(Enumerable.Range(1, 10).Select(x => new ComputeFunc()), t)); + TestClosure((c, t) => c.CallAsync(Enumerable.Range(1, 10).Select(x => new ComputeFunc()), + new ComputeReducer(), t)); + TestClosure((c, t) => c.AffinityCallAsync(null, 0, new ComputeFunc(), t)); + TestClosure((c, t) => c.ApplyAsync(new ComputeBiFunc(), 10, t)); TestClosure((c, t) => c.ApplyAsync(new ComputeBiFunc(), Enumerable.Range(1, 100), t)); TestClosure((c, t) => c.ApplyAsync(new ComputeBiFunc(), Enumerable.Range(1, 100), new ComputeReducer(), t)); http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ClosureTaskTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ClosureTaskTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ClosureTaskTest.cs index 8664413..ffb2844 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ClosureTaskTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ClosureTaskTest.cs @@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Tests.Compute { using System; using System.Collections.Generic; + using System.Linq; using Apache.Ignite.Core.Compute; using NUnit.Framework; @@ -27,7 +28,7 @@ namespace Apache.Ignite.Core.Tests.Compute /// public abstract class ClosureTaskTest : AbstractTaskTest { - /** Amount of multiple clousres. */ + /** Amount of multiple closures. */ private const int MultiCloCnt = 5; /** */ @@ -45,9 +46,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestExecuteSingle() { - var res = Grid1.GetCompute().Call(OutFunc(false)); - - CheckResult(res); + CheckResult(Grid1.GetCompute().Call(OutFunc(false))); + CheckResult(Grid1.GetCompute().CallAsync(OutFunc(false)).Result); } /// @@ -56,16 +56,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestExecuteSingleException() { - try - { - Grid1.GetCompute().Call(OutFunc(true)); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Call(OutFunc(true)))); + CheckError(Assert.Catch(() => Grid1.GetCompute().CallAsync(OutFunc(true)).Wait())); } /// @@ -74,15 +66,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestExecuteMultiple() { - var clos = new List>(MultiCloCnt); - - for (int i = 0; i < MultiCloCnt; i++) - clos.Add(OutFunc(false)); - - ICollection ress = Grid1.GetCompute().Call(clos); + var clos = Enumerable.Range(0, MultiCloCnt).Select(x => OutFunc(false)).ToArray(); - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Call(clos).ToList().ForEach(CheckResult); + Grid1.GetCompute().CallAsync(clos).Result.ToList().ForEach(CheckResult); } /// @@ -91,15 +78,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestExecuteMultipleReduced() { - var clos = new List>(MultiCloCnt); + var clos = Enumerable.Range(0, MultiCloCnt).Select(x => OutFunc(false)).ToArray(); - for (int i = 0; i < MultiCloCnt; i++) - clos.Add(OutFunc(false)); - - ICollection ress = Grid1.GetCompute().Call(clos, new Reducer(false)); - - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Call(clos, new Reducer(false)).ToList().ForEach(CheckResult); + Grid1.GetCompute().CallAsync(clos, new Reducer(false)).Result.ToList().ForEach(CheckResult); } /// @@ -108,21 +90,11 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestExecuteMultipleException() { - var clos = new List>(MultiCloCnt); + // Some closures will be faulty. + var clos = Enumerable.Range(0, MultiCloCnt).Select(x => OutFunc(x % 2 == 0)).ToArray(); - for (int i = 0; i < MultiCloCnt; i++) - clos.Add(OutFunc(i % 2 == 0)); // Some closures will be faulty. - - try - { - Grid1.GetCompute().Call(clos); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Call(clos))); + CheckError(Assert.Catch(() => Grid1.GetCompute().CallAsync(clos).Wait())); } /// @@ -131,10 +103,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestBroadcastOut() { - ICollection ress = Grid1.GetCompute().Broadcast(OutFunc(false)); - - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Broadcast(OutFunc(false)).ToList().ForEach(CheckResult); + Grid1.GetCompute().BroadcastAsync(OutFunc(false)).Result.ToList().ForEach(CheckResult); } /// @@ -143,16 +113,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestBroadcastOutException() { - try - { - Grid1.GetCompute().Broadcast(OutFunc(true)); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Broadcast(OutFunc(true)))); + CheckError(Assert.Catch(() => Grid1.GetCompute().BroadcastAsync(OutFunc(true)).Wait())); } /// @@ -161,10 +123,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestBroadcastInOut() { - ICollection ress = Grid1.GetCompute().Broadcast(Func(false), 1); - - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Broadcast(Func(false), 1).ToList().ForEach(CheckResult); + Grid1.GetCompute().BroadcastAsync(Func(false), 1).Result.ToList().ForEach(CheckResult); } /// @@ -173,16 +133,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestBroadcastInOutException() { - try - { - Grid1.GetCompute().Broadcast(Func(true), 1); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Broadcast(Func(true), 1))); + CheckError(Assert.Catch(() => Grid1.GetCompute().BroadcastAsync(Func(true), 1).Wait())); } /// @@ -191,9 +143,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestApply() { - object res = Grid1.GetCompute().Apply(Func(false), 1); - - CheckResult(res); + CheckResult(Grid1.GetCompute().Apply(Func(false), 1)); + CheckResult(Grid1.GetCompute().ApplyAsync(Func(false), 1).Result); } /// @@ -202,16 +153,8 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestApplyException() { - try - { - Grid1.GetCompute().Apply(Func(true), 1); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Apply(Func(true), 1))); + CheckError(Assert.Catch(() => Grid1.GetCompute().ApplyAsync(Func(true), 1).Wait())); } /// @@ -220,19 +163,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestApplyMultiple() { - var args = new List(MultiCloCnt); - - for (int i = 0; i < MultiCloCnt; i++) - args.Add(1); - - Console.WriteLine("START TASK"); - - var ress = Grid1.GetCompute().Apply(Func(false), args); + var args = Enumerable.Repeat(1, MultiCloCnt).Cast().ToArray(); - Console.WriteLine("END TASK."); - - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Apply(Func(false), args).ToList().ForEach(CheckResult); + Grid1.GetCompute().ApplyAsync(Func(false), args).Result.ToList().ForEach(CheckResult); } /// @@ -241,21 +175,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestApplyMultipleException() { - ICollection args = new List(MultiCloCnt); - - for (int i = 0; i < MultiCloCnt; i++) - args.Add(1); - - try - { - Grid1.GetCompute().Apply(Func(true), args); + var args = Enumerable.Repeat(1, MultiCloCnt).Cast().ToArray(); - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Apply(Func(true), args))); + CheckError(Assert.Catch(() => Grid1.GetCompute().ApplyAsync(Func(true), args).Wait())); } /// @@ -264,16 +187,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestApplyMultipleReducer() { - var args = new List(MultiCloCnt); + var args = Enumerable.Repeat(1, MultiCloCnt).Cast().ToArray(); - for (int i = 0; i < MultiCloCnt; i++) - args.Add(1); - - ICollection ress = - Grid1.GetCompute().Apply(Func(false), args, new Reducer(false)); - - foreach (object res in ress) - CheckResult(res); + Grid1.GetCompute().Apply(Func(false), args, new Reducer(false)).ToList().ForEach(CheckResult); + Grid1.GetCompute().ApplyAsync(Func(false), args, new Reducer(false)).Result.ToList().ForEach(CheckResult); } /// @@ -282,21 +199,10 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestAppylMultipleReducerJobException() { - List args = new List(MultiCloCnt); + var args = Enumerable.Repeat(1, MultiCloCnt).Cast().ToArray(); - for (int i = 0; i < MultiCloCnt; i++) - args.Add(1); - - try - { - Grid1.GetCompute().Apply(Func(true), args, new Reducer(false)); - - Assert.Fail(); - } - catch (Exception e) - { - CheckError(e); - } + CheckError(Assert.Catch(() => Grid1.GetCompute().Apply(Func(true), args, new Reducer(false)))); + CheckError(Assert.Catch(() => Grid1.GetCompute().ApplyAsync(Func(true), args, new Reducer(false)).Wait())); } /// @@ -305,23 +211,11 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestAppylMultipleReducerReduceException() { - var args = new List(MultiCloCnt); - - for (int i = 0; i < MultiCloCnt; i++) - args.Add(1); + var args = Enumerable.Repeat(1, MultiCloCnt).Cast().ToArray(); - try - { - Grid1.GetCompute().Apply(Func(false), args, new Reducer(true)); + var e = Assert.Throws(() => Grid1.GetCompute().Apply(Func(false), args, new Reducer(true))); - Assert.Fail(); - } - catch (Exception e) - { - Assert.AreEqual(typeof(Exception), e.GetType()); - - Assert.AreEqual(ErrMsg, e.Message); - } + Assert.AreEqual(ErrMsg, e.Message); } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs index bc26e4c..5a29167 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTest.cs @@ -187,7 +187,10 @@ namespace Apache.Ignite.Core.Tests.Compute Assert.NotNull(prj); - Assert.IsTrue(prj == prj.Ignite); + Assert.AreEqual(prj, prj.Ignite); + + // Check that default Compute projection excludes client nodes. + CollectionAssert.AreEquivalent(prj.ForServers().GetNodes(), prj.GetCompute().ClusterGroup.GetNodes()); } /// @@ -965,9 +968,7 @@ namespace Apache.Ignite.Core.Tests.Compute compute.WithKeepBinary(); - PlatformComputeNetBinarizable arg = new PlatformComputeNetBinarizable(); - - arg.Field = 100; + PlatformComputeNetBinarizable arg = new PlatformComputeNetBinarizable {Field = 100}; int res = compute.ExecuteJavaTask(BinaryArgTask, arg); @@ -1010,9 +1011,11 @@ namespace Apache.Ignite.Core.Tests.Compute public void TestBroadcastAction() { var id = Guid.NewGuid(); - _grid1.GetCompute().Broadcast(new ComputeAction(id)); + Assert.AreEqual(2, ComputeAction.InvokeCount(id)); + id = Guid.NewGuid(); + _grid1.GetCompute().BroadcastAsync(new ComputeAction(id)).Wait(); Assert.AreEqual(2, ComputeAction.InvokeCount(id)); } @@ -1023,9 +1026,11 @@ namespace Apache.Ignite.Core.Tests.Compute public void TestRunAction() { var id = Guid.NewGuid(); - _grid1.GetCompute().Run(new ComputeAction(id)); + Assert.AreEqual(1, ComputeAction.InvokeCount(id)); + id = Guid.NewGuid(); + _grid1.GetCompute().RunAsync(new ComputeAction(id)).Wait(); Assert.AreEqual(1, ComputeAction.InvokeCount(id)); } @@ -1055,12 +1060,12 @@ namespace Apache.Ignite.Core.Tests.Compute public void TestRunActions() { var id = Guid.NewGuid(); - - var actions = Enumerable.Range(0, 10).Select(x => new ComputeAction(id)); - - _grid1.GetCompute().Run(actions); - + _grid1.GetCompute().Run(Enumerable.Range(0, 10).Select(x => new ComputeAction(id))); Assert.AreEqual(10, ComputeAction.InvokeCount(id)); + + var id2 = Guid.NewGuid(); + _grid1.GetCompute().RunAsync(Enumerable.Range(0, 10).Select(x => new ComputeAction(id2))).Wait(); + Assert.AreEqual(10, ComputeAction.InvokeCount(id2)); } /// @@ -1083,7 +1088,9 @@ namespace Apache.Ignite.Core.Tests.Compute var affinityKey = _grid1.GetAffinity(cacheName).GetAffinityKey(primaryKey); _grid1.GetCompute().AffinityRun(cacheName, affinityKey, new ComputeAction()); + Assert.AreEqual(node.Id, ComputeAction.LastNodeId); + _grid1.GetCompute().AffinityRunAsync(cacheName, affinityKey, new ComputeAction()).Wait(); Assert.AreEqual(node.Id, ComputeAction.LastNodeId); } } @@ -1112,6 +1119,15 @@ namespace Apache.Ignite.Core.Tests.Compute Assert.AreEqual(result, ComputeFunc.InvokeCount); Assert.AreEqual(node.Id, ComputeFunc.LastNodeId); + + // Async. + ComputeFunc.InvokeCount = 0; + + result = _grid1.GetCompute().AffinityCallAsync(cacheName, affinityKey, new ComputeFunc()).Result; + + Assert.AreEqual(result, ComputeFunc.InvokeCount); + + Assert.AreEqual(node.Id, ComputeFunc.LastNodeId); } } @@ -1149,10 +1165,18 @@ namespace Apache.Ignite.Core.Tests.Compute [Test] public void TestNetTaskSimple() { - int res = _grid1.GetCompute().Execute( - typeof(NetSimpleTask), new NetSimpleJobArgument(1)).Res; + Assert.AreEqual(2, _grid1.GetCompute() + .Execute( + typeof(NetSimpleTask), new NetSimpleJobArgument(1)).Res); + + Assert.AreEqual(2, _grid1.GetCompute() + .ExecuteAsync( + typeof(NetSimpleTask), new NetSimpleJobArgument(1)).Result.Res); - Assert.AreEqual(2, res); + Assert.AreEqual(4, _grid1.GetCompute().Execute(new NetSimpleTask(), new NetSimpleJobArgument(2)).Res); + + Assert.AreEqual(6, _grid1.GetCompute().ExecuteAsync(new NetSimpleTask(), new NetSimpleJobArgument(3)) + .Result.Res); } /// @@ -1381,6 +1405,7 @@ namespace Apache.Ignite.Core.Tests.Compute int IComputeFunc.Invoke() { + Thread.Sleep(10); InvokeCount++; LastNodeId = _grid.GetCluster().GetLocalNode().Id; return InvokeCount; http://git-wip-us.apache.org/repos/asf/ignite/blob/e4eda7cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/FailoverTaskSelfTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/FailoverTaskSelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/FailoverTaskSelfTest.cs index 45af888..1987245 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/FailoverTaskSelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/FailoverTaskSelfTest.cs @@ -19,7 +19,6 @@ namespace Apache.Ignite.Core.Tests.Compute { using System; using System.Collections.Generic; - using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Compute; using Apache.Ignite.Core.Resource; @@ -111,9 +110,9 @@ namespace Apache.Ignite.Core.Tests.Compute } /** */ - override protected void GetBinaryTypeConfigurations(ICollection portTypeCfgs) + protected override ICollection GetBinaryTypes() { - portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(TestBinarizableJob))); + return new[] {typeof(TestBinarizableJob)}; } ///