Lucene.Net.TestFramework.Index.RandomCodec: Fixed bugs that were causing KeyNotFoundExceptions and fixed ToString() to output the format and DV format dictionaries
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/eaf01d11 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/eaf01d11 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/eaf01d11 Branch: refs/heads/api-work Commit: eaf01d119e0f768dcfe937e246c30a4d289a78a1 Parents: 8cdfd72 Author: Shad Storhaug <[email protected]> Authored: Thu Mar 2 03:43:20 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 2 08:09:03 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.TestFramework/Index/RandomCodec.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/eaf01d11/src/Lucene.Net.TestFramework/Index/RandomCodec.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Index/RandomCodec.cs b/src/Lucene.Net.TestFramework/Index/RandomCodec.cs index 6ed24d5..bab0903 100644 --- a/src/Lucene.Net.TestFramework/Index/RandomCodec.cs +++ b/src/Lucene.Net.TestFramework/Index/RandomCodec.cs @@ -1,6 +1,7 @@ using Lucene.Net.Support; using Lucene.Net.Util; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -86,15 +87,15 @@ namespace Lucene.Net.Index // note: we have to sync this map even though its just for debugging/toString, // otherwise DWPT's .toString() calls that iterate over the map can // cause concurrentmodificationexception if indexwriter's infostream is on - private readonly IDictionary<string, PostingsFormat> previousMappings = new ConcurrentHashMapWrapper<string, PostingsFormat>(new Dictionary<string, PostingsFormat>()); + private readonly IDictionary<string, PostingsFormat> previousMappings = new ConcurrentDictionary<string, PostingsFormat>(); - private IDictionary<string, DocValuesFormat> previousDVMappings = new ConcurrentHashMapWrapper<string, DocValuesFormat>(new Dictionary<string, DocValuesFormat>()); + private IDictionary<string, DocValuesFormat> previousDVMappings = new ConcurrentDictionary<string, DocValuesFormat>(); private readonly int perFieldSeed; public override PostingsFormat GetPostingsFormatForField(string name) { - PostingsFormat codec = previousMappings[name]; - if (codec == null) + PostingsFormat codec; + if (!previousMappings.TryGetValue(name, out codec) || codec == null) { codec = formats[Math.Abs(perFieldSeed ^ name.GetHashCode()) % formats.Count]; if (codec is SimpleTextPostingsFormat && perFieldSeed % 5 != 0) @@ -111,8 +112,8 @@ namespace Lucene.Net.Index public override DocValuesFormat GetDocValuesFormatForField(string name) { - DocValuesFormat codec = previousDVMappings[name]; - if (codec == null) + DocValuesFormat codec; + if (!previousDVMappings.TryGetValue(name, out codec) || codec == null) { codec = dvFormats[Math.Abs(perFieldSeed ^ name.GetHashCode()) % dvFormats.Count]; if (codec is SimpleTextDocValuesFormat && perFieldSeed % 5 != 0) @@ -214,7 +215,8 @@ namespace Lucene.Net.Index public override string ToString() { - return base.ToString() + ": " + previousMappings.ToString() + ", docValues:" + previousDVMappings.ToString(); + // LUCENENET NOTE: using toString() extension method on dictionaries to print out their contents + return base.ToString() + ": " + previousMappings.toString() + ", docValues:" + previousDVMappings.toString(); } } } \ No newline at end of file
