IGNITE-6263 .NET: Verify Java config parity with a unit test
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3be007f3 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3be007f3 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3be007f3 Branch: refs/heads/ignite-5937 Commit: 3be007f3091adbf0d230ac999684b1cbb5e8ed1a Parents: 7810970 Author: Pavel Tupitsyn <[email protected]> Authored: Mon Oct 23 17:43:46 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Mon Oct 23 17:43:46 2017 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests.csproj | 7 + .../ApiParity/CacheConfigurationParityTest.cs | 88 ++++++++++++ .../ClientConnectorConfigurationParityTest.cs | 39 ++++++ .../DataRegionConfigurationParityTest.cs | 39 ++++++ .../DataStorageConfigurationParityTest.cs | 53 ++++++++ .../ApiParity/IgniteConfigurationParityTest.cs | 98 ++++++++++++++ .../ApiParity/ParityTest.cs | 135 +++++++++++++++++++ .../QueryEntityConfigurationParityTest.cs | 49 +++++++ 8 files changed, 508 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/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 1d17757..7e1753c 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 @@ -69,6 +69,13 @@ <Reference Include="System.Xml.Linq" /> </ItemGroup> <ItemGroup> + <Compile Include="ApiParity\ClientConnectorConfigurationParityTest.cs" /> + <Compile Include="ApiParity\DataRegionConfigurationParityTest.cs" /> + <Compile Include="ApiParity\DataStorageConfigurationParityTest.cs" /> + <Compile Include="ApiParity\IgniteConfigurationParityTest.cs" /> + <Compile Include="ApiParity\ParityTest.cs" /> + <Compile Include="ApiParity\CacheConfigurationParityTest.cs" /> + <Compile Include="ApiParity\QueryEntityConfigurationParityTest.cs" /> <Compile Include="Binary\BinaryBuilderSelfTestSimpleName.cs" /> <Compile Include="Binary\BinaryDateTimeTest.cs" /> <Compile Include="Binary\BinaryEqualityComparerTest.cs" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/CacheConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/CacheConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/CacheConfigurationParityTest.cs new file mode 100644 index 0000000..617eb83 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/CacheConfigurationParityTest.cs @@ -0,0 +1,88 @@ +/* + * 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.ApiParity +{ + using System.Collections.Generic; + using Apache.Ignite.Core.Cache.Configuration; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="CacheConfiguration"/> has all properties from Java configuration APIs. + /// </summary> + public class CacheConfigurationParityTest + { + /** Known property name mappings. */ + private static readonly Dictionary<string, string> KnownMappings = new Dictionary<string, string> + { + {"isStoreKeepBinary", "KeepBinaryInStore"}, + {"Affinity", "AffinityFunction"}, + {"DefaultLockTimeout", "LockTimeout"} + }; + + /** Properties that are not needed on .NET side. */ + private static readonly string[] UnneededProperties = + { + // False matches. + "clearQueryEntities", + + // Java-specific. + "CacheStoreSessionListenerFactories", + "CacheEntryListenerConfigurations", + "TopologyValidator", + "SqlFunctionClasses", + "Interceptor", + "EvictionFilter", + "IndexedTypes", + + // Deprecated, but not marked so. + "AffinityMapper" + }; + + /** Properties that are missing on .NET side. */ + private static readonly string[] MissingProperties = + { + "NodeFilter", // IGNITE-2890 + + "KeyConfiguration", // IGNITE-6704 + + // IGNITE-6705 + "IsOnheapCacheEnabled", + "StoreConcurrentLoadAllThreshold", + "RebalanceOrder", + "RebalanceBatchesPrefetchCount", + "MaxQueryIteratorsCount", + "QueryDetailMetricsSize", + "SqlSchema", + "QueryParallelism" + }; + + /// <summary> + /// Tests the cache configuration parity. + /// </summary> + [Test] + public void TestCacheConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\configuration\CacheConfiguration.java", + typeof(CacheConfiguration), + UnneededProperties, + MissingProperties, + KnownMappings); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ClientConnectorConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ClientConnectorConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ClientConnectorConfigurationParityTest.cs new file mode 100644 index 0000000..f735557 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ClientConnectorConfigurationParityTest.cs @@ -0,0 +1,39 @@ +/* + * 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.ApiParity +{ + using Apache.Ignite.Core.Configuration; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="ClientConnectorConfiguration"/> has all properties from Java configuration APIs. + /// </summary> + public class ClientConnectorConfigurationParityTest + { + /// <summary> + /// Tests the ignite configuration parity. + /// </summary> + [Test] + public void TestConnectorConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\configuration\ClientConnectorConfiguration.java", + typeof(ClientConnectorConfiguration)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataRegionConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataRegionConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataRegionConfigurationParityTest.cs new file mode 100644 index 0000000..dbc4686 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataRegionConfigurationParityTest.cs @@ -0,0 +1,39 @@ +/* + * 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.ApiParity +{ + using Apache.Ignite.Core.Configuration; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="DataRegionConfiguration"/> has all properties from Java configuration APIs. + /// </summary> + public class DataRegionConfigurationParityTest + { + /// <summary> + /// Tests the ignite configuration parity. + /// </summary> + [Test] + public void TestRegionConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\configuration\DataRegionConfiguration.java", + typeof(DataRegionConfiguration)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataStorageConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataStorageConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataStorageConfigurationParityTest.cs new file mode 100644 index 0000000..db53e2e --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/DataStorageConfigurationParityTest.cs @@ -0,0 +1,53 @@ +/* + * 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.ApiParity +{ + using Apache.Ignite.Core.Configuration; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="DataStorageConfiguration"/> has all properties from Java configuration APIs. + /// </summary> + public class DataStorageConfigurationParityTest + { + /** Properties that are not needed on .NET side. */ + private static readonly string[] UnneededProperties = + { + "FileIOFactory" + }; + + /** Properties that are missing on .NET side. */ + private static readonly string[] MissingProperties = + { + "WalAutoArchiveAfterInactivity" + }; + + /// <summary> + /// Tests the ignite configuration parity. + /// </summary> + [Test] + public void TestStorageConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\configuration\DataStorageConfiguration.java", + typeof(DataStorageConfiguration), + UnneededProperties, + MissingProperties); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/IgniteConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/IgniteConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/IgniteConfigurationParityTest.cs new file mode 100644 index 0000000..235b177 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/IgniteConfigurationParityTest.cs @@ -0,0 +1,98 @@ +/* + * 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.ApiParity +{ + using System.Collections.Generic; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="IgniteConfiguration"/> has all properties from Java configuration APIs. + /// </summary> + public class IgniteConfigurationParityTest + { + /** Known property name mappings Java -> .NET. */ + private static readonly Dictionary<string, string> KnownMappings = new Dictionary<string, string> + { + {"GridLogger", "Logger"}, + {"IncludeEventTypes", "IncludedEventTypes"}, + }; + + /** Properties that are not needed on .NET side. */ + private static readonly string[] UnneededProperties = + { + "PeerClassLoadingThreadPoolSize", + "IgfsThreadPoolSize", + "UtilityCacheKeepAliveTime", + "MBeanServer", + "isPeerClassLoadingEnabled", + "isMarshalLocalJobs", + "PeerClassLoadingLocalClassPathExclude", + "LifecycleBeans", + "SslContextFactory", + "SegmentationResolvers", + "CollisionSpi", + "DeploymentSpi", + "CheckpointSpi", + "FailoverSpi", + "LoadBalancingSpi", + "IndexingSpi", + "AddressResolver", + "DeploymentMode", + "PeerClassLoadingMissedResourcesCacheSize", + "CacheKeyConfiguration", + "FileSystemConfiguration", + "HadoopConfiguration", + "ConnectorConfiguration", + "ServiceConfiguration", + "WarmupClosure", + "ClassLoader", + "CacheStoreSessionListenerFactories", + "PlatformConfiguration", + "ExecutorConfiguration" + }; + + /** Properties that are missing on .NET side. */ + private static readonly string[] MissingProperties = + { + "RebalanceThreadPoolSize", + "SegmentationPolicy", + "isWaitForSegmentOnStart", + "isAllSegmentationResolversPassRequired", + "SegmentationResolveAttempts", + "SegmentCheckFrequency", + "isCacheSanityCheckEnabled", + "TimeServerPortBase", + "TimeServerPortRange", + "IncludeProperties" + }; + + /// <summary> + /// Tests the ignite configuration parity. + /// </summary> + [Test] + public void TestIgniteConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\configuration\IgniteConfiguration.java", + typeof(IgniteConfiguration), + UnneededProperties, + MissingProperties, + KnownMappings); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ParityTest.cs new file mode 100644 index 0000000..068d22e --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/ParityTest.cs @@ -0,0 +1,135 @@ +/* + * 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.ApiParity +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Text; + using System.Text.RegularExpressions; + using Apache.Ignite.Core.Impl.Common; + using NUnit.Framework; + + /// <summary> + /// Base class for API parity tests. + /// </summary> + public static class ParityTest + { + /** Property regex. */ + private static readonly Regex JavaPropertyRegex = + new Regex("(@Deprecated)?\\s+public [^=^\r^\n]+ (\\w+)\\(\\) {", RegexOptions.Compiled); + + /** Properties that are not needed on .NET side. */ + private static readonly string[] UnneededProperties = + { + "toString", + "hashCode", + "writeReplace" + }; + + /// <summary> + /// Tests the configuration parity. + /// </summary> + public static void CheckConfigurationParity(string javaFilePath, + Type type, + IEnumerable<string> excludedProperties = null, + IEnumerable<string> knownMissingProperties = null, + Dictionary<string, string> knownMappings = null) + { + var path = Path.Combine(IgniteHome.Resolve(null), javaFilePath); + + Assert.IsTrue(File.Exists(path)); + + var dotNetProperties = type.GetProperties() + .ToDictionary(x => x.Name, x => x, StringComparer.OrdinalIgnoreCase); + + var javaProperties = GetJavaProperties(path) + .Except(excludedProperties ?? Enumerable.Empty<string>()); + + var missingProperties = javaProperties + .Where(jp => !GetNameVariants(jp, knownMappings).Any(dotNetProperties.ContainsKey)) + .ToDictionary(x => x, x => x, StringComparer.OrdinalIgnoreCase); + + var knownMissing = (knownMissingProperties ?? Enumerable.Empty<string>()) + .ToDictionary(x => x, x => x, StringComparer.OrdinalIgnoreCase); + + var sb = new StringBuilder(); + + foreach (var javaMissingProp in missingProperties) + { + if (!knownMissing.ContainsKey(javaMissingProp.Key)) + { + sb.AppendFormat("{0}.{1} property is missing in .NET.\n", type.Name, javaMissingProp.Key); + } + } + + foreach (var dotnetMissingProp in knownMissing) + { + if (!missingProperties.ContainsKey(dotnetMissingProp.Key)) + { + sb.AppendFormat("{0}.{1} property is missing in Java, but is specified as known in .NET.\n", + type.Name, dotnetMissingProp.Key); + } + } + + if (sb.Length > 0) + { + Assert.Fail(sb.ToString()); + } + } + + /// <summary> + /// Gets the java properties from file. + /// </summary> + private static IEnumerable<string> GetJavaProperties(string path) + { + var text = File.ReadAllText(path); + + return JavaPropertyRegex.Matches(text) + .OfType<Match>() + .Where(m => m.Groups[1].Value == string.Empty) + .Select(m => m.Groups[2].Value.Replace("get", "")) + .Where(x => !x.Contains(" void ")) + .Except(UnneededProperties); + } + + /// <summary> + /// Gets the name variants for a property. + /// </summary> + private static IEnumerable<string> GetNameVariants(string javaPropertyName, + IDictionary<string, string> knownMappings) + { + yield return javaPropertyName; + + yield return javaPropertyName.Replace("PoolSize", "ThreadPoolSize"); + + if (javaPropertyName.StartsWith("is")) + { + yield return javaPropertyName.Substring(2); + } + + string map; + + if (knownMappings != null && knownMappings.TryGetValue(javaPropertyName, out map)) + { + yield return map; + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/3be007f3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/QueryEntityConfigurationParityTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/QueryEntityConfigurationParityTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/QueryEntityConfigurationParityTest.cs new file mode 100644 index 0000000..e186612 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/QueryEntityConfigurationParityTest.cs @@ -0,0 +1,49 @@ +/* + * 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.ApiParity +{ + using Apache.Ignite.Core.Cache.Configuration; + using NUnit.Framework; + + /// <summary> + /// Tests that .NET <see cref="QueryEntity"/> has all properties from Java configuration APIs. + /// </summary> + public class QueryEntityConfigurationParityTest + { + /** Properties that are not needed on .NET side. */ + private static readonly string[] UnneededProperties = + { + "findKeyType", + "findValueType", + "KeyFields", + "NotNullFields" + }; + + /// <summary> + /// Tests the ignite configuration parity. + /// </summary> + [Test] + public void TestQueryEntityConfiguration() + { + ParityTest.CheckConfigurationParity( + @"modules\core\src\main\java\org\apache\ignite\cache\QueryEntity.java", + typeof(QueryEntity), + UnneededProperties); + } + } +} \ No newline at end of file
