IGNITE-6494 .NET: Fix CacheConfiguration.WriteSynchronizationMode default value
This closes #2741 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/357f6035 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/357f6035 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/357f6035 Branch: refs/heads/ignite-3478 Commit: 357f6035a917ad7be9b7002aea5638d9d61b5330 Parents: 737033c Author: Pavel Tupitsyn <[email protected]> Authored: Tue Sep 26 11:37:31 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Tue Sep 26 11:37:31 2017 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests.csproj | 4 ++ .../Binary/BinaryDynamicRegistrationTest.cs | 15 +++-- .../Cache/CacheConfigurationTest.cs | 39 ++++++++++++- .../Config/Dynamic/dynamic-data.xml | 2 + .../Config/cache-default.xml | 56 ++++++++++++++++++ .../IgniteConfigurationSerializerTest.cs | 58 ++----------------- .../Apache.Ignite.Core.Tests/TestUtils.cs | 61 ++++++++++++++++++++ .../Cache/Configuration/CacheConfiguration.cs | 14 ++++- 8 files changed, 187 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/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 9e6cfb2..375b6b8 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 @@ -308,6 +308,10 @@ <Content Include="Config\cache-binarizables.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Config\cache-default.xml"> + <SubType>Designer</SubType> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="Config\cache-local-node.xml"> <SubType>Designer</SubType> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs index 01804b7..e635bd1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs @@ -113,7 +113,8 @@ namespace Apache.Ignite.Core.Tests.Binary { CacheStoreFactory = new StoreFactory(), ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true } } }; @@ -125,7 +126,8 @@ namespace Apache.Ignite.Core.Tests.Binary { CacheStoreFactory = new StoreFactory(), ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true }); dynCache[2] = new Foo { Str = "test2", Int = 3 }; @@ -203,7 +205,8 @@ namespace Apache.Ignite.Core.Tests.Binary { CacheStoreFactory = new StoreFactory {StringProp = "test", IntProp = 9}, ReadThrough = true, - WriteThrough = true + WriteThrough = true, + KeepBinaryInStore = true } } }; @@ -410,7 +413,11 @@ namespace Apache.Ignite.Core.Tests.Binary /// </summary> private static void Test(IIgnite ignite1, IIgnite ignite2) { - var cfg = new CacheConfiguration("cache") {CacheMode = CacheMode.Partitioned}; + var cfg = new CacheConfiguration("cache") + { + CacheMode = CacheMode.Partitioned, + WriteSynchronizationMode = CacheWriteSynchronizationMode.FullSync + }; // Put on one grid. var cache1 = ignite1.GetOrCreateCache<int, object>(cfg); http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs index 435e65f..b400ef6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs @@ -49,6 +49,9 @@ namespace Apache.Ignite.Core.Tests.Cache private const string CacheName2 = "cacheName2"; /** */ + private const string SpringCacheName = "cache-default-spring"; + + /** */ private static int _factoryProp; @@ -79,7 +82,8 @@ namespace Apache.Ignite.Core.Tests.Cache MaxSize = 99 * 1024 * 1024 } } - } + }, + SpringConfigUrl = "Config\\cache-default.xml" }; _ignite = Ignition.Start(cfg); @@ -104,7 +108,24 @@ namespace Apache.Ignite.Core.Tests.Cache AssertConfigIsDefault(_ignite.GetCache<int, int>(DefaultCacheName).GetConfiguration()); - AssertConfigIsDefault(_ignite.GetConfiguration().CacheConfiguration.Single(c => c.Name == DefaultCacheName)); + AssertConfigIsDefault(_ignite.GetConfiguration().CacheConfiguration + .Single(c => c.Name == DefaultCacheName)); + } + + /// <summary> + /// Tests that defaults are the same in Java. + /// </summary> + [Test] + public void TestDefaultsAreSameInJava() + { + var springConfig = _ignite.GetCache<int, int>(SpringCacheName).GetConfiguration(); + + var ignoredProps = new[] {"AffinityFunction"}; + + TestUtils.AssertReflectionEqual(springConfig, new CacheConfiguration(SpringCacheName), + ignoredProperties: new HashSet<string>(ignoredProps)); + + AssertConfigIsDefault(springConfig); } /// <summary> @@ -221,7 +242,7 @@ namespace Apache.Ignite.Core.Tests.Cache Assert.AreEqual(CacheConfiguration.DefaultCopyOnRead, cfg.CopyOnRead); Assert.AreEqual(CacheConfiguration.DefaultEagerTtl, cfg.EagerTtl); Assert.AreEqual(CacheConfiguration.DefaultInvalidate, cfg.Invalidate); - Assert.AreEqual(CacheConfiguration.DefaultKeepVinaryInStore, cfg.KeepBinaryInStore); + Assert.AreEqual(CacheConfiguration.DefaultKeepBinaryInStore, cfg.KeepBinaryInStore); Assert.AreEqual(CacheConfiguration.DefaultLoadPreviousValue, cfg.LoadPreviousValue); Assert.AreEqual(CacheConfiguration.DefaultLockTimeout, cfg.LockTimeout); #pragma warning disable 618 @@ -240,6 +261,12 @@ namespace Apache.Ignite.Core.Tests.Cache Assert.AreEqual(CacheConfiguration.DefaultWriteBehindFlushThreadCount, cfg.WriteBehindFlushThreadCount); Assert.AreEqual(CacheConfiguration.DefaultWriteBehindCoalescing, cfg.WriteBehindCoalescing); Assert.AreEqual(CacheConfiguration.DefaultPartitionLossPolicy, cfg.PartitionLossPolicy); + Assert.AreEqual(CacheConfiguration.DefaultWriteSynchronizationMode, cfg.WriteSynchronizationMode); + Assert.AreEqual(CacheConfiguration.DefaultWriteBehindCoalescing, cfg.WriteBehindCoalescing); + Assert.AreEqual(CacheConfiguration.DefaultWriteThrough, cfg.WriteThrough); + Assert.AreEqual(CacheConfiguration.DefaultReadThrough, cfg.ReadThrough); + Assert.AreEqual(CacheConfiguration.DefaultCopyOnRead, cfg.CopyOnRead); + Assert.AreEqual(CacheConfiguration.DefaultKeepBinaryInStore, cfg.KeepBinaryInStore); } /// <summary> @@ -272,13 +299,19 @@ namespace Apache.Ignite.Core.Tests.Cache Assert.AreEqual(x.EnableStatistics, y.EnableStatistics); Assert.AreEqual(x.MemoryPolicyName, y.MemoryPolicyName); Assert.AreEqual(x.PartitionLossPolicy, y.PartitionLossPolicy); + Assert.AreEqual(x.WriteBehindCoalescing, y.WriteBehindCoalescing); Assert.AreEqual(x.GroupName, y.GroupName); + Assert.AreEqual(x.WriteSynchronizationMode, y.WriteSynchronizationMode); if (x.ExpiryPolicyFactory != null) + { Assert.AreEqual(x.ExpiryPolicyFactory.CreateInstance().GetType(), y.ExpiryPolicyFactory.CreateInstance().GetType()); + } else + { Assert.IsNull(y.ExpiryPolicyFactory); + } AssertConfigsAreEqual(x.QueryEntities, y.QueryEntities); AssertConfigsAreEqual(x.NearConfiguration, y.NearConfiguration); http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml index 682a517..3b37fa9 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Dynamic/dynamic-data.xml @@ -35,12 +35,14 @@ <property name="name" value="p"/> <property name="cacheMode" value="PARTITIONED"/> <property name="atomicityMode" value="TRANSACTIONAL"/> + <property name="writeSynchronizationMode" value="FULL_SYNC"/> </bean> <bean class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="pa"/> <property name="cacheMode" value="PARTITIONED"/> <property name="atomicityMode" value="ATOMIC"/> + <property name="writeSynchronizationMode" value="FULL_SYNC"/> </bean> </list> </property> http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml new file mode 100644 index 0000000..7832e87 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-default.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util.xsd"> + <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="localHost" value="127.0.0.1"/> + <property name="connectorConfiguration"><null/></property> + + <property name="cacheConfiguration"> + <list> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <property name="name" value="cache-default-spring"/> + </bean> + </list> + </property> + + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> + <property name="addresses"> + <list> + <!-- In distributed environment, replace with actual host IP address. --> + <value>127.0.0.1:47500</value> + </list> + </property> + </bean> + </property> + <property name="socketTimeout" value="300" /> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index 23ee884..2177c6a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -20,7 +20,6 @@ namespace Apache.Ignite.Core.Tests { using System; - using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.CodeAnalysis; @@ -514,15 +513,15 @@ namespace Apache.Ignite.Core.Tests { // Empty section. var cfg = IgniteConfiguration.FromXml("<x />"); - AssertReflectionEqual(new IgniteConfiguration(), cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration(), cfg); // Empty section with XML header. cfg = IgniteConfiguration.FromXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><x />"); - AssertReflectionEqual(new IgniteConfiguration(), cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration(), cfg); // Simple test. cfg = IgniteConfiguration.FromXml(@"<igCfg igniteInstanceName=""myGrid"" clientMode=""true"" />"); - AssertReflectionEqual(new IgniteConfiguration {IgniteInstanceName = "myGrid", ClientMode = true}, cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration {IgniteInstanceName = "myGrid", ClientMode = true}, cfg); // Invalid xml. var ex = Assert.Throws<ConfigurationErrorsException>(() => @@ -537,7 +536,7 @@ namespace Apache.Ignite.Core.Tests { cfg = IgniteConfiguration.FromXml(xmlReader); } - AssertReflectionEqual(new IgniteConfiguration { IgniteInstanceName = "myGrid", ClientMode = true }, cfg); + TestUtils.AssertReflectionEqual(new IgniteConfiguration { IgniteInstanceName = "myGrid", ClientMode = true }, cfg); } /// <summary> @@ -589,7 +588,7 @@ namespace Apache.Ignite.Core.Tests { var resCfg = SerializeDeserialize(cfg); - AssertReflectionEqual(cfg, resCfg); + TestUtils.AssertReflectionEqual(cfg, resCfg); } /// <summary> @@ -602,53 +601,6 @@ namespace Apache.Ignite.Core.Tests return IgniteConfiguration.FromXml(xml); } - /// <summary> - /// Asserts equality with reflection. - /// </summary> - private static void AssertReflectionEqual(object x, object y) - { - var type = x.GetType(); - - Assert.AreEqual(type, y.GetType()); - - if (type.IsValueType || type == typeof (string) || type.IsSubclassOf(typeof (Type))) - { - Assert.AreEqual(x, y); - return; - } - - var props = type.GetProperties().Where(p => p.GetIndexParameters().Length == 0); - - foreach (var propInfo in props) - { - var propType = propInfo.PropertyType; - - var xVal = propInfo.GetValue(x, null); - var yVal = propInfo.GetValue(y, null); - - if (xVal == null || yVal == null) - { - Assert.IsNull(xVal); - Assert.IsNull(yVal); - } - else if (propType != typeof(string) && propType.IsGenericType && - (propType.GetGenericTypeDefinition() == typeof(ICollection<>) || - propType.GetGenericTypeDefinition() == typeof(IDictionary<,>) )) - { - var xCol = ((IEnumerable) xVal).OfType<object>().ToList(); - var yCol = ((IEnumerable) yVal).OfType<object>().ToList(); - - Assert.AreEqual(xCol.Count, yCol.Count); - - for (int i = 0; i < xCol.Count; i++) - AssertReflectionEqual(xCol[i], yCol[i]); - } - else - { - AssertReflectionEqual(xVal, yVal); - } - } - } /// <summary> /// Gets the test configuration. http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs index 4b171b0..34e356b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs @@ -18,6 +18,7 @@ namespace Apache.Ignite.Core.Tests { using System; + using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -402,5 +403,65 @@ namespace Apache.Ignite.Core.Tests { return GetPrimaryKeys(ignite, cacheName, node).First(); } + + /// <summary> + /// Asserts equality with reflection. + /// </summary> + public static void AssertReflectionEqual(object x, object y, string propertyPath = null, + HashSet<string> ignoredProperties = null) + { + var type = x.GetType(); + + Assert.AreEqual(type, y.GetType()); + + propertyPath = propertyPath ?? type.Name; + + if (type.IsValueType || type == typeof(string) || type.IsSubclassOf(typeof(Type))) + { + Assert.AreEqual(x, y, propertyPath); + return; + } + + var props = type.GetProperties().Where(p => p.GetIndexParameters().Length == 0); + + foreach (var propInfo in props) + { + var propType = propInfo.PropertyType; + + if (ignoredProperties != null && ignoredProperties.Contains(propInfo.Name)) + { + continue; + } + + var propName = propertyPath + "." + propInfo.Name; + + var xVal = propInfo.GetValue(x, null); + var yVal = propInfo.GetValue(y, null); + + if (xVal == null || yVal == null) + { + Assert.IsNull(xVal, propName); + Assert.IsNull(yVal, propName); + } + else if (propType != typeof(string) && propType.IsGenericType && + (propType.GetGenericTypeDefinition() == typeof(ICollection<>) || + propType.GetGenericTypeDefinition() == typeof(IDictionary<,>))) + { + var xCol = ((IEnumerable)xVal).OfType<object>().ToList(); + var yCol = ((IEnumerable)yVal).OfType<object>().ToList(); + + Assert.AreEqual(xCol.Count, yCol.Count, propName); + + for (var i = 0; i < xCol.Count; i++) + { + AssertReflectionEqual(xCol[i], yCol[i], propName, ignoredProperties); + } + } + else + { + AssertReflectionEqual(xVal, yVal, propName, ignoredProperties); + } + } + } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/357f6035/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs index d08a191..421f16f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs @@ -81,6 +81,10 @@ namespace Apache.Ignite.Core.Cache.Configuration /// <summary> Default rebalance batch size in bytes. </summary> public const int DefaultRebalanceBatchSize = 512*1024; // 512K + /// <summary> Default value for <see cref="WriteSynchronizationMode"/> property.</summary> + public const CacheWriteSynchronizationMode DefaultWriteSynchronizationMode = + CacheWriteSynchronizationMode.PrimarySync; + /// <summary> Default value for eager ttl flag. </summary> public const bool DefaultEagerTtl = true; @@ -112,8 +116,12 @@ namespace Apache.Ignite.Core.Cache.Configuration public static readonly TimeSpan DefaultLongQueryWarningTimeout = TimeSpan.FromMilliseconds(3000); /// <summary> Default value for keep portable in store behavior .</summary> + [Obsolete("Use DefaultKeepBinaryInStore instead.")] public const bool DefaultKeepVinaryInStore = true; + /// <summary> Default value for <see cref="KeepBinaryInStore"/> property.</summary> + public const bool DefaultKeepBinaryInStore = false; + /// <summary> Default value for 'copyOnRead' flag. </summary> public const bool DefaultCopyOnRead = true; @@ -154,9 +162,10 @@ namespace Apache.Ignite.Core.Cache.Configuration AtomicityMode = DefaultAtomicityMode; CacheMode = DefaultCacheMode; CopyOnRead = DefaultCopyOnRead; + WriteSynchronizationMode = DefaultWriteSynchronizationMode; EagerTtl = DefaultEagerTtl; Invalidate = DefaultInvalidate; - KeepBinaryInStore = DefaultKeepVinaryInStore; + KeepBinaryInStore = DefaultKeepBinaryInStore; LoadPreviousValue = DefaultLoadPreviousValue; LockTimeout = DefaultLockTimeout; #pragma warning disable 618 @@ -438,6 +447,7 @@ namespace Apache.Ignite.Core.Cache.Configuration /// Gets or sets write synchronization mode. This mode controls whether the main /// caller should wait for update on other nodes to complete or not. /// </summary> + [DefaultValue(DefaultWriteSynchronizationMode)] public CacheWriteSynchronizationMode WriteSynchronizationMode { get; set; } /// <summary> @@ -467,7 +477,7 @@ namespace Apache.Ignite.Core.Cache.Configuration /// Gets or sets the flag indicating whether <see cref="ICacheStore"/> is working with binary objects /// instead of deserialized objects. /// </summary> - [DefaultValue(DefaultKeepVinaryInStore)] + [DefaultValue(DefaultKeepBinaryInStore)] public bool KeepBinaryInStore { get; set; } /// <summary>
