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 E38CE18C6C for ; Fri, 4 Sep 2015 16:27:16 +0000 (UTC) Received: (qmail 27604 invoked by uid 500); 4 Sep 2015 16:27:16 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 27534 invoked by uid 500); 4 Sep 2015 16:27:16 -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 26599 invoked by uid 99); 4 Sep 2015 16:27:16 -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, 04 Sep 2015 16:27:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0AD61E0216; Fri, 4 Sep 2015 16:27:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Fri, 04 Sep 2015 16:27:39 -0000 Message-Id: In-Reply-To: <32fe56bbbbab49f3a70cddb00c220582@git.apache.org> References: <32fe56bbbbab49f3a70cddb00c220582@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [25/55] [abbrv] ignite git commit: IGNITE-1348: Moved GridGain's .Net module to Ignite. http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAffinityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAffinityTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAffinityTest.cs new file mode 100644 index 0000000..beb2c0f --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAffinityTest.cs @@ -0,0 +1,139 @@ +/* + * 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 Apache.Ignite.Core.Cache; + using Apache.Ignite.Core.Cluster; + using Apache.Ignite.Core.Impl; + using Apache.Ignite.Core.Portable; + using NUnit.Framework; + + /// + /// Affinity key tests. + /// + public class CacheAffinityTest + { + /// + /// + /// + [TestFixtureSetUp] + public virtual void StartGrids() + { + TestUtils.KillProcesses(); + + IgniteConfigurationEx cfg = new IgniteConfigurationEx(); + + cfg.JvmClasspath = TestUtils.CreateTestClasspath(); + cfg.JvmOptions = TestUtils.TestJavaOptions(); + cfg.SpringConfigUrl = "config\\native-client-test-cache-affinity.xml"; + + for (int i = 0; i < 3; i++) + { + cfg.GridName = "grid-" + i; + + Ignition.Start(cfg); + } + } + + /// + /// Tear-down routine. + /// + [TestFixtureTearDown] + public virtual void StopGrids() + { + for (int i = 0; i < 3; i++) + Ignition.Stop("grid-" + i, true); + } + + /// + /// Test affinity key. + /// + [Test] + public void TestAffinity() + { + IIgnite g = Ignition.GetIgnite("grid-0"); + + ICacheAffinity aff = g.Affinity(null); + + IClusterNode node = aff.MapKeyToNode(new AffinityTestKey(0, 1)); + + for (int i = 0; i < 10; i++) + Assert.AreEqual(node.Id, aff.MapKeyToNode(new AffinityTestKey(i, 1)).Id); + } + + /// + /// Test affinity with portable flag. + /// + [Test] + public void TestAffinityPortable() + { + IIgnite g = Ignition.GetIgnite("grid-0"); + + ICacheAffinity aff = g.Affinity(null); + + IPortableObject affKey = g.Portables().ToPortable(new AffinityTestKey(0, 1)); + + IClusterNode node = aff.MapKeyToNode(affKey); + + for (int i = 0; i < 10; i++) + { + IPortableObject otherAffKey = + g.Portables().ToPortable(new AffinityTestKey(i, 1)); + + Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); + } + } + + /// + /// Affinity key. + /// + public class AffinityTestKey + { + /** ID. */ + private int _id; + + /** Affinity key. */ + private int _affKey; + + /// + /// Constructor. + /// + /// ID. + /// Affinity key. + public AffinityTestKey(int id, int affKey) + { + _id = id; + _affKey = affKey; + } + + /** */ + public override bool Equals(object obj) + { + AffinityTestKey other = obj as AffinityTestKey; + + return other != null && _id == other._id; + } + + /** */ + public override int GetHashCode() + { + return _id; + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheDynamicStartTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheDynamicStartTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheDynamicStartTest.cs new file mode 100644 index 0000000..210d80c --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheDynamicStartTest.cs @@ -0,0 +1,281 @@ +/* + * 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; + using System.Collections.Generic; + using Apache.Ignite.Core.Cache; + using Apache.Ignite.Core.Impl; + using Apache.Ignite.Core.Portable; + using Apache.Ignite.Core.Tests.Query; + using NUnit.Framework; + + /// + /// Tests for dynamic a cache start. + /// + public class CacheDynamicStartTest + { + /** Grid name: data. */ + private const string GridData = "d"; + + /** Grid name: data, no configuration. */ + private const string GridDataNoCfg = "dnc"; + + /** Grid name: client. */ + private const string GridClient = "c"; + + /** Cache name: partitioned, transactional. */ + private const string CacheTx = "p"; + + /** Cache name: atomic. */ + private const string CacheAtomic = "pa"; + + /** Cache name: dummy. */ + private const string CacheDummy = "dummy"; + + /// + /// Set up routine. + /// + [SetUp] + public void SetUp() + { + TestUtils.KillProcesses(); + + Ignition.Start(CreateConfiguration(GridData, @"config/dynamic/dynamic-data.xml")); + Ignition.Start(CreateConfiguration(GridDataNoCfg, @"config/dynamic/dynamic-data-no-cfg.xml")); + Ignition.Start(CreateConfiguration(GridClient, @"config/dynamic/dynamic-client.xml")); + } + + /// + /// Tear down routine. + /// + [TearDown] + public void StopGrids() + { + Ignition.Stop(GridData, true); + Ignition.Stop(GridDataNoCfg, true); + Ignition.Stop(GridClient, true); + } + + /// + /// Create configuration. + /// + /// Grid name. + /// Spring configuration. + /// Configuration. + private static IgniteConfigurationEx CreateConfiguration(string name, string springCfg) + { + IgniteConfigurationEx cfg = new IgniteConfigurationEx(); + + PortableConfiguration portCfg = new PortableConfiguration(); + + ICollection portTypeCfgs = new List(); + + portTypeCfgs.Add(new PortableTypeConfiguration(typeof(DynamicTestKey))); + portTypeCfgs.Add(new PortableTypeConfiguration(typeof(DynamicTestValue))); + + portCfg.TypeConfigurations = portTypeCfgs; + + cfg.GridName = name; + cfg.PortableConfiguration = portCfg; + cfg.JvmClasspath = TestUtils.CreateTestClasspath(); + cfg.JvmOptions = TestUtils.TestJavaOptions(); + cfg.SpringConfigUrl = springCfg; + + return cfg; + } + + /// + /// Try getting not configured cache. + /// + [Test] + public void TestNoStarted() + { + Assert.Throws(() => + { + Ignition.GetIgnite(GridData).Cache(CacheDummy); + }); + + Assert.Throws(() => + { + Ignition.GetIgnite(GridDataNoCfg).Cache(CacheDummy); + }); + + Assert.Throws(() => + { + Ignition.GetIgnite(GridClient).Cache(CacheDummy); + }); + } + + /// + /// Test TX cache. + /// + [Test] + public void TestTransactional() + { + Check(CacheTx); + } + + /// + /// Test ATOMIC cache. + /// + [Test] + public void TestAtomic() + { + Check(CacheAtomic); + } + + /// + /// Check routine. + /// + /// Cache name. + private void Check(string cacheName) + { + ICache cacheData = + Ignition.GetIgnite(GridData).Cache(cacheName); + + ICache cacheDataNoCfg = + Ignition.GetIgnite(GridDataNoCfg).Cache(cacheName); + + ICache cacheClient = + Ignition.GetIgnite(GridClient).Cache(cacheName); + + DynamicTestKey key1 = new DynamicTestKey(1); + DynamicTestKey key2 = new DynamicTestKey(2); + DynamicTestKey key3 = new DynamicTestKey(3); + + DynamicTestValue val1 = new DynamicTestValue(1); + DynamicTestValue val2 = new DynamicTestValue(2); + DynamicTestValue val3 = new DynamicTestValue(3); + + cacheData.Put(key1, val1); + Assert.AreEqual(val1, cacheData.Get(key1)); + Assert.AreEqual(val1, cacheDataNoCfg.Get(key1)); + Assert.AreEqual(val1, cacheClient.Get(key1)); + + cacheDataNoCfg.Put(key2, val2); + Assert.AreEqual(val2, cacheData.Get(key2)); + Assert.AreEqual(val2, cacheDataNoCfg.Get(key2)); + Assert.AreEqual(val2, cacheClient.Get(key2)); + + cacheClient.Put(key3, val3); + Assert.AreEqual(val3, cacheData.Get(key3)); + Assert.AreEqual(val3, cacheDataNoCfg.Get(key3)); + Assert.AreEqual(val3, cacheClient.Get(key3)); + + for (int i = 0; i < 10000; i++) + cacheClient.Put(new DynamicTestKey(i), new DynamicTestValue(1)); + + int sizeClient = cacheClient.LocalSize(); + + Assert.AreEqual(0, sizeClient); + } + } + + /// + /// Key for dynamic cache start tests. + /// + class DynamicTestKey + { + /// + /// Default constructor. + /// + public DynamicTestKey() + { + // No-op. + } + + /// + /// Constructor. + /// + /// ID. + public DynamicTestKey(int id) + { + Id = id; + } + + /// + /// ID. + /// + public int Id + { + get; + set; + } + + /** */ + public override bool Equals(object obj) + { + DynamicTestKey other = obj as DynamicTestKey; + + return other != null && Id == other.Id; + } + + /** */ + public override int GetHashCode() + { + return Id; + } + } + + /// + /// Value for dynamic cache start tests. + /// + class DynamicTestValue + { + /// + /// Default constructor. + /// + public DynamicTestValue() + { + // No-op. + } + + /// + /// Constructor. + /// + /// ID. + public DynamicTestValue(int id) + { + Id = id; + } + + /// + /// ID. + /// + public int Id + { + get; + set; + } + + /** */ + public override bool Equals(object obj) + { + DynamicTestValue other = obj as DynamicTestValue; + + return other != null && Id == other.Id; + } + + /** */ + public override int GetHashCode() + { + return Id; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheEntryTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheEntryTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheEntryTest.cs new file mode 100644 index 0000000..8464b8e --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheEntryTest.cs @@ -0,0 +1,69 @@ +/* + * 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.Impl.Cache; + using NUnit.Framework; + + /// + /// tests. + /// + public class CacheEntryTest + { + /// + /// Tests equality members. + /// + [Test] + public void TestEquality() + { + var entry1 = new CacheEntry(1, 2); + var entry2 = new CacheEntry(1, 2); + var entry3 = new CacheEntry(1, 3); + + Assert.AreEqual(entry1, entry2); + Assert.AreNotEqual(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 CacheEntry(1, 2); + var entry2 = new CacheEntry(1, 2); + var entry3 = new CacheEntry(1, 3); + + var set = new HashSet {entry1}; + + Assert.IsTrue(set.Contains(entry1)); + Assert.IsTrue(set.Contains(entry2)); + Assert.IsFalse(set.Contains(entry3)); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheForkedTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheForkedTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheForkedTest.cs new file mode 100644 index 0000000..04aff5f --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheForkedTest.cs @@ -0,0 +1,82 @@ +/* + * 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.IO; + using Apache.Ignite.Core.Tests.Process; + using NUnit.Framework; + + /// + /// Tests cache with a standalone process. + /// + [Ignore("IGNITE-1367")] + public class CacheForkedTest + { + /** */ + private IIgnite _grid; + + /// + /// Set up. + /// + [TestFixtureSetUp] + public void SetUp() + { + const string springConfigUrl = "config\\compute\\compute-grid1.xml"; + + // ReSharper disable once UnusedVariable + var proc = new IgniteProcess( + "-jvmClasspath=" + TestUtils.CreateTestClasspath(), + "-springConfigUrl=" + Path.GetFullPath(springConfigUrl), + "-J-ea", + "-J-Xcheck:jni", + "-J-Xms512m", + "-J-Xmx512m", + "-J-DIGNITE_QUIET=false" + ); + + _grid = Ignition.Start(new IgniteConfiguration + { + JvmClasspath = TestUtils.CreateTestClasspath(), + JvmOptions = TestUtils.TestJavaOptions(), + SpringConfigUrl = springConfigUrl + }); + + Assert.IsTrue(_grid.WaitTopology(2, 30000)); + } + + /// + /// Tear down. + /// + [TestFixtureTearDown] + public void TearDown() + { + IgniteProcess.KillAll(); + + Ignition.StopAll(true); + } + + /// + /// Tests cache clear. + /// + [Test] + public void TestClearCache() + { + _grid.Cache(null).Clear(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalAtomicTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalAtomicTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalAtomicTest.cs new file mode 100644 index 0000000..b60c254 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalAtomicTest.cs @@ -0,0 +1,57 @@ +/* + * 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 +{ + public class CacheLocalAtomicTest : CacheAbstractTest + { + protected override int CachePartitions() + { + return 1; + } + + protected override int GridCount() + { + return 1; + } + + protected override string CacheName() + { + return "local_atomic"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return false; + } + + protected override bool LocalCache() + { + return true; + } + + protected override int Backups() + { + return 0; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalTest.cs new file mode 100644 index 0000000..02cb987 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheLocalTest.cs @@ -0,0 +1,56 @@ +/* + * 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 +{ + public class CacheLocalTest : CacheAbstractTest + { + protected override int CachePartitions() + { + return 1; + } + + protected override int GridCount() + { + return 1; + } + + protected override string CacheName() + { + return "local"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return true; + } + protected override bool LocalCache() + { + return true; + } + + protected override int Backups() + { + return 0; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicNearEnabledTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicNearEnabledTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicNearEnabledTest.cs new file mode 100644 index 0000000..4f6e7a0 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicNearEnabledTest.cs @@ -0,0 +1,50 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CachePartitionedAtomicNearEnabledTest : CacheAbstractTest + { + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "partitioned_atomic_near"; + } + + protected override bool NearEnabled() + { + return true; + } + + protected override bool TxEnabled() + { + return false; + } + + protected override int Backups() + { + return 1; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicTest.cs new file mode 100644 index 0000000..ab59c64 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedAtomicTest.cs @@ -0,0 +1,50 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CachePartitionedAtomicTest : CacheAbstractTest + { + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "partitioned_atomic"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return false; + } + + protected override int Backups() + { + return 1; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedNearEnabledTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedNearEnabledTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedNearEnabledTest.cs new file mode 100644 index 0000000..830698b --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedNearEnabledTest.cs @@ -0,0 +1,50 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CachePartitionedNearEnabledTest : CacheAbstractTest + { + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "partitioned_near"; + } + + protected override bool NearEnabled() + { + return true; + } + + protected override bool TxEnabled() + { + return true; + } + + protected override int Backups() + { + return 1; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedTest.cs new file mode 100644 index 0000000..02d3208 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CachePartitionedTest.cs @@ -0,0 +1,50 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CachePartitionedTest : CacheAbstractTest + { + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "partitioned"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return true; + } + + protected override int Backups() + { + return 1; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedAtomicTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedAtomicTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedAtomicTest.cs new file mode 100644 index 0000000..db6f5a5 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedAtomicTest.cs @@ -0,0 +1,60 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CacheReplicatedAtomicTest : CacheAbstractTest + { + protected override int CachePartitions() + { + return 512; + } + + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "replicated_atomic"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return false; + } + + protected override int Backups() + { + return GridCount() - 1; + } + + protected override bool ReplicatedCache() + { + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedTest.cs new file mode 100644 index 0000000..7c70222 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheReplicatedTest.cs @@ -0,0 +1,60 @@ +/* + * 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 NUnit.Framework; + + [Category(TestUtils.CategoryIntensive)] + public class CacheReplicatedTest : CacheAbstractTest + { + protected override int CachePartitions() + { + return 512; + } + + protected override int GridCount() + { + return 3; + } + + protected override string CacheName() + { + return "replicated"; + } + + protected override bool NearEnabled() + { + return false; + } + + protected override bool TxEnabled() + { + return true; + } + + protected override int Backups() + { + return GridCount() - 1; + } + + protected override bool ReplicatedCache() + { + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs new file mode 100644 index 0000000..93f5973 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs @@ -0,0 +1,436 @@ +/* + * 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; + using System.Collections.Generic; + using System.Diagnostics; + using Apache.Ignite.Core.Cache; + using Apache.Ignite.Core.Cache.Expiry; + using Apache.Ignite.Core.Cache.Query; + using Apache.Ignite.Core.Cache.Query.Continuous; + using Apache.Ignite.Core.Common; + + /// + /// Wraps IGridCache implementation to simplify async mode testing. + /// + internal class CacheTestAsyncWrapper : ICache + { + private readonly ICache _cache; + + /// + /// Initializes a new instance of the class. + /// + /// The cache to be wrapped. + public CacheTestAsyncWrapper(ICache cache) + { + Debug.Assert(cache.IsAsync, "GridCacheTestAsyncWrapper only works with async caches."); + + _cache = cache; + } + + /** */ + public ICache WithAsync() + { + return this; + } + + /** */ + public bool IsAsync + { + get { return true; } + } + + /** */ + public IFuture GetFuture() + { + Debug.Fail("GridCacheTestAsyncWrapper.Future() should not be called. It always returns null."); + return null; + } + + /** */ + public IFuture GetFuture() + { + Debug.Fail("GridCacheTestAsyncWrapper.Future() should not be called. It always returns null."); + return null; + } + + /** */ + public string Name + { + get { return _cache.Name; } + } + + /** */ + public IIgnite Ignite + { + get { return _cache.Ignite; } + } + + /** */ + public bool IsEmpty + { + get { return _cache.IsEmpty; } + } + + /** */ + public bool KeepPortable + { + get { return _cache.KeepPortable; } + } + + /** */ + public ICache WithSkipStore() + { + return _cache.WithSkipStore().WrapAsync(); + } + + /** */ + public ICache WithExpiryPolicy(IExpiryPolicy plc) + { + return _cache.WithExpiryPolicy(plc).WrapAsync(); + } + + /** */ + public ICache WithKeepPortable() + { + return _cache.WithKeepPortable().WrapAsync(); + } + + /** */ + public void LoadCache(ICacheEntryFilter p, params object[] args) + { + _cache.LoadCache(p, args); + WaitResult(); + } + + /** */ + public void LocalLoadCache(ICacheEntryFilter p, params object[] args) + { + _cache.LocalLoadCache(p, args); + WaitResult(); + } + + /** */ + public bool ContainsKey(TK key) + { + _cache.ContainsKey(key); + return GetResult(); + } + + /** */ + public bool ContainsKeys(IEnumerable keys) + { + _cache.ContainsKeys(keys); + return GetResult(); + } + + /** */ + public TV LocalPeek(TK key, params CachePeekMode[] modes) + { + _cache.LocalPeek(key, modes); + return GetResult(); + } + + /** */ + public TV Get(TK key) + { + _cache.Get(key); + return GetResult(); + } + + /** */ + public IDictionary GetAll(IEnumerable keys) + { + _cache.GetAll(keys); + return GetResult>(); + } + + /** */ + public void Put(TK key, TV val) + { + _cache.Put(key, val); + WaitResult(); + } + + /** */ + public TV GetAndPut(TK key, TV val) + { + _cache.GetAndPut(key, val); + return GetResult(); + } + + /** */ + public TV GetAndReplace(TK key, TV val) + { + _cache.GetAndReplace(key, val); + return GetResult(); + } + + /** */ + public TV GetAndRemove(TK key) + { + _cache.GetAndRemove(key); + return GetResult(); + } + + /** */ + public bool PutIfAbsent(TK key, TV val) + { + _cache.PutIfAbsent(key, val); + return GetResult(); + } + + /** */ + public TV GetAndPutIfAbsent(TK key, TV val) + { + _cache.GetAndPutIfAbsent(key, val); + return GetResult(); + } + + /** */ + public bool Replace(TK key, TV val) + { + _cache.Replace(key, val); + return GetResult(); + } + + /** */ + public bool Replace(TK key, TV oldVal, TV newVal) + { + _cache.Replace(key, oldVal, newVal); + return GetResult(); + } + + /** */ + public void PutAll(IDictionary vals) + { + _cache.PutAll(vals); + WaitResult(); + } + + /** */ + public void LocalEvict(IEnumerable keys) + { + _cache.LocalEvict(keys); + } + + /** */ + public void Clear() + { + _cache.Clear(); + WaitResult(); + } + + /** */ + public void Clear(TK key) + { + _cache.Clear(key); + } + + /** */ + public void ClearAll(IEnumerable keys) + { + _cache.ClearAll(keys); + } + + /** */ + public void LocalClear(TK key) + { + _cache.LocalClear(key); + } + + /** */ + public void LocalClearAll(IEnumerable keys) + { + _cache.LocalClearAll(keys); + } + + /** */ + public bool Remove(TK key) + { + _cache.Remove(key); + return GetResult(); + } + + /** */ + public bool Remove(TK key, TV val) + { + _cache.Remove(key, val); + return GetResult(); + } + + /** */ + public void RemoveAll(IEnumerable keys) + { + _cache.RemoveAll(keys); + WaitResult(); + } + + /** */ + public void RemoveAll() + { + _cache.RemoveAll(); + WaitResult(); + } + + /** */ + public int LocalSize(params CachePeekMode[] modes) + { + return _cache.LocalSize(modes); + } + + /** */ + public int Size(params CachePeekMode[] modes) + { + _cache.Size(modes); + return GetResult(); + } + + /** */ + public void LocalPromote(IEnumerable keys) + { + _cache.LocalPromote(keys); + } + + /** */ + public IQueryCursor> Query(QueryBase qry) + { + return _cache.Query(qry); + } + + /** */ + public IQueryCursor QueryFields(SqlFieldsQuery qry) + { + return _cache.QueryFields(qry); + } + + /** */ + IContinuousQueryHandle ICache.QueryContinuous(ContinuousQuery qry) + { + return _cache.QueryContinuous(qry); + } + + /** */ + public IContinuousQueryHandle> QueryContinuous(ContinuousQuery qry, QueryBase initialQry) + { + return _cache.QueryContinuous(qry, initialQry); + } + + /** */ + public IEnumerable> GetLocalEntries(params CachePeekMode[] peekModes) + { + return _cache.GetLocalEntries(peekModes); + } + + /** */ + public TR Invoke(TK key, ICacheEntryProcessor processor, TA arg) + { + _cache.Invoke(key, processor, arg); + + return GetResult(); + } + + /** */ + public IDictionary> InvokeAll(IEnumerable keys, + ICacheEntryProcessor processor, TA arg) + { + _cache.InvokeAll(keys, processor, arg); + + return GetResult>>(); + } + + /** */ + public ICacheLock Lock(TK key) + { + return _cache.Lock(key); + } + + /** */ + public ICacheLock LockAll(IEnumerable keys) + { + return _cache.LockAll(keys); + } + + /** */ + public bool IsLocalLocked(TK key, bool byCurrentThread) + { + return _cache.IsLocalLocked(key, byCurrentThread); + } + + /** */ + public ICacheMetrics GetMetrics() + { + return _cache.GetMetrics(); + } + + /** */ + public IFuture Rebalance() + { + return _cache.Rebalance(); + } + + /** */ + public ICache WithNoRetries() + { + return _cache.WithNoRetries(); + } + + /** */ + public IEnumerator> GetEnumerator() + { + return _cache.GetEnumerator(); + } + + /** */ + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Waits for the async result. + /// + private void WaitResult() + { + GetResult(); + } + + /// + /// Gets the async result. + /// + private T GetResult() + { + return _cache.GetFuture().Get(); + } + } + + /// + /// Extension methods for IGridCache. + /// + public static class CacheExtensions + { + /// + /// Wraps specified instance into GridCacheTestAsyncWrapper. + /// + public static ICache WrapAsync(this ICache cache) + { + return new CacheTestAsyncWrapper(cache); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs new file mode 100644 index 0000000..85227b6 --- /dev/null +++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs @@ -0,0 +1,928 @@ +/* + * 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.Query +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; + using System.Text; + using Apache.Ignite.Core.Cache; + using Apache.Ignite.Core.Cache.Query; + using Apache.Ignite.Core.Common; + using Apache.Ignite.Core.Impl; + using Apache.Ignite.Core.Impl.Portable; + using Apache.Ignite.Core.Portable; + using NUnit.Framework; + + /// + /// Queries tests. + /// + public class CacheQueriesTest + { + /** Grid count. */ + private const int GridCnt = 2; + + /** Cache name. */ + private const string CacheName = "cache"; + + /** Path to XML configuration. */ + private const string CfgPath = "config\\cache-query.xml"; + + /** Maximum amount of items in cache. */ + private const int MaxItemCnt = 100; + + /// + /// + /// + [TestFixtureSetUp] + public virtual void StartGrids() + { + TestUtils.JvmDebug = true; + TestUtils.KillProcesses(); + + IgniteConfigurationEx cfg = new IgniteConfigurationEx + { + PortableConfiguration = new PortableConfiguration + { + TypeConfigurations = new[] + { + new PortableTypeConfiguration(typeof (QueryPerson)), + new PortableTypeConfiguration(typeof (PortableScanQueryFilter)), + new PortableTypeConfiguration(typeof (PortableScanQueryFilter)) + } + }, + JvmClasspath = TestUtils.CreateTestClasspath(), + JvmOptions = TestUtils.TestJavaOptions(), + SpringConfigUrl = CfgPath + }; + + for (int i = 0; i < GridCnt; i++) + { + cfg.GridName = "grid-" + i; + + Ignition.Start(cfg); + } + } + + /// + /// + /// + [TestFixtureTearDown] + public virtual void StopGrids() + { + for (int i = 0; i < GridCnt; i++) + Ignition.Stop("grid-" + i, true); + } + + /// + /// + /// + [SetUp] + public virtual void BeforeTest() + { + Console.WriteLine("Test started: " + TestContext.CurrentContext.Test.Name); + } + + /// + /// + /// + [TearDown] + public virtual void AfterTest() + { + var cache = Cache(); + + for (int i = 0; i < GridCnt; i++) + { + for (int j = 0; j < MaxItemCnt; j++) + cache.Remove(j); + + Assert.IsTrue(cache.IsEmpty); + } + + Console.WriteLine("Test finished: " + TestContext.CurrentContext.Test.Name); + } + + /// + /// + /// + /// + /// + public IIgnite GetIgnite(int idx) + { + return Ignition.GetIgnite("grid-" + idx); + } + + /// + /// + /// + /// + /// + public ICache Cache(int idx) + { + return GetIgnite(idx).Cache(CacheName); + } + + /// + /// + /// + /// + public ICache Cache() + { + return Cache(0); + } + + /// + /// Test arguments validation for SQL queries. + /// + [Test] + public void TestValidationSql() + { + // 1. No sql. + Assert.Throws(() => + { Cache().Query(new SqlQuery(typeof(QueryPerson), null)); }); + + // 2. No type. + Assert.Throws(() => + { Cache().Query(new SqlQuery((string)null, "age >= 50")); }); + } + + /// + /// Test arguments validation for SQL fields queries. + /// + [Test] + public void TestValidationSqlFields() + { + // 1. No sql. + Assert.Throws(() => { Cache().QueryFields(new SqlFieldsQuery(null)); }); + } + + /// + /// Test arguments validation for TEXT queries. + /// + [Test] + public void TestValidationText() + { + // 1. No text. + Assert.Throws(() => + { Cache().Query(new TextQuery(typeof(QueryPerson), null)); }); + + // 2. No type. + Assert.Throws(() => + { Cache().Query(new TextQuery((string)null, "Ivanov")); }); + } + + /// + /// Cursor tests. + /// + [Test] + [SuppressMessage("ReSharper", "ReturnValueOfPureMethodIsNotUsed")] + public void TestCursor() + { + var cache0 = Cache().WithAsync(); + + cache0.WithAsync().Put(1, new QueryPerson("Ivanov", 30)); + + IFuture res = cache0.GetFuture(); + + res.Get(); + + Cache().Put(1, new QueryPerson("Ivanov", 30)); + Cache().Put(1, new QueryPerson("Petrov", 40)); + Cache().Put(1, new QueryPerson("Sidorov", 50)); + + SqlQuery qry = new SqlQuery(typeof(QueryPerson), "age >= 20"); + + // 1. Test GetAll(). + using (IQueryCursor> cursor = Cache().Query(qry)) + { + cursor.GetAll(); + + Assert.Throws(() => { cursor.GetAll(); }); + Assert.Throws(() => { cursor.GetEnumerator(); }); + } + + // 2. Test GetEnumerator. + using (IQueryCursor> cursor = Cache().Query(qry)) + { + cursor.GetEnumerator(); + + Assert.Throws(() => { cursor.GetAll(); }); + Assert.Throws(() => { cursor.GetEnumerator(); }); + } + } + + /// + /// Test enumerator. + /// + [Test] + [SuppressMessage("ReSharper", "UnusedVariable")] + public void TestEnumerator() + { + Cache().Put(1, new QueryPerson("Ivanov", 30)); + Cache().Put(2, new QueryPerson("Petrov", 40)); + Cache().Put(3, new QueryPerson("Sidorov", 50)); + Cache().Put(4, new QueryPerson("Unknown", 60)); + + // 1. Empty result set. + using ( + IQueryCursor> cursor = + Cache().Query(new SqlQuery(typeof(QueryPerson), "age = 100"))) + { + IEnumerator> e = cursor.GetEnumerator(); + + Assert.Throws(() => + { ICacheEntry entry = e.Current; }); + + Assert.IsFalse(e.MoveNext()); + + Assert.Throws(() => + { ICacheEntry entry = e.Current; }); + + Assert.Throws(() => e.Reset()); + } + + SqlQuery qry = new SqlQuery(typeof (QueryPerson), "age < 60"); + + // 2. Page size is bigger than result set. + qry.PageSize = 4; + CheckEnumeratorQuery(qry); + + // 3. Page size equal to result set. + qry.PageSize = 3; + CheckEnumeratorQuery(qry); + + // 4. Page size if less than result set. + qry.PageSize = 2; + CheckEnumeratorQuery(qry); + } + + /// + /// Test SQL query arguments passing. + /// + public void TestSqlQueryArguments() + { + Cache().Put(1, new QueryPerson("Ivanov", 30)); + Cache().Put(2, new QueryPerson("Petrov", 40)); + Cache().Put(3, new QueryPerson("Sidorov", 50)); + + // 1. Empty result set. + using ( + IQueryCursor> cursor = + Cache().Query(new SqlQuery(typeof(QueryPerson), "age < ?", 50))) + { + foreach (ICacheEntry entry in cursor.GetAll()) + Assert.IsTrue(entry.Key == 1 || entry.Key == 2); + } + } + + /// + /// Test SQL fields query arguments passing. + /// + public void TestSqlFieldsQueryArguments() + { + Cache().Put(1, new QueryPerson("Ivanov", 30)); + Cache().Put(2, new QueryPerson("Petrov", 40)); + Cache().Put(3, new QueryPerson("Sidorov", 50)); + + // 1. Empty result set. + using ( + IQueryCursor cursor = Cache().QueryFields( + new SqlFieldsQuery("SELECT age FROM QueryPerson WHERE age < ?", 50))) + { + foreach (IList entry in cursor.GetAll()) + Assert.IsTrue((int) entry[0] < 50); + } + } + + /// + /// Check query result for enumerator test. + /// + /// QUery. + private void CheckEnumeratorQuery(SqlQuery qry) + { + using (IQueryCursor> cursor = Cache().Query(qry)) + { + bool first = false; + bool second = false; + bool third = false; + + foreach (var entry in cursor) + { + if (entry.Key == 1) + { + first = true; + + Assert.AreEqual("Ivanov", entry.Value.Name); + Assert.AreEqual(30, entry.Value.Age); + } + else if (entry.Key == 2) + { + second = true; + + Assert.AreEqual("Petrov", entry.Value.Name); + Assert.AreEqual(40, entry.Value.Age); + } + else if (entry.Key == 3) + { + third = true; + + Assert.AreEqual("Sidorov", entry.Value.Name); + Assert.AreEqual(50, entry.Value.Age); + } + else + Assert.Fail("Unexpected value: " + entry); + } + + Assert.IsTrue(first && second && third); + } + } + + /// + /// Check SQL query. + /// + [Test] + public void TestSqlQuery() + { + CheckSqlQuery(MaxItemCnt, false, false); + } + + /// + /// Check SQL query in portable mode. + /// + [Test] + public void TestSqlQueryPortable() + { + CheckSqlQuery(MaxItemCnt, false, true); + } + + /// + /// Check local SQL query. + /// + [Test] + public void TestSqlQueryLocal() + { + CheckSqlQuery(MaxItemCnt, true, false); + } + + /// + /// Check local SQL query in portable mode. + /// + [Test] + public void TestSqlQueryLocalPortable() + { + CheckSqlQuery(MaxItemCnt, true, true); + } + + /// + /// Check SQL query. + /// + /// Amount of cache entries to create. + /// Local query flag. + /// Keep portable flag. + private void CheckSqlQuery(int cnt, bool loc, bool keepPortable) + { + var cache = Cache(); + + // 1. Populate cache with data, calculating expected count in parallel. + var exp = PopulateCache(cache, loc, cnt, x => x < 50); + + // 2. Validate results. + SqlQuery qry = loc ? new SqlQuery(typeof(QueryPerson), "age < 50", true) : + new SqlQuery(typeof(QueryPerson), "age < 50"); + + ValidateQueryResults(cache, qry, exp, keepPortable); + } + + /// + /// Check SQL fields query. + /// + [Test] + public void TestSqlFieldsQuery() + { + CheckSqlFieldsQuery(MaxItemCnt, false); + } + + /// + /// Check local SQL fields query. + /// + [Test] + public void TestSqlFieldsQueryLocal() + { + CheckSqlFieldsQuery(MaxItemCnt, true); + } + + /// + /// Check SQL fields query. + /// + /// Amount of cache entries to create. + /// Local query flag. + private void CheckSqlFieldsQuery(int cnt, bool loc) + { + var cache = Cache(); + + // 1. Populate cache with data, calculating expected count in parallel. + var exp = PopulateCache(cache, loc, cnt, x => x < 50); + + // 2. Vlaidate results. + SqlFieldsQuery qry = loc ? new SqlFieldsQuery("SELECT name, age FROM QueryPerson WHERE age < 50", true) : + new SqlFieldsQuery("SELECT name, age FROM QueryPerson WHERE age < 50"); + + using (IQueryCursor cursor = cache.QueryFields(qry)) + { + HashSet exp0 = new HashSet(exp); + + foreach (var entry in cursor.GetAll()) + { + Assert.AreEqual(2, entry.Count); + Assert.AreEqual(entry[0].ToString(), entry[1].ToString()); + + exp0.Remove((int)entry[1]); + } + + Assert.AreEqual(0, exp0.Count); + } + + using (IQueryCursor cursor = cache.QueryFields(qry)) + { + HashSet exp0 = new HashSet(exp); + + foreach (var entry in cursor) + { + Assert.AreEqual(entry[0].ToString(), entry[1].ToString()); + + exp0.Remove((int)entry[1]); + } + + Assert.AreEqual(0, exp0.Count); + } + } + + /// + /// Check text query. + /// + [Test] + public void TestTextQuery() + { + CheckTextQuery(MaxItemCnt, false, false); + } + + /// + /// Check SQL query in portable mode. + /// + [Test] + public void TestTextQueryPortable() + { + CheckTextQuery(MaxItemCnt, false, true); + } + + /// + /// Check local SQL query. + /// + [Test] + public void TestTextQueryLocal() + { + CheckTextQuery(MaxItemCnt, true, false); + } + + /// + /// Check local SQL query in portable mode. + /// + [Test] + public void TestTextQueryLocalPortable() + { + CheckTextQuery(MaxItemCnt, true, true); + } + + /// + /// Check text query. + /// + /// Amount of cache entries to create. + /// Local query flag. + /// Keep portable flag. + private void CheckTextQuery(int cnt, bool loc, bool keepPortable) + { + var cache = Cache(); + + // 1. Populate cache with data, calculating expected count in parallel. + var exp = PopulateCache(cache, loc, cnt, x => x.ToString().StartsWith("1")); + + // 2. Validate results. + TextQuery qry = loc ? new TextQuery(typeof(QueryPerson), "1*", true) : + new TextQuery(typeof(QueryPerson), "1*"); + + ValidateQueryResults(cache, qry, exp, keepPortable); + } + + /// + /// Check scan query. + /// + [Test] + public void TestScanQuery() + { + CheckScanQuery(MaxItemCnt, false, false); + } + + /// + /// Check scan query in portable mode. + /// + [Test] + public void TestScanQueryPortable() + { + CheckScanQuery(MaxItemCnt, false, true); + } + + /// + /// Check local scan query. + /// + [Test] + public void TestScanQueryLocal() + { + CheckScanQuery(MaxItemCnt, true, false); + } + + /// + /// Check local scan query in portable mode. + /// + [Test] + public void TestScanQueryLocalPortable() + { + CheckScanQuery(MaxItemCnt, true, true); + } + + /// + /// Check scan query with partitions. + /// + [Test] + [Ignore("IGNITE-1012")] + public void TestScanQueryPartitions([Values(true, false)] bool loc) + { + CheckScanQueryPartitions(MaxItemCnt, loc, false); + } + + /// + /// Check scan query with partitions in portable mode. + /// + [Test] + [Ignore("IGNITE-1012")] + public void TestScanQueryPartitionsPortable([Values(true, false)] bool loc) + { + CheckScanQueryPartitions(MaxItemCnt, loc, true); + } + + /// + /// Tests that query attempt on non-indexed cache causes an exception. + /// + [Test] + public void TestIndexingDisabledError() + { + var cache = GetIgnite(0).GetOrCreateCache("nonindexed_cache"); + + var queries = new QueryBase[] + { + new TextQuery(typeof (QueryPerson), "1*"), + new SqlQuery(typeof (QueryPerson), "age < 50") + }; + + foreach (var qry in queries) + { + var err = Assert.Throws(() => cache.Query(qry)); + + Assert.AreEqual("Indexing is disabled for cache: nonindexed_cache. " + + "Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.", err.Message); + } + } + + /// + /// Check scan query. + /// + /// Amount of cache entries to create. + /// Local query flag. + /// Keep portable flag. + private void CheckScanQuery(int cnt, bool loc, bool keepPortable) + { + var cache = Cache(); + + // No predicate + var exp = PopulateCache(cache, loc, cnt, x => true); + var qry = new ScanQuery(); + ValidateQueryResults(cache, qry, exp, keepPortable); + + // Serializable + exp = PopulateCache(cache, loc, cnt, x => x < 50); + qry = new ScanQuery(new ScanQueryFilter()); + ValidateQueryResults(cache, qry, exp, keepPortable); + + // Portable + exp = PopulateCache(cache, loc, cnt, x => x < 50); + qry = new ScanQuery(new PortableScanQueryFilter()); + ValidateQueryResults(cache, qry, exp, keepPortable); + + // Exception + exp = PopulateCache(cache, loc, cnt, x => x < 50); + qry = new ScanQuery(new ScanQueryFilter {ThrowErr = true}); + + var ex = Assert.Throws(() => ValidateQueryResults(cache, qry, exp, keepPortable)); + Assert.AreEqual(ScanQueryFilter.ErrMessage, ex.Message); + } + + /// + /// Checks scan query with partitions. + /// + /// Amount of cache entries to create. + /// Local query flag. + /// Keep portable flag. + private void CheckScanQueryPartitions(int cnt, bool loc, bool keepPortable) + { + StopGrids(); + StartGrids(); + + var cache = Cache(); + + var aff = cache.Ignite.Affinity(CacheName); + var exp = PopulateCache(cache, loc, cnt, x => true); // populate outside the loop (slow) + + for (var part = 0; part < aff.Partitions; part++) + { + //var exp0 = new HashSet(exp.Where(x => aff.Partition(x) == part)); // filter expected keys + var exp0 = new HashSet(); + foreach (var x in exp) + if (aff.Partition(x) == part) + exp0.Add(x); + + var qry = new ScanQuery { Partition = part }; + + Console.WriteLine("Checking query on partition " + part); + ValidateQueryResults(cache, qry, exp0, keepPortable); + } + + // Partitions with predicate + exp = PopulateCache(cache, loc, cnt, x => x < 50); // populate outside the loop (slow) + + for (var part = 0; part < aff.Partitions; part++) + { + //var exp0 = new HashSet(exp.Where(x => aff.Partition(x) == part)); // filter expected keys + var exp0 = new HashSet(); + foreach (var x in exp) + if (aff.Partition(x) == part) + exp0.Add(x); + + var qry = new ScanQuery(new ScanQueryFilter()) { Partition = part }; + + Console.WriteLine("Checking predicate query on partition " + part); + ValidateQueryResults(cache, qry, exp0, keepPortable); + } + + } + + /// + /// Validates the query results. + /// + /// Cache. + /// Query. + /// Expected keys. + /// Keep portable flag. + private static void ValidateQueryResults(ICache cache, QueryBase qry, HashSet exp, + bool keepPortable) + { + if (keepPortable) + { + var cache0 = cache.WithKeepPortable(); + + using (var cursor = cache0.Query(qry)) + { + HashSet exp0 = new HashSet(exp); + var all = new List>(); + + foreach (var entry in cursor.GetAll()) + { + all.Add(entry); + + Assert.AreEqual(entry.Key.ToString(), entry.Value.Field("name")); + Assert.AreEqual(entry.Key, entry.Value.Field("age")); + + exp0.Remove(entry.Key); + } + + AssertMissingExpectedKeys(exp0, cache, all); + } + + using (var cursor = cache0.Query(qry)) + { + HashSet exp0 = new HashSet(exp); + var all = new List>(); + + foreach (var entry in cursor) + { + all.Add(entry); + + Assert.AreEqual(entry.Key.ToString(), entry.Value.Field("name")); + Assert.AreEqual(entry.Key, entry.Value.Field("age")); + + exp0.Remove(entry.Key); + } + + AssertMissingExpectedKeys(exp0, cache, all); + } + } + else + { + using (var cursor = cache.Query(qry)) + { + HashSet exp0 = new HashSet(exp); + var all = new List>(); + + foreach (var entry in cursor.GetAll()) + { + all.Add(entry); + + Assert.AreEqual(entry.Key.ToString(), entry.Value.Name); + Assert.AreEqual(entry.Key, entry.Value.Age); + + exp0.Remove(entry.Key); + } + + AssertMissingExpectedKeys(exp0, cache, all); + } + + using (var cursor = cache.Query(qry)) + { + HashSet exp0 = new HashSet(exp); + var all = new List>(); + + foreach (var entry in cursor) + { + all.Add(entry); + + Assert.AreEqual(entry.Key.ToString(), entry.Value.Name); + Assert.AreEqual(entry.Key, entry.Value.Age); + + exp0.Remove(entry.Key); + } + + AssertMissingExpectedKeys(exp0, cache, all); + } + } + } + + /// + /// Asserts that all expected entries have been received. + /// + private static void AssertMissingExpectedKeys(ICollection exp, ICache cache, + IList> all) + { + if (exp.Count == 0) + return; + + var sb = new StringBuilder(); + var aff = cache.Ignite.Affinity(cache.Name); + + foreach (var key in exp) + { + var part = aff.Partition(key); + sb.AppendFormat( + "Query did not return expected key '{0}' (exists: {1}), partition '{2}', partition nodes: ", + key, cache.Get(key) != null, part); + + var partNodes = aff.MapPartitionToPrimaryAndBackups(part); + + foreach (var node in partNodes) + sb.Append(node).Append(" "); + + sb.AppendLine(";"); + } + + sb.Append("Returned keys: "); + + foreach (var e in all) + sb.Append(e.Key).Append(" "); + + sb.AppendLine(";"); + + Assert.Fail(sb.ToString()); + } + + /// + /// Populates the cache with random entries and returns expected results set according to filter. + /// + /// The cache. + /// Amount of cache entries to create. + /// Local query flag. + /// The expected entry filter. + /// Expected results set. + private static HashSet PopulateCache(ICache cache, bool loc, int cnt, + Func expectedEntryFilter) + { + var rand = new Random(); + + var exp = new HashSet(); + + for (var i = 0; i < cnt; i++) + { + var val = rand.Next(100); + + cache.Put(val, new QueryPerson(val.ToString(), val)); + + if (expectedEntryFilter(val) && (!loc || cache.Ignite.Affinity(cache.Name) + .IsPrimary(cache.Ignite.Cluster.LocalNode, val))) + exp.Add(val); + } + + return exp; + } + } + + /// + /// Person. + /// + public class QueryPerson + { + /// + /// Constructor. + /// + public QueryPerson() + { + // No-op. + } + + /// + /// Constructor. + /// + /// Name. + /// Age. + public QueryPerson(string name, int age) + { + Name = name; + Age = age; + } + + /// + /// Name. + /// + public string Name { get; set; } + + /// + /// Age. + /// + public int Age { get; set; } + } + + /// + /// Query filter. + /// + [Serializable] + public class ScanQueryFilter : ICacheEntryFilter + { + // Error message + public const string ErrMessage = "Error in ScanQueryFilter.Invoke"; + + // Error flag + public bool ThrowErr { get; set; } + + /** */ + public bool Invoke(ICacheEntry entry) + { + if (ThrowErr) + throw new Exception(ErrMessage); + + return entry.Key < 50; + } + } + + /// + /// Portable query filter. + /// + public class PortableScanQueryFilter : ScanQueryFilter, IPortableMarshalAware + { + /** */ + public void WritePortable(IPortableWriter writer) + { + var w = writer.RawWriter(); + + w.WriteBoolean(ThrowErr); + } + + /** */ + public void ReadPortable(IPortableReader reader) + { + var r = reader.RawReader(); + + ThrowErr = r.ReadBoolean(); + } + } +}