You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/01/11 09:12:56 UTC
[ignite] branch master updated: IGNITE-12090 .NET: Fix
KeyNotFoundException on nullable sbyte query field
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new e2b0b11 IGNITE-12090 .NET: Fix KeyNotFoundException on nullable sbyte query field
e2b0b11 is described below
commit e2b0b115d7228ad92a0c45ad772489aaca625507
Author: Aleksandr Shapkin <as...@gridgain.com>
AuthorDate: Mon Jan 11 12:12:22 2021 +0300
IGNITE-12090 .NET: Fix KeyNotFoundException on nullable sbyte query field
---
.../Log/CustomLoggerTest.cs | 91 ++++++++++++++++++++++
.../Apache.Ignite.Core/Impl/Binary/JavaTypes.cs | 2 +-
2 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
index 543287e..06d54b6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
@@ -211,6 +211,89 @@ namespace Apache.Ignite.Core.Tests.Log
}
/// <summary>
+ /// Tests the nullable <see cref="QueryEntity"/> validation.
+ /// </summary>
+ [TestCase(typeof(sbyte?), "java.lang.Byte", typeof(byte))]
+ [TestCase(typeof(ushort?), "java.lang.Short", typeof(short))]
+ [TestCase(typeof(uint?), "java.lang.Integer", typeof(int))]
+ [TestCase(typeof(ulong?), "java.lang.Long", typeof(long))]
+ public void TestNullableQueryEntityValidation(Type type, string javaType, Type hintType)
+ {
+ var cfg = new IgniteConfiguration(GetConfigWithLogger())
+ {
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration("cache1", new QueryEntity(type, type)
+ {
+ Fields = new[]
+ {
+ new QueryField("myField", type)
+ }
+ })
+ }
+ };
+
+ using (Ignition.Start(cfg))
+ {
+ var warns = TestLogger.Entries.Where(x => x.Level == LogLevel.Warn && x.Args != null)
+ .Select(x => string.Format(x.Message, x.Args)).ToList();
+
+ Assert.AreEqual(3, warns.Count);
+
+ string pattern = "Validating cache configuration 'cache1', QueryEntity '{0}:{0}': " +
+ "Type '{1}' maps to Java type '{0}' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use '{2}' " +
+ "instead to achieve direct mapping.";
+
+ string expected = string.Format(pattern, javaType, type, hintType);
+
+ Assert.AreEqual(expected, warns[0]);
+ Assert.AreEqual(expected, warns[1]);
+
+ string fieldsPattern = "Validating cache configuration 'cache1', QueryEntity '{0}:{0}', " +
+ "QueryField 'myField': Type '{1}' maps to Java type '{0}' using " +
+ "unchecked conversion. This may cause issues in SQL queries. " +
+ "You can use '{2}' instead to achieve direct mapping.";
+
+ string fieldsExpected = string.Format(fieldsPattern, javaType, type, hintType);
+ Assert.AreEqual(fieldsExpected, warns[2]);
+ }
+ }
+
+ /// <summary>
+ /// Tests cache creation with nullable <see cref="QueryEntity"/> does not log warnings.
+ /// </summary>
+ [TestCase(typeof(int))]
+ [TestCase(typeof(int?))]
+ [TestCase(typeof(string))]
+ [TestCase(typeof(LogEntry))]
+ [TestCase(typeof(CustomLoggerTest))]
+ [TestCase(typeof(CustomEnum))]
+ [TestCase(typeof(CustomEnum?))]
+ public void TestCacheCreationWithDirectQueryEntityMappingsDoesNotLogWarnings(Type type)
+ {
+ var cfg = new IgniteConfiguration(GetConfigWithLogger())
+ {
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration("cache1", new QueryEntity(type, type)
+ {
+ Fields = new[]
+ {
+ new QueryField("myField", type)
+ }
+ })
+ }
+ };
+
+ using (Ignition.Start(cfg))
+ {
+ int warnsCount = TestLogger.Entries.Count(x => x.Level == LogLevel.Warn && x.Args != null);
+ Assert.AreEqual(0, warnsCount);
+ }
+ }
+
+ /// <summary>
/// Tests the <see cref="LoggerExtensions"/> methods.
/// </summary>
[Test]
@@ -449,5 +532,13 @@ namespace Apache.Ignite.Core.Tests.Log
throw new ArithmeticException("Error in func.");
}
}
+
+ /// <summary>
+ /// Custom enum for testing.
+ /// </summary>
+ private struct CustomEnum
+ {
+ public int Field { get; set; }
+ }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
index 9451d8c..15a8e78 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
@@ -107,7 +107,7 @@ namespace Apache.Ignite.Core.Impl.Binary
log.Warn("{0}: Type '{1}' maps to Java type '{2}' using unchecked conversion. " +
"This may cause issues in SQL queries. " +
"You can use '{3}' instead to achieve direct mapping.",
- logInfo, type, NetToJava[type], directType);
+ logInfo, type, NetToJava[directType], directType);
}
/// <summary>