You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2015/05/16 20:19:22 UTC

[1/3] lucenenet git commit: use Environment.TickCount instead DateTime.Now.Millisecond

Repository: lucenenet
Updated Branches:
  refs/heads/master f963b1d7a -> e3833d6cc


use Environment.TickCount instead DateTime.Now.Millisecond


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ee1635f4
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ee1635f4
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ee1635f4

Branch: refs/heads/master
Commit: ee1635f4c12385f9310fef75078d0c9e13fda966
Parents: 37c4003
Author: Laimonas Simutis <la...@gmail.com>
Authored: Sat May 16 13:49:49 2015 -0400
Committer: Laimonas Simutis <la...@gmail.com>
Committed: Sat May 16 13:49:49 2015 -0400

----------------------------------------------------------------------
 .../Index/BufferedUpdatesStream.cs              |   4 +-
 .../Index/ConcurrentMergeScheduler.cs           |   4 +-
 src/Lucene.Net.Core/Index/DocTermOrds.cs        |   6 +-
 src/Lucene.Net.Core/Index/IndexWriter.cs        |   8 +-
 .../Index/SimpleMergedSegmentWarmer.cs          |   4 +-
 .../Search/ControlledRealTimeReopenThread.cs    |   4 +-
 src/Lucene.Net.Core/Util/OfflineSorter.cs       | 480 -------------------
 .../Search/QueryUtils.cs                        |   4 +-
 src/Lucene.Net.Tests/core/Index/Test2BTerms.cs  |   8 +-
 .../core/Index/TestAtomicUpdate.cs              |   6 +-
 .../core/Index/TestDeletionPolicy.cs            |   7 +-
 .../core/Index/TestDocValuesWithThreads.cs      |  11 +-
 .../Index/TestDocumentsWriterStallControl.cs    |  11 +-
 .../core/Index/TestIndexWriterCommit.cs         |  20 +-
 .../core/Index/TestIndexWriterReader.cs         |  30 +-
 .../core/Index/TestIndexWriterWithThreads.cs    |  15 +-
 .../core/Index/TestNRTReaderWithThreads.cs      |  12 +-
 .../core/Index/TestNeverDelete.cs               |  14 +-
 .../core/Index/TestSnapshotDeletionPolicy.cs    |  11 +-
 .../core/Index/TestStressIndexing.cs            |  14 +-
 .../core/Index/TestTermdocPerf.cs               |  15 +-
 .../core/Index/TestTransactions.cs              |   7 +-
 .../core/Search/TestDateFilter.cs               |   4 +-
 .../core/Search/TestMultiThreadTermVectors.cs   |   8 +-
 .../core/Search/TestSearchWithThreads.cs        |   9 +-
 25 files changed, 101 insertions(+), 615 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Index/BufferedUpdatesStream.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BufferedUpdatesStream.cs b/src/Lucene.Net.Core/Index/BufferedUpdatesStream.cs
index 5fd762f..d807882 100644
--- a/src/Lucene.Net.Core/Index/BufferedUpdatesStream.cs
+++ b/src/Lucene.Net.Core/Index/BufferedUpdatesStream.cs
@@ -179,7 +179,7 @@ namespace Lucene.Net.Index
         {
             lock (this)
             {
-                long t0 = DateTime.Now.Millisecond;
+                long t0 = Environment.TickCount;
 
                 if (infos.Count == 0)
                 {
@@ -373,7 +373,7 @@ namespace Lucene.Net.Index
                 Debug.Assert(CheckDeleteStats());
                 if (InfoStream.IsEnabled("BD"))
                 {
-                    InfoStream.Message("BD", "applyDeletes took " + (DateTime.Now.Millisecond - t0) + " msec");
+                    InfoStream.Message("BD", "applyDeletes took " + (Environment.TickCount - t0) + " msec");
                 }
                 // assert infos != segmentInfos || !any() : "infos=" + infos + " segmentInfos=" + segmentInfos + " any=" + any;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Index/ConcurrentMergeScheduler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ConcurrentMergeScheduler.cs b/src/Lucene.Net.Core/Index/ConcurrentMergeScheduler.cs
index 5f6bfa3..eeb3231 100644
--- a/src/Lucene.Net.Core/Index/ConcurrentMergeScheduler.cs
+++ b/src/Lucene.Net.Core/Index/ConcurrentMergeScheduler.cs
@@ -437,7 +437,7 @@ namespace Lucene.Net.Index
                         // updateMergeThreads).  We stall this producer
                         // thread to prevent creation of new segments,
                         // until merging has caught up:
-                        startStallTime = DateTime.Now.Millisecond;
+                        startStallTime = Environment.TickCount;
                         if (Verbose())
                         {
                             Message("    too many merges; stalling...");
@@ -456,7 +456,7 @@ namespace Lucene.Net.Index
                     {
                         if (startStallTime != 0)
                         {
-                            Message("  stalled for " + (DateTime.Now.Millisecond - startStallTime) + " msec");
+                            Message("  stalled for " + (Environment.TickCount - startStallTime) + " msec");
                         }
                     }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Index/DocTermOrds.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/DocTermOrds.cs b/src/Lucene.Net.Core/Index/DocTermOrds.cs
index 50bca35..d393555 100644
--- a/src/Lucene.Net.Core/Index/DocTermOrds.cs
+++ b/src/Lucene.Net.Core/Index/DocTermOrds.cs
@@ -331,7 +331,7 @@ namespace Lucene.Net.Index
                 throw new InvalidOperationException("Type mismatch: " + Field + " was indexed as " + info.DocValuesType);
             }
             //System.out.println("DTO uninvert field=" + field + " prefix=" + termPrefix);
-            long startTime = DateTime.Now.Millisecond;
+            long startTime = Environment.TickCount;
             Prefix = termPrefix == null ? null : BytesRef.DeepCopyOf(termPrefix);
 
             int maxDoc = reader.MaxDoc;
@@ -552,7 +552,7 @@ namespace Lucene.Net.Index
 
             NumTermsInField = termNum;
 
-            long midPoint = DateTime.Now.Millisecond;
+            long midPoint = Environment.TickCount;
 
             if (TermInstances == 0)
             {
@@ -662,7 +662,7 @@ namespace Lucene.Net.Index
                 IndexedTermsArray = indexedTerms.ToArray();
             }
 
-            long endTime = DateTime.Now.Millisecond;
+            long endTime = Environment.TickCount;
 
             Total_time = (int)(endTime - startTime);
             Phase1_time = (int)(midPoint - startTime);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Index/IndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs
index 1067ab5..2cb6c0a 100644
--- a/src/Lucene.Net.Core/Index/IndexWriter.cs
+++ b/src/Lucene.Net.Core/Index/IndexWriter.cs
@@ -368,7 +368,7 @@ namespace Lucene.Net.Index
         {
             EnsureOpen();
 
-            long tStart = DateTime.Now.Millisecond;
+            long tStart = Environment.TickCount;
 
             if (infoStream.IsEnabled("IW"))
             {
@@ -444,7 +444,7 @@ namespace Lucene.Net.Index
                 }
                 if (infoStream.IsEnabled("IW"))
                 {
-                    infoStream.Message("IW", "getReader took " + (DateTime.Now.Millisecond - tStart) + " msec");
+                    infoStream.Message("IW", "getReader took " + (Environment.TickCount - tStart) + " msec");
                 }
                 success2 = true;
             }
@@ -4542,7 +4542,7 @@ namespace Lucene.Net.Index
         {
             bool success = false;
 
-            long t0 = DateTime.Now.Millisecond;
+            long t0 = Environment.TickCount;
 
             try
             {
@@ -4605,7 +4605,7 @@ namespace Lucene.Net.Index
             {
                 if (infoStream.IsEnabled("IW"))
                 {
-                    infoStream.Message("IW", "merge time " + (DateTime.Now.Millisecond - t0) + " msec for " + merge.info.Info.DocCount + " docs");
+                    infoStream.Message("IW", "merge time " + (Environment.TickCount - t0) + " msec for " + merge.info.Info.DocCount + " docs");
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Index/SimpleMergedSegmentWarmer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SimpleMergedSegmentWarmer.cs b/src/Lucene.Net.Core/Index/SimpleMergedSegmentWarmer.cs
index e8490e3..87ec152 100644
--- a/src/Lucene.Net.Core/Index/SimpleMergedSegmentWarmer.cs
+++ b/src/Lucene.Net.Core/Index/SimpleMergedSegmentWarmer.cs
@@ -43,7 +43,7 @@ namespace Lucene.Net.Index
 
         public override void Warm(AtomicReader reader)
         {
-            long startTime = DateTime.Now.Millisecond;
+            long startTime = Environment.TickCount;
             int indexedCount = 0;
             int docValuesCount = 0;
             int normsCount = 0;
@@ -94,7 +94,7 @@ namespace Lucene.Net.Index
 
             if (InfoStream.IsEnabled("SMSW"))
             {
-                InfoStream.Message("SMSW", "Finished warming segment: " + reader + ", indexed=" + indexedCount + ", docValues=" + docValuesCount + ", norms=" + normsCount + ", time=" + (DateTime.Now.Millisecond - startTime));
+                InfoStream.Message("SMSW", "Finished warming segment: " + reader + ", indexed=" + indexedCount + ", docValues=" + docValuesCount + ", norms=" + normsCount + ", time=" + (Environment.TickCount - startTime));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Search/ControlledRealTimeReopenThread.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/ControlledRealTimeReopenThread.cs b/src/Lucene.Net.Core/Search/ControlledRealTimeReopenThread.cs
index bf1812b..a296405 100644
--- a/src/Lucene.Net.Core/Search/ControlledRealTimeReopenThread.cs
+++ b/src/Lucene.Net.Core/Search/ControlledRealTimeReopenThread.cs
@@ -219,7 +219,7 @@ namespace Lucene.Net.Search
                         ReopenLock.Unlock();
                     }
 
-                    long startMS = DateTime.Now.Millisecond;//System.nanoTime() / 1000000;
+                    long startMS = Environment.TickCount;//System.nanoTime() / 1000000;
 
                     while (targetGen > SearchingGen)
                     {
@@ -229,7 +229,7 @@ namespace Lucene.Net.Search
                         }
                         else
                         {
-                            long msLeft = (startMS + maxMS) - DateTime.Now.Millisecond;//(System.nanoTime()) / 1000000;
+                            long msLeft = (startMS + maxMS) - Environment.TickCount;//(System.nanoTime()) / 1000000;
                             if (msLeft <= 0)
                             {
                                 return false;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Core/Util/OfflineSorter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/OfflineSorter.cs b/src/Lucene.Net.Core/Util/OfflineSorter.cs
index db6db48..afc0159 100644
--- a/src/Lucene.Net.Core/Util/OfflineSorter.cs
+++ b/src/Lucene.Net.Core/Util/OfflineSorter.cs
@@ -34,486 +34,6 @@ namespace Lucene.Net.Util
     /// </summary>
     public sealed class OfflineSorter
     {
-//        private bool InstanceFieldsInitialized = false;
-//
-//        private void InitializeInstanceFields()
-//        {
-//            Buffer = new BytesRefArray(BufferBytesUsed);
-//        }
-//
-//        /// <summary>
-//        /// Convenience constant for megabytes </summary>
-//        public const long MB = 1024 * 1024;
-//        /// <summary>
-//        /// Convenience constant for gigabytes </summary>
-//        public static readonly long GB = MB * 1024;
-//
-//        /// <summary>
-//        /// Minimum recommended buffer size for sorting.
-//        /// </summary>
-//        public const long MIN_BUFFER_SIZE_MB = 32;
-//
-//        /// <summary>
-//        /// Absolute minimum required buffer size for sorting.
-//        /// </summary>
-//        public static readonly long ABSOLUTE_MIN_SORT_BUFFER_SIZE = MB / 2;
-//        private const string MIN_BUFFER_SIZE_MSG = "At least 0.5MB RAM buffer is needed";
-//
-//        /// <summary>
-//        /// Maximum number of temporary files before doing an intermediate merge.
-//        /// </summary>
-//        public const int MAX_TEMPFILES = 128;
-//
-//        /// <summary>
-//        /// A bit more descriptive unit for constructors.
-//        /// </summary>
-//        /// <seealso cref= #automatic() </seealso>
-//        /// <seealso cref= #megabytes(long) </seealso>
-//        public sealed class BufferSize
-//        {
-//            internal readonly int Bytes;
-//
-//            internal BufferSize(long bytes)
-//            {
-//                if (bytes > int.MaxValue)
-//                {
-//                    throw new System.ArgumentException("Buffer too large for Java (" + (int.MaxValue / MB) + "mb max): " + bytes);
-//                }
-//
-//                if (bytes < ABSOLUTE_MIN_SORT_BUFFER_SIZE)
-//                {
-//                    throw new System.ArgumentException(MIN_BUFFER_SIZE_MSG + ": " + bytes);
-//                }
-//
-//                this.Bytes = (int)bytes;
-//            }
-//
-//            /// <summary>
-//            /// Creates a <seealso cref="BufferSize"/> in MB. The given
-//            /// values must be &gt; 0 and &lt; 2048.
-//            /// </summary>
-//            public static BufferSize Megabytes(long mb)
-//            {
-//                return new BufferSize(mb * MB);
-//            }
-//
-//            /// <summary>
-//            /// Approximately half of the currently available free heap, but no less
-//            /// than <seealso cref="#ABSOLUTE_MIN_SORT_BUFFER_SIZE"/>. However if current heap allocation
-//            /// is insufficient or if there is a large portion of unallocated heap-space available
-//            /// for sorting consult with max allowed heap size.
-//            /// </summary>
-//            public static BufferSize Automatic()
-//            {
-//                var proc = Process.GetCurrentProcess();
-//
-//                // take sizes in "conservative" order
-//                long max = proc.PeakVirtualMemorySize64; // max allocated; java has it as Runtime.maxMemory();
-//                long total = proc.VirtualMemorySize64; // currently allocated; java has it as Runtime.totalMemory();
-//                long free = rt.freeMemory(); // unused portion of currently allocated
-//                long totalAvailableBytes = max - total + free;
-//
-//                // by free mem (attempting to not grow the heap for this)
-//                long sortBufferByteSize = free / 2;
-//                const long minBufferSizeBytes = MIN_BUFFER_SIZE_MB * MB;
-//                if (sortBufferByteSize < minBufferSizeBytes || totalAvailableBytes > 10 * minBufferSizeBytes) // lets see if we need/should to grow the heap
-//                {
-//                    if (totalAvailableBytes / 2 > minBufferSizeBytes) // there is enough mem for a reasonable buffer
-//                    {
-//                        sortBufferByteSize = totalAvailableBytes / 2; // grow the heap
-//                    }
-//                    else
-//                    {
-//                        //heap seems smallish lets be conservative fall back to the free/2
-//                        sortBufferByteSize = Math.Max(ABSOLUTE_MIN_SORT_BUFFER_SIZE, sortBufferByteSize);
-//                    }
-//                }
-//                return new BufferSize(Math.Min((long)int.MaxValue, sortBufferByteSize));
-//            }
-//        }
-//
-//        /// <summary>
-//        /// Sort info (debugging mostly).
-//        /// </summary>
-//        public class SortInfo
-//        {
-//            internal bool InstanceFieldsInitialized = false;
-//
-//            internal virtual void InitializeInstanceFields()
-//            {
-//                BufferSize = OuterInstance.RamBufferSize.Bytes;
-//            }
-//
-//            private readonly OfflineSorter OuterInstance;
-//
-//            /// <summary>
-//            /// number of temporary files created when merging partitions </summary>
-//            public int TempMergeFiles;
-//            /// <summary>
-//            /// number of partition merges </summary>
-//            public int MergeRounds;
-//            /// <summary>
-//            /// number of lines of data read </summary>
-//            public int Lines;
-//            /// <summary>
-//            /// time spent merging sorted partitions (in milliseconds) </summary>
-//            public long MergeTime;
-//            /// <summary>
-//            /// time spent sorting data (in milliseconds) </summary>
-//            public long SortTime;
-//            /// <summary>
-//            /// total time spent (in milliseconds) </summary>
-//            public long TotalTime;
-//            /// <summary>
-//            /// time spent in i/o read (in milliseconds) </summary>
-//            public long ReadTime;
-//            /// <summary>
-//            /// read buffer size (in bytes) </summary>
-//            public long BufferSize;
-//
-//            /// <summary>
-//            /// create a new SortInfo (with empty statistics) for debugging </summary>
-//            public SortInfo(OfflineSorter outerInstance)
-//            {
-//                this.OuterInstance = outerInstance;
-//
-//                if (!InstanceFieldsInitialized)
-//                {
-//                    InitializeInstanceFields();
-//                    InstanceFieldsInitialized = true;
-//                }
-//            }
-//
-//            public override string ToString()
-//            {
-//                return string.Format("time=%.2f sec. total (%.2f reading, %.2f sorting, %.2f merging), lines=%d, temp files=%d, merges=%d, soft ram limit=%.2f MB", TotalTime / 1000.0d, ReadTime / 1000.0d, SortTime / 1000.0d, MergeTime / 1000.0d, Lines, TempMergeFiles, MergeRounds, (double)BufferSize / MB);
-//            }
-//        }
-//
-//        private readonly BufferSize RamBufferSize;
-//
-//        private readonly Counter BufferBytesUsed = Counter.NewCounter();
-//        private BytesRefArray Buffer;
-//        private SortInfo sortInfo;
-//        private readonly int MaxTempFiles;
-//        private readonly IComparer<BytesRef> comparator;
-//
-//        /// <summary>
-//        /// Default comparator: sorts in binary (codepoint) order </summary>
-//        public static readonly IComparer<BytesRef> DEFAULT_COMPARATOR = BytesRef.UTF8SortedAsUnicodeComparator.Instance;
-//
-//        /// <summary>
-//        /// Defaults constructor.
-//        /// </summary>
-//        /// <seealso cref= #defaultTempDir() </seealso>
-//        /// <seealso cref= BufferSize#automatic() </seealso>
-//        public OfflineSorter()
-//            : this(DEFAULT_COMPARATOR, BufferSize.Automatic(), DefaultTempDir(), MAX_TEMPFILES)
-//        {
-//            if (!InstanceFieldsInitialized)
-//            {
-//                InitializeInstanceFields();
-//                InstanceFieldsInitialized = true;
-//            }
-//        }
-//
-//        /// <summary>
-//        /// Defaults constructor with a custom comparator.
-//        /// </summary>
-//        /// <seealso cref= #defaultTempDir() </seealso>
-//        /// <seealso cref= BufferSize#automatic() </seealso>
-//        public OfflineSorter(IComparer<BytesRef> comparator)
-//            : this(comparator, BufferSize.Automatic(), DefaultTempDir(), MAX_TEMPFILES)
-//        {
-//            if (!InstanceFieldsInitialized)
-//            {
-//                InitializeInstanceFields();
-//                InstanceFieldsInitialized = true;
-//            }
-//        }
-//
-//        /// <summary>
-//        /// All-details constructor.
-//        /// </summary>
-//        public OfflineSorter(IComparer<BytesRef> comparator, BufferSize ramBufferSize, /*DirectoryInfo tempDirectory,*/ int maxTempfiles)
-//        {
-//            if (!InstanceFieldsInitialized)
-//            {
-//                InitializeInstanceFields();
-//                InstanceFieldsInitialized = true;
-//            }
-//            if (ramBufferSize.Bytes < ABSOLUTE_MIN_SORT_BUFFER_SIZE)
-//            {
-//                throw new System.ArgumentException(MIN_BUFFER_SIZE_MSG + ": " + ramBufferSize.Bytes);
-//            }
-//
-//            if (maxTempfiles < 2)
-//            {
-//                throw new System.ArgumentException("maxTempFiles must be >= 2");
-//            }
-//
-//            this.RamBufferSize = ramBufferSize;
-//            this.MaxTempFiles = maxTempfiles;
-//            this.comparator = comparator;
-//        }
-//
-//        /// <summary>
-//        /// Sort input to output, explicit hint for the buffer size. The amount of allocated
-//        /// memory may deviate from the hint (may be smaller or larger).
-//        /// </summary>
-//        public SortInfo Sort(FileInfo input, FileInfo output)
-//        {
-//            sortInfo = new SortInfo(this) {TotalTime = DateTime.Now.Millisecond};
-//
-//            output.Delete();
-//
-//            var merges = new List<FileInfo>();
-//            bool success2 = false;
-//            try
-//            {
-//                var inputStream = new ByteSequencesReader(input);
-//                bool success = false;
-//                try
-//                {
-//                    int lines = 0;
-//                    while ((lines = ReadPartition(inputStream)) > 0)
-//                    {
-//                        merges.Add(SortPartition(lines));
-//                        sortInfo.TempMergeFiles++;
-//                        sortInfo.Lines += lines;
-//
-//                        // Handle intermediate merges.
-//                        if (merges.Count == MaxTempFiles)
-//                        {
-//                            var intermediate = new FileInfo(Path.GetTempFileName());
-//                            try
-//                            {
-//                                MergePartitions(merges, intermediate);
-//                            }
-//                            finally
-//                            {
-//                                foreach (var file in merges)
-//                                {
-//                                    file.Delete();
-//                                }
-//                                merges.Clear();
-//                                merges.Add(intermediate);
-//                            }
-//                            sortInfo.TempMergeFiles++;
-//                        }
-//                    }
-//                    success = true;
-//                }
-//                finally
-//                {
-//                    if (success)
-//                    {
-//                        IOUtils.Close(inputStream);
-//                    }
-//                    else
-//                    {
-//                        IOUtils.CloseWhileHandlingException(inputStream);
-//                    }
-//                }
-//
-//                // One partition, try to rename or copy if unsuccessful.
-//                if (merges.Count == 1)
-//                {
-//                    FileInfo single = merges[0];
-//                    Copy(single, output);
-//                    try
-//                    {
-//                        File.Delete(single.FullName);
-//                    }
-//                    catch (Exception)
-//                    {
-//                        // ignored
-//                    }
-//                }
-//                else
-//                {
-//                    // otherwise merge the partitions with a priority queue.
-//                    MergePartitions(merges, output);
-//                }
-//                success2 = true;
-//            }
-//            finally
-//            {
-//                foreach (FileInfo file in merges)
-//                {
-//                    file.Delete();
-//                }
-//                if (!success2)
-//                {
-//                    output.Delete();
-//                }
-//            }
-//
-//            sortInfo.TotalTime = (DateTime.Now.Millisecond - sortInfo.TotalTime);
-//            return sortInfo;
-//        }
-//
-//        /// <summary>
-//        /// Returns the default temporary directory. By default, the System's temp folder. If not accessible
-//        /// or not available, an IOException is thrown
-//        /// </summary>
-//        public static DirectoryInfo DefaultTempDir()
-//        {
-//            return new DirectoryInfo(Path.GetTempPath());
-//        }
-//
-//        /// <summary>
-//        /// Copies one file to another.
-//        /// </summary>
-//        private static void Copy(FileInfo file, FileInfo output)
-//        {
-//            File.Copy(file.FullName, output.FullName);
-//        }
-//
-//        /// <summary>
-//        /// Sort a single partition in-memory. </summary>
-//        internal FileInfo SortPartition(int len)
-//        {
-//            var data = this.Buffer;
-//            var tempFile = new FileInfo(Path.GetTempFileName());
-//            //var tempFile1 = File.Create(new ());
-//            //FileInfo tempFile = FileInfo.createTempFile("sort", "partition", TempDirectory);
-//
-//            long start = DateTime.Now.Millisecond;
-//            sortInfo.SortTime += (DateTime.Now.Millisecond - start);
-//
-//            var @out = new ByteSequencesWriter(tempFile);
-//            BytesRef spare;
-//            try
-//            {
-//                BytesRefIterator iter = Buffer.Iterator(comparator);
-//                while ((spare = iter.Next()) != null)
-//                {
-//                    Debug.Assert(spare.Length <= short.MaxValue);
-//                    @out.Write(spare);
-//                }
-//
-//                @out.Dispose();
-//
-//                // Clean up the buffer for the next partition.
-//                data.Clear();
-//                return tempFile;
-//            }
-//            finally
-//            {
-//                IOUtils.Close(@out);
-//            }
-//        }
-//
-//        /// <summary>
-//        /// Merge a list of sorted temporary files (partitions) into an output file </summary>
-//        internal void MergePartitions(IList<FileInfo> merges, FileInfo outputFile)
-//        {
-//            long start = DateTime.Now.Millisecond;
-//
-//            var @out = new ByteSequencesWriter(outputFile);
-//
-//            PriorityQueue<FileAndTop> queue = new PriorityQueueAnonymousInnerClassHelper(this, merges.Count);
-//
-//            var streams = new ByteSequencesReader[merges.Count];
-//            try
-//            {
-//                // Open streams and read the top for each file
-//                for (int i = 0; i < merges.Count; i++)
-//                {
-//                    streams[i] = new ByteSequencesReader(merges[i]);
-//                    sbyte[] line = streams[i].Read();
-//                    if (line != null)
-//                    {
-//                        queue.InsertWithOverflow(new FileAndTop(i, line));
-//                    }
-//                }
-//
-//                // Unix utility sort() uses ordered array of files to pick the next line from, updating
-//                // it as it reads new lines. The PQ used here is a more elegant solution and has
-//                // a nicer theoretical complexity bound :) The entire sorting process is I/O bound anyway
-//                // so it shouldn't make much of a difference (didn't check).
-//                FileAndTop top;
-//                while ((top = queue.Top()) != null)
-//                {
-//                    @out.Write(top.Current);
-//                    if (!streams[top.Fd].Read(top.Current))
-//                    {
-//                        queue.Pop();
-//                    }
-//                    else
-//                    {
-//                        queue.UpdateTop();
-//                    }
-//                }
-//
-//                SortInfo.MergeTime += DateTime.UtcNow.Ticks - start;
-//                SortInfo.MergeRounds++;
-//            }
-//            finally
-//            {
-//                // The logic below is: if an exception occurs in closing out, it has a priority over exceptions
-//                // happening in closing streams.
-//                try
-//                {
-//                    IOUtils.Close(streams);
-//                }
-//                finally
-//                {
-//                    IOUtils.Close(@out);
-//                }
-//            }
-//        }
-//
-//        private class PriorityQueueAnonymousInnerClassHelper : PriorityQueue<FileAndTop>
-//        {
-//            private readonly OfflineSorter OuterInstance;
-//
-//            public PriorityQueueAnonymousInnerClassHelper(OfflineSorter outerInstance, int size)
-//                : base(size)
-//            {
-//                this.OuterInstance = outerInstance;
-//            }
-//
-//            public override bool LessThan(FileAndTop a, FileAndTop b)
-//            {
-//                return OuterInstance.comparator.Compare(a.Current, b.Current) < 0;
-//            }
-//        }
-//
-//        /// <summary>
-//        /// Read in a single partition of data </summary>
-//        internal int ReadPartition(ByteSequencesReader reader)
-//        {
-//            long start = DateTime.Now.Millisecond;
-//            var scratch = new BytesRef();
-//            while ((scratch.Bytes = reader.Read()) != null)
-//            {
-//                scratch.Length = scratch.Bytes.Length;
-//                Buffer.Append(scratch);
-//                // Account for the created objects.
-//                // (buffer slots do not account to buffer size.)
-//                if (RamBufferSize.Bytes < BufferBytesUsed.Get())
-//                {
-//                    break;
-//                }
-//            }
-//            sortInfo.ReadTime += (DateTime.Now.Millisecond - start);
-//            return Buffer.Size();
-//        }
-//
-//        internal class FileAndTop
-//        {
-//            internal readonly int Fd;
-//            internal readonly BytesRef Current;
-//
-//            internal FileAndTop(int fd, sbyte[] firstLine)
-//            {
-//                this.Fd = fd;
-//                this.Current = new BytesRef(firstLine);
-//            }
-//        }
-//
         /// <summary>
         /// Utility class to emit length-prefixed byte[] entries to an output stream for sorting.
         /// Complementary to <seealso cref="ByteSequencesReader"/>.

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.TestFramework/Search/QueryUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Search/QueryUtils.cs b/src/Lucene.Net.TestFramework/Search/QueryUtils.cs
index 6cf5f1d..1156eee 100644
--- a/src/Lucene.Net.TestFramework/Search/QueryUtils.cs
+++ b/src/Lucene.Net.TestFramework/Search/QueryUtils.cs
@@ -470,7 +470,7 @@ namespace Lucene.Net.Search
                 float score = scorer.Score();
                 try
                 {
-                    long startMS = DateTime.Now.Millisecond;
+                    long startMS = Environment.TickCount;
                     for (int i = LastDoc[0] + 1; i <= doc; i++)
                     {
                         Weight w = s.CreateNormalizedWeight(q);
@@ -483,7 +483,7 @@ namespace Lucene.Net.Search
 
                         // Hurry things along if they are going slow (eg
                         // if you got SimpleText codec this will kick in):
-                        if (i < doc && DateTime.Now.Millisecond - startMS > 5)
+                        if (i < doc && Environment.TickCount - startMS > 5)
                         {
                             i = doc - 1;
                         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/Test2BTerms.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/Test2BTerms.cs b/src/Lucene.Net.Tests/core/Index/Test2BTerms.cs
index aa53677..8ed26d3 100644
--- a/src/Lucene.Net.Tests/core/Index/Test2BTerms.cs
+++ b/src/Lucene.Net.Tests/core/Index/Test2BTerms.cs
@@ -217,9 +217,9 @@ namespace Lucene.Net.Index
 
                 for (int i = 0; i < numDocs; i++)
                 {
-                    long t0 = DateTime.Now.Millisecond;
+                    long t0 = Environment.TickCount;
                     w.AddDocument(doc);
-                    Console.WriteLine(i + " of " + numDocs + " " + (DateTime.Now.Millisecond - t0) + " msec");
+                    Console.WriteLine(i + " of " + numDocs + " " + (Environment.TickCount - t0) + " msec");
                 }
                 savedTerms = ts.SavedTerms;
 
@@ -282,14 +282,14 @@ namespace Lucene.Net.Index
             {
                 BytesRef term = terms[Random().Next(terms.Count)];
                 Console.WriteLine("TEST: search " + term);
-                long t0 = DateTime.Now.Millisecond;
+                long t0 = Environment.TickCount;
                 int count = s.Search(new TermQuery(new Term("field", term)), 1).TotalHits;
                 if (count <= 0)
                 {
                     Console.WriteLine("  FAILED: count=" + count);
                     failed = true;
                 }
-                long t1 = DateTime.Now.Millisecond;
+                long t1 = Environment.TickCount;
                 Console.WriteLine("  took " + (t1 - t0) + " millis");
 
                 TermsEnum.SeekStatus result = termsEnum.SeekCeil(term);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestAtomicUpdate.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestAtomicUpdate.cs b/src/Lucene.Net.Tests/core/Index/TestAtomicUpdate.cs
index 9f4b2ed..10a43dc 100644
--- a/src/Lucene.Net.Tests/core/Index/TestAtomicUpdate.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestAtomicUpdate.cs
@@ -49,7 +49,7 @@ namespace Lucene.Net.Index
 
             public override void Run()
             {
-                long stopTime = DateTime.Now.Millisecond + (long)RUN_TIME_MSEC;
+                long stopTime = Environment.TickCount + (long)RUN_TIME_MSEC;
 
                 Count = 0;
 
@@ -63,7 +63,7 @@ namespace Lucene.Net.Index
                         }
                         DoWork();
                         Count++;
-                    } while (DateTime.Now.Millisecond < stopTime);
+                    } while (Environment.TickCount < stopTime);
                 }
                 catch (Exception e)
                 {
@@ -195,7 +195,7 @@ namespace Lucene.Net.Index
           FSDirectory.
         */
 
-        [Test, LongRunningTest]
+        [Test]
         public virtual void TestAtomicUpdates()
         {
             Directory directory;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestDeletionPolicy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestDeletionPolicy.cs b/src/Lucene.Net.Tests/core/Index/TestDeletionPolicy.cs
index a45f0d7..2d17d37 100644
--- a/src/Lucene.Net.Tests/core/Index/TestDeletionPolicy.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestDeletionPolicy.cs
@@ -259,7 +259,6 @@ namespace Lucene.Net.Index
          * Test "by time expiration" deletion policy:
          */
 
-        [Ignore]
         [Test]
         public virtual void TestExpirationTimeDeletionPolicy()
         {
@@ -272,7 +271,7 @@ namespace Lucene.Net.Index
             IndexWriter writer = new IndexWriter(dir, conf);
             ExpirationTimeDeletionPolicy policy = (ExpirationTimeDeletionPolicy)writer.Config.DelPolicy;
             IDictionary<string, string> commitData = new Dictionary<string, string>();
-            commitData["commitTime"] = Convert.ToString(DateTime.Now.Millisecond);
+            commitData["commitTime"] = Convert.ToString(Environment.TickCount);
             writer.CommitData = commitData;
             writer.Commit();
             writer.Dispose();
@@ -283,7 +282,7 @@ namespace Lucene.Net.Index
             {
                 // Record last time when writer performed deletes of
                 // past commits
-                lastDeleteTime = DateTime.Now.Millisecond;
+                lastDeleteTime = Environment.TickCount;
                 conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.APPEND).SetIndexDeletionPolicy(policy);
                 mp = conf.MergePolicy;
                 mp.NoCFSRatio = 1.0;
@@ -294,7 +293,7 @@ namespace Lucene.Net.Index
                     AddDoc(writer);
                 }
                 commitData = new Dictionary<string, string>();
-                commitData["commitTime"] = Convert.ToString(DateTime.Now.Millisecond);
+                commitData["commitTime"] = Convert.ToString(Environment.TickCount);
                 writer.CommitData = commitData;
                 writer.Commit();
                 writer.Dispose();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestDocValuesWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestDocValuesWithThreads.cs b/src/Lucene.Net.Tests/core/Index/TestDocValuesWithThreads.cs
index 014d330..4fc262e 100644
--- a/src/Lucene.Net.Tests/core/Index/TestDocValuesWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestDocValuesWithThreads.cs
@@ -239,13 +239,13 @@ namespace Lucene.Net.Index
 
             AtomicReader sr = GetOnlySegmentReader(r);
 
-            long END_TIME = DateTime.Now.Millisecond + (TEST_NIGHTLY ? 30 : 1);
+            long END_TIME = Environment.TickCount + (TEST_NIGHTLY ? 30 : 1);
 
             int NUM_THREADS = TestUtil.NextInt(Random(), 1, 10);
             ThreadClass[] threads = new ThreadClass[NUM_THREADS];
             for (int thread = 0; thread < NUM_THREADS; thread++)
             {
-                threads[thread] = new ThreadAnonymousInnerClassHelper2(this, random, docValues, sr, END_TIME);
+                threads[thread] = new ThreadAnonymousInnerClassHelper2(random, docValues, sr, END_TIME);
                 threads[thread].Start();
             }
 
@@ -260,16 +260,13 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper2 : ThreadClass
         {
-            private readonly TestDocValuesWithThreads OuterInstance;
-
             private Random Random;
             private IList<BytesRef> DocValues;
             private AtomicReader Sr;
             private long END_TIME;
 
-            public ThreadAnonymousInnerClassHelper2(TestDocValuesWithThreads outerInstance, Random random, IList<BytesRef> docValues, AtomicReader sr, long END_TIME)
+            public ThreadAnonymousInnerClassHelper2(Random random, IList<BytesRef> docValues, AtomicReader sr, long END_TIME)
             {
-                this.OuterInstance = outerInstance;
                 this.Random = random;
                 this.DocValues = docValues;
                 this.Sr = sr;
@@ -291,7 +288,7 @@ namespace Lucene.Net.Index
                 {
                     throw new Exception(ioe.Message, ioe);
                 }
-                while (DateTime.Now.Millisecond < END_TIME)
+                while (Environment.TickCount < END_TIME)
                 {
                     SortedDocValues source;
                     source = stringDVDirect;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestDocumentsWriterStallControl.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestDocumentsWriterStallControl.cs b/src/Lucene.Net.Tests/core/Index/TestDocumentsWriterStallControl.cs
index 14d4458..9c0b80d 100644
--- a/src/Lucene.Net.Tests/core/Index/TestDocumentsWriterStallControl.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestDocumentsWriterStallControl.cs
@@ -68,15 +68,15 @@ namespace Lucene.Net.Index
             for (int i = 0; i < stallThreads.Length; i++)
             {
                 int stallProbability = 1 + Random().Next(10);
-                stallThreads[i] = new ThreadAnonymousInnerClassHelper(this, ctrl, stallProbability);
+                stallThreads[i] = new ThreadAnonymousInnerClassHelper(ctrl, stallProbability);
             }
             Start(stallThreads);
-            long time = DateTime.Now.Millisecond;
+            long time = Environment.TickCount;
             /*
              * use a 100 sec timeout to make sure we not hang forever. join will fail in
              * that case
              */
-            while ((DateTime.Now.Millisecond - time) < 100 * 1000 && !Terminated(stallThreads))
+            while ((Environment.TickCount - time) < 100 * 1000 && !Terminated(stallThreads))
             {
                 ctrl.UpdateStalled(false);
                 if (Random().NextBoolean())
@@ -93,14 +93,11 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestDocumentsWriterStallControl OuterInstance;
-
             private DocumentsWriterStallControl Ctrl;
             private int StallProbability;
 
-            public ThreadAnonymousInnerClassHelper(TestDocumentsWriterStallControl outerInstance, DocumentsWriterStallControl ctrl, int stallProbability)
+            public ThreadAnonymousInnerClassHelper(DocumentsWriterStallControl ctrl, int stallProbability)
             {
-                this.OuterInstance = outerInstance;
                 this.Ctrl = ctrl;
                 this.StallProbability = stallProbability;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
index 4580112..3f898e7 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
@@ -355,23 +355,22 @@ namespace Lucene.Net.Index
         // LUCENE-2095: make sure with multiple threads commit
         // doesn't return until all changes are in fact in the
         // index
-        [Ignore]
         [Test]
         public virtual void TestCommitThreadSafety()
         {
             const int NUM_THREADS = 5;
             const double RUN_SEC = 0.5;
-            Directory dir = NewDirectory();
-            RandomIndexWriter w = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
+            var dir = NewDirectory();
+            var w = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
             TestUtil.ReduceOpenFiles(w.w);
             w.Commit();
-            AtomicBoolean failed = new AtomicBoolean();
-            ThreadClass[] threads = new ThreadClass[NUM_THREADS];
-            long endTime = DateTime.Now.Millisecond + ((long)(RUN_SEC * 1000));
+            var failed = new AtomicBoolean();
+            var threads = new ThreadClass[NUM_THREADS];
+            long endTime = Environment.TickCount + ((long)(RUN_SEC * 1000));
             for (int i = 0; i < NUM_THREADS; i++)
             {
                 int finalI = i;
-                threads[i] = new ThreadAnonymousInnerClassHelper(this, dir, w, failed, endTime, finalI);
+                threads[i] = new ThreadAnonymousInnerClassHelper(dir, w, failed, endTime, finalI);
                 threads[i].Start();
             }
             for (int i = 0; i < NUM_THREADS; i++)
@@ -385,17 +384,14 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestIndexWriterCommit OuterInstance;
-
             private Directory Dir;
             private RandomIndexWriter w;
             private AtomicBoolean Failed;
             private long EndTime;
             private int FinalI;
 
-            public ThreadAnonymousInnerClassHelper(TestIndexWriterCommit outerInstance, Directory dir, RandomIndexWriter w, AtomicBoolean failed, long endTime, int finalI)
+            public ThreadAnonymousInnerClassHelper(Directory dir, RandomIndexWriter w, AtomicBoolean failed, long endTime, int finalI)
             {
-                this.OuterInstance = outerInstance;
                 this.Dir = dir;
                 this.w = w;
                 this.Failed = failed;
@@ -431,7 +427,7 @@ namespace Lucene.Net.Index
                             r = r2;
                             Assert.AreEqual(1, r.DocFreq(new Term("f", s)), "term=f:" + s + "; r=" + r);
                         }
-                    } while (DateTime.Now.Millisecond < EndTime);
+                    } while (Environment.TickCount < EndTime);
                     r.Dispose();
                 }
                 catch (Exception t)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
index 93013d1..2d97f09 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
@@ -844,7 +844,7 @@ namespace Lucene.Net.Index
         }
 
         // Stress test reopen during addIndexes
-        [Test, LongRunningTest]
+        [Test]
         public virtual void TestDuringAddIndexes()
         {
             Directory dir1 = GetAssertNoDeletesDirectory(NewDirectory());
@@ -864,7 +864,7 @@ namespace Lucene.Net.Index
 
             const float SECONDS = 0.5f;
 
-            long endTime = (long)(DateTime.Now.Millisecond + 1000.0 * SECONDS);
+            long endTime = (long)(Environment.TickCount + 1000.0 * SECONDS);
             IList<Exception> excs = new SynchronizedCollection<Exception>();
 
             // Only one thread can addIndexes at a time, because
@@ -872,13 +872,13 @@ namespace Lucene.Net.Index
             var threads = new ThreadClass[1];
             for (int i = 0; i < threads.Length; i++)
             {
-                threads[i] = new ThreadAnonymousInnerClassHelper(this, writer, dirs, endTime, excs);
+                threads[i] = new ThreadAnonymousInnerClassHelper(writer, dirs, endTime, excs);
                 threads[i].SetDaemon(true);
                 threads[i].Start();
             }
 
             int lastCount = 0;
-            while (DateTime.Now.Millisecond < endTime)
+            while (Environment.TickCount < endTime)
             {
                 DirectoryReader r2 = DirectoryReader.OpenIfChanged(r);
                 if (r2 != null)
@@ -924,16 +924,13 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestIndexWriterReader OuterInstance;
-
             private IndexWriter Writer;
             private Directory[] Dirs;
             private long EndTime;
             private IList<Exception> Excs;
 
-            public ThreadAnonymousInnerClassHelper(TestIndexWriterReader outerInstance, IndexWriter writer, Directory[] dirs, long endTime, IList<Exception> excs)
+            public ThreadAnonymousInnerClassHelper(IndexWriter writer, Directory[] dirs, long endTime, IList<Exception> excs)
             {
-                this.OuterInstance = outerInstance;
                 this.Writer = writer;
                 this.Dirs = dirs;
                 this.EndTime = endTime;
@@ -954,7 +951,7 @@ namespace Lucene.Net.Index
                         Excs.Add(t);
                         throw new Exception(t.Message, t);
                     }
-                } while (DateTime.Now.Millisecond < EndTime);
+                } while (Environment.TickCount < EndTime);
             }
         }
 
@@ -968,7 +965,7 @@ namespace Lucene.Net.Index
         }
 
         // Stress test reopen during add/delete
-        [Test, LongRunningTest]
+        [Test]
         public virtual void TestDuringAddDelete()
         {
             Directory dir1 = NewDirectory();
@@ -982,19 +979,19 @@ namespace Lucene.Net.Index
 
             const float SECONDS = 0.5f;
 
-            long endTime = (long)(DateTime.Now.Millisecond + 1000.0 * SECONDS);
+            long endTime = (long)(Environment.TickCount + 1000.0 * SECONDS);
             IList<Exception> excs = new SynchronizedCollection<Exception>();
 
             var threads = new ThreadClass[NumThreads];
             for (int i = 0; i < NumThreads; i++)
             {
-                threads[i] = new ThreadAnonymousInnerClassHelper2(this, writer, r, endTime, excs);
+                threads[i] = new ThreadAnonymousInnerClassHelper2(writer, r, endTime, excs);
                 threads[i].SetDaemon(true);
                 threads[i].Start();
             }
 
             int sum = 0;
-            while (DateTime.Now.Millisecond < endTime)
+            while (Environment.TickCount < endTime)
             {
                 DirectoryReader r2 = DirectoryReader.OpenIfChanged(r);
                 if (r2 != null)
@@ -1032,16 +1029,13 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper2 : ThreadClass
         {
-            private readonly TestIndexWriterReader OuterInstance;
-
             private IndexWriter Writer;
             private DirectoryReader r;
             private long EndTime;
             private IList<Exception> Excs;
 
-            public ThreadAnonymousInnerClassHelper2(TestIndexWriterReader outerInstance, IndexWriter writer, DirectoryReader r, long endTime, IList<Exception> excs)
+            public ThreadAnonymousInnerClassHelper2(IndexWriter writer, DirectoryReader r, long endTime, IList<Exception> excs)
             {
-                this.OuterInstance = outerInstance;
                 this.Writer = writer;
                 this.r = r;
                 this.EndTime = endTime;
@@ -1075,7 +1069,7 @@ namespace Lucene.Net.Index
                         Excs.Add(t);
                         throw new Exception(t.Message, t);
                     }
-                } while (DateTime.Now.Millisecond < EndTime);
+                } while (Environment.TickCount < EndTime);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
index 488c713..ba1d3d2 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
@@ -56,8 +56,6 @@ namespace Lucene.Net.Index
         // Used by test cases below
         private class IndexerThread : ThreadClass
         {
-            private readonly TestIndexWriterWithThreads OuterInstance;
-
             internal bool DiskFull;
             internal Exception Error;
             internal AlreadyClosedException Ace;
@@ -65,9 +63,8 @@ namespace Lucene.Net.Index
             internal bool NoErrors;
             internal volatile int AddCount;
 
-            public IndexerThread(TestIndexWriterWithThreads outerInstance, IndexWriter writer, bool noErrors)
+            public IndexerThread(IndexWriter writer, bool noErrors)
             {
-                this.OuterInstance = outerInstance;
                 this.Writer = writer;
                 this.NoErrors = noErrors;
             }
@@ -85,7 +82,7 @@ namespace Lucene.Net.Index
 
                 int idUpto = 0;
                 int fullCount = 0;
-                long stopTime = DateTime.Now.Millisecond + 200;
+                long stopTime = Environment.TickCount + 200;
 
                 do
                 {
@@ -141,7 +138,7 @@ namespace Lucene.Net.Index
                         }
                         break;
                     }
-                } while (DateTime.Now.Millisecond < stopTime);
+                } while (Environment.TickCount < stopTime);
             }
         }
 
@@ -168,7 +165,7 @@ namespace Lucene.Net.Index
 
                 for (int i = 0; i < NUM_THREADS; i++)
                 {
-                    threads[i] = new IndexerThread(this, writer, true);
+                    threads[i] = new IndexerThread(writer, true);
                 }
 
                 for (int i = 0; i < NUM_THREADS; i++)
@@ -216,7 +213,7 @@ namespace Lucene.Net.Index
 
                 for (int i = 0; i < NUM_THREADS; i++)
                 {
-                    threads[i] = new IndexerThread(this, writer, false);
+                    threads[i] = new IndexerThread(writer, false);
                 }
 
                 for (int i = 0; i < NUM_THREADS; i++)
@@ -297,7 +294,7 @@ namespace Lucene.Net.Index
 
                 for (int i = 0; i < NUM_THREADS; i++)
                 {
-                    threads[i] = new IndexerThread(this, writer, true);
+                    threads[i] = new IndexerThread(writer, true);
                 }
 
                 for (int i = 0; i < NUM_THREADS; i++)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestNRTReaderWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestNRTReaderWithThreads.cs b/src/Lucene.Net.Tests/core/Index/TestNRTReaderWithThreads.cs
index 77e1ae8..bcf2260 100644
--- a/src/Lucene.Net.Tests/core/Index/TestNRTReaderWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestNRTReaderWithThreads.cs
@@ -33,30 +33,28 @@ namespace Lucene.Net.Index
     public class TestNRTReaderWithThreads : LuceneTestCase
     {
         internal AtomicInteger Seq = new AtomicInteger(1);
-
-        [Ignore]
         [Test]
         public virtual void TestIndexing()
         {
             Directory mainDir = NewDirectory();
-            MockDirectoryWrapper wrapper = mainDir as MockDirectoryWrapper;
+            var wrapper = mainDir as MockDirectoryWrapper;
             if (wrapper != null)
             {
                 wrapper.AssertNoDeleteOpenFile = true;
             }
-            IndexWriter writer = new IndexWriter(mainDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(false, 2)));
+            var writer = new IndexWriter(mainDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(false, 2)));
             IndexReader reader = writer.Reader; // start pooling readers
             reader.Dispose();
-            RunThread[] indexThreads = new RunThread[4];
+            var indexThreads = new RunThread[4];
             for (int x = 0; x < indexThreads.Length; x++)
             {
                 indexThreads[x] = new RunThread(this, x % 2, writer);
                 indexThreads[x].Name = "Thread " + x;
                 indexThreads[x].Start();
             }
-            long startTime = DateTime.Now.Millisecond;
+            long startTime = Environment.TickCount;
             long duration = 1000;
-            while ((DateTime.Now.Millisecond - startTime) < duration)
+            while ((Environment.TickCount - startTime) < duration)
             {
                 Thread.Sleep(100);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestNeverDelete.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestNeverDelete.cs b/src/Lucene.Net.Tests/core/Index/TestNeverDelete.cs
index a8716fc..61a5105 100644
--- a/src/Lucene.Net.Tests/core/Index/TestNeverDelete.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestNeverDelete.cs
@@ -37,7 +37,6 @@ namespace Lucene.Net.Index
     // Make sure if you use NoDeletionPolicy that no file
     // referenced by a commit point is ever deleted
 
-    [Ignore]
     [TestFixture]
     public class TestNeverDelete : LuceneTestCase
     {
@@ -59,10 +58,10 @@ namespace Lucene.Net.Index
 
             w.Commit();
             ThreadClass[] indexThreads = new ThreadClass[Random().Next(4)];
-            long stopTime = DateTime.Now.Millisecond + AtLeast(1000);
+            long stopTime = Environment.TickCount + AtLeast(1000);
             for (int x = 0; x < indexThreads.Length; x++)
             {
-                indexThreads[x] = new ThreadAnonymousInnerClassHelper(this, w, stopTime);
+                indexThreads[x] = new ThreadAnonymousInnerClassHelper(w, stopTime);
                 indexThreads[x].Name = "Thread " + x;
                 indexThreads[x].Start();
             }
@@ -70,7 +69,7 @@ namespace Lucene.Net.Index
             HashSet<string> allFiles = new HashSet<string>();
 
             DirectoryReader r = DirectoryReader.Open(d);
-            while (DateTime.Now.Millisecond < stopTime)
+            while (Environment.TickCount < stopTime)
             {
                 IndexCommit ic = r.IndexCommit;
                 if (VERBOSE)
@@ -105,14 +104,11 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestNeverDelete OuterInstance;
-
             private RandomIndexWriter w;
             private long StopTime;
 
-            public ThreadAnonymousInnerClassHelper(TestNeverDelete outerInstance, RandomIndexWriter w, long stopTime)
+            public ThreadAnonymousInnerClassHelper(RandomIndexWriter w, long stopTime)
             {
-                this.OuterInstance = outerInstance;
                 this.w = w;
                 this.StopTime = stopTime;
             }
@@ -122,7 +118,7 @@ namespace Lucene.Net.Index
                 try
                 {
                     int docCount = 0;
-                    while (DateTime.Now.Millisecond < StopTime)
+                    while (Environment.TickCount < StopTime)
                     {
                         Document doc = new Document();
                         doc.Add(NewStringField("dc", "" + docCount, Field.Store.YES));

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestSnapshotDeletionPolicy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestSnapshotDeletionPolicy.cs b/src/Lucene.Net.Tests/core/Index/TestSnapshotDeletionPolicy.cs
index 469e1a5..b03b743 100644
--- a/src/Lucene.Net.Tests/core/Index/TestSnapshotDeletionPolicy.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestSnapshotDeletionPolicy.cs
@@ -130,7 +130,7 @@ namespace Lucene.Net.Index
         private void RunTest(Random random, Directory dir)
         {
             // Run for ~1 seconds
-            long stopTime = DateTime.Now.Millisecond + 1000;
+            long stopTime = Environment.TickCount + 1000;
 
             SnapshotDeletionPolicy dp = DeletionPolicy;
             IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetIndexDeletionPolicy(dp).SetMaxBufferedDocs(2));
@@ -148,7 +148,7 @@ namespace Lucene.Net.Index
             dp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
             writer.Commit();
 
-            ThreadClass t = new ThreadAnonymousInnerClassHelper(this, stopTime, writer);
+            ThreadClass t = new ThreadAnonymousInnerClassHelper(stopTime, writer);
 
             t.Start();
 
@@ -181,14 +181,11 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestSnapshotDeletionPolicy OuterInstance;
-
             private long StopTime;
             private IndexWriter Writer;
 
-            public ThreadAnonymousInnerClassHelper(TestSnapshotDeletionPolicy outerInstance, long stopTime, IndexWriter writer)
+            public ThreadAnonymousInnerClassHelper(long stopTime, IndexWriter writer)
             {
-                this.OuterInstance = outerInstance;
                 this.StopTime = stopTime;
                 this.Writer = writer;
             }
@@ -234,7 +231,7 @@ namespace Lucene.Net.Index
                     {
                         throw new ThreadInterruptedException("Thread Interrupted Exception", ie);
                     }
-                } while (DateTime.Now.Millisecond < StopTime);
+                } while (Environment.TickCount < StopTime);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestStressIndexing.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestStressIndexing.cs b/src/Lucene.Net.Tests/core/Index/TestStressIndexing.cs
index 12c2fa3..1b19afa 100644
--- a/src/Lucene.Net.Tests/core/Index/TestStressIndexing.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestStressIndexing.cs
@@ -50,7 +50,7 @@ namespace Lucene.Net.Index
 
             public override void Run()
             {
-                long stopTime = DateTime.Now.Millisecond + RUN_TIME_MSEC;
+                long stopTime = Environment.TickCount + RUN_TIME_MSEC;
 
                 Count = 0;
 
@@ -64,7 +64,7 @@ namespace Lucene.Net.Index
                         }
                         DoWork();
                         Count++;
-                    } while (DateTime.Now.Millisecond < stopTime);
+                    } while (Environment.TickCount < stopTime);
                 }
                 catch (Exception e)
                 {
@@ -89,15 +89,12 @@ namespace Lucene.Net.Index
 
         private class IndexerThread : TimedThread
         {
-            private readonly TestStressIndexing OuterInstance;
-
             internal IndexWriter Writer;
             internal int NextID;
 
-            public IndexerThread(TestStressIndexing outerInstance, IndexWriter writer, TimedThread[] threads)
+            public IndexerThread(IndexWriter writer, TimedThread[] threads)
                 : base(threads)
             {
-                this.OuterInstance = outerInstance;
                 this.Writer = writer;
             }
 
@@ -160,11 +157,11 @@ namespace Lucene.Net.Index
 
             // One modifier that writes 10 docs then removes 5, over
             // and over:
-            IndexerThread indexerThread = new IndexerThread(this, modifier, threads);
+            IndexerThread indexerThread = new IndexerThread(modifier, threads);
             threads[numThread++] = indexerThread;
             indexerThread.Start();
 
-            IndexerThread indexerThread2 = new IndexerThread(this, modifier, threads);
+            IndexerThread indexerThread2 = new IndexerThread(modifier, threads);
             threads[numThread++] = indexerThread2;
             indexerThread2.Start();
 
@@ -201,7 +198,6 @@ namespace Lucene.Net.Index
         */
 
         [Test]
-        [LongRunningTest]
         public virtual void TestStressIndexAndSearching()
         {
             Directory directory = NewDirectory();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs b/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs
index 8f32a38..46833a0 100644
--- a/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs
@@ -86,7 +86,7 @@ namespace Lucene.Net.Index
     {
         internal virtual void AddDocs(Random random, Directory dir, int ndocs, string field, string val, int maxTF, float percentDocs)
         {
-            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, random, val, maxTF, percentDocs);
+            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(random, val, maxTF, percentDocs);
 
             Document doc = new Document();
 
@@ -104,16 +104,13 @@ namespace Lucene.Net.Index
 
         private class AnalyzerAnonymousInnerClassHelper : Analyzer
         {
-            private readonly TestTermdocPerf OuterInstance;
-
             private Random Random;
             private string Val;
             private int MaxTF;
             private float PercentDocs;
 
-            public AnalyzerAnonymousInnerClassHelper(TestTermdocPerf outerInstance, Random random, string val, int maxTF, float percentDocs)
+            public AnalyzerAnonymousInnerClassHelper(Random random, string val, int maxTF, float percentDocs)
             {
-                this.OuterInstance = outerInstance;
                 this.Random = random;
                 this.Val = val;
                 this.MaxTF = maxTF;
@@ -130,9 +127,9 @@ namespace Lucene.Net.Index
         {
             Directory dir = NewDirectory();
 
-            long start = DateTime.Now.Millisecond;
+            long start = Environment.TickCount;
             AddDocs(Random(), dir, ndocs, "foo", "val", maxTF, percentDocs);
-            long end = DateTime.Now.Millisecond;
+            long end = Environment.TickCount;
             if (VERBOSE)
             {
                 Console.WriteLine("milliseconds for creation of " + ndocs + " docs = " + (end - start));
@@ -142,7 +139,7 @@ namespace Lucene.Net.Index
 
             TermsEnum tenum = MultiFields.GetTerms(reader, "foo").Iterator(null);
 
-            start = DateTime.Now.Millisecond;
+            start = Environment.TickCount;
 
             int ret = 0;
             DocsEnum tdocs = null;
@@ -157,7 +154,7 @@ namespace Lucene.Net.Index
                 }
             }
 
-            end = DateTime.Now.Millisecond;
+            end = Environment.TickCount;
             if (VERBOSE)
             {
                 Console.WriteLine("milliseconds for " + iter + " TermDocs iteration: " + (end - start));

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Index/TestTransactions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestTransactions.cs b/src/Lucene.Net.Tests/core/Index/TestTransactions.cs
index 488472a..2dba7c9 100644
--- a/src/Lucene.Net.Tests/core/Index/TestTransactions.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestTransactions.cs
@@ -74,7 +74,7 @@ namespace Lucene.Net.Index
 
             public override void Run()
             {
-                long stopTime = DateTime.Now.Millisecond + (long)(RUN_TIME_MSEC);
+                long stopTime = Environment.TickCount + (long)(RUN_TIME_MSEC);
 
                 try
                 {
@@ -85,7 +85,7 @@ namespace Lucene.Net.Index
                             break;
                         }
                         DoWork();
-                    } while (DateTime.Now.Millisecond < stopTime);
+                    } while (Environment.TickCount < stopTime);
                 }
                 catch (Exception e)
                 {
@@ -268,6 +268,7 @@ namespace Lucene.Net.Index
         [Test]
         public virtual void TestTransactions_Mem()
         {
+            Console.WriteLine("Start test");
             // we cant use non-ramdir on windows, because this test needs to double-write.
             MockDirectoryWrapper dir1 = new MockDirectoryWrapper(Random(), new RAMDirectory());
             MockDirectoryWrapper dir2 = new MockDirectoryWrapper(Random(), new RAMDirectory());
@@ -312,6 +313,8 @@ namespace Lucene.Net.Index
             }
             dir1.Dispose();
             dir2.Dispose();
+
+            Console.WriteLine("End test");
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Search/TestDateFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestDateFilter.cs b/src/Lucene.Net.Tests/core/Search/TestDateFilter.cs
index ad4d157..baaf0da 100644
--- a/src/Lucene.Net.Tests/core/Search/TestDateFilter.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestDateFilter.cs
@@ -47,7 +47,7 @@ namespace Lucene.Net.Search
             Directory indexStore = NewDirectory();
             RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore);
 
-            long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
+            long now = Environment.TickCount / TimeSpan.TicksPerMillisecond;
 
             Document doc = new Document();
             // add time that is in the past
@@ -111,7 +111,7 @@ namespace Lucene.Net.Search
             Directory indexStore = NewDirectory();
             RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore);
 
-            long now = DateTime.Now.Millisecond;
+            long now = Environment.TickCount;
 
             Document doc = new Document();
             // add time that is in the future

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Search/TestMultiThreadTermVectors.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestMultiThreadTermVectors.cs b/src/Lucene.Net.Tests/core/Search/TestMultiThreadTermVectors.cs
index 795b28a..1071285 100644
--- a/src/Lucene.Net.Tests/core/Search/TestMultiThreadTermVectors.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestMultiThreadTermVectors.cs
@@ -203,16 +203,16 @@ namespace Lucene.Net.Search
             long start = 0L;
             for (int docId = 0; docId < numDocs; docId++)
             {
-                start = DateTime.Now.Millisecond;
+                start = Environment.TickCount;
                 Fields vectors = Reader.GetTermVectors(docId);
-                TimeElapsed += DateTime.Now.Millisecond - start;
+                TimeElapsed += Environment.TickCount - start;
 
                 // verify vectors result
                 VerifyVectors(vectors, docId);
 
-                start = DateTime.Now.Millisecond;
+                start = Environment.TickCount;
                 Terms vector = Reader.GetTermVectors(docId).Terms("field");
-                TimeElapsed += DateTime.Now.Millisecond - start;
+                TimeElapsed += Environment.TickCount - start;
 
                 VerifyVector(vector.Iterator(null), docId);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee1635f4/src/Lucene.Net.Tests/core/Search/TestSearchWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSearchWithThreads.cs b/src/Lucene.Net.Tests/core/Search/TestSearchWithThreads.cs
index f5c34c4..c4d033a 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSearchWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSearchWithThreads.cs
@@ -48,14 +48,13 @@ namespace Lucene.Net.Search
             RUN_TIME_MSEC = AtLeast(1000);
         }
 
-        [Ignore]
         [Test]
         public virtual void Test()
         {
             Directory dir = NewDirectory();
             RandomIndexWriter w = new RandomIndexWriter(Random(), dir);
 
-            long startTime = DateTime.Now.Millisecond;
+            long startTime = Environment.TickCount;
 
             // TODO: replace w/ the @nightly test data; make this
             // into an optional @nightly stress test
@@ -78,7 +77,7 @@ namespace Lucene.Net.Search
             IndexReader r = w.Reader;
             w.Dispose();
 
-            long endTime = DateTime.Now.Millisecond;
+            long endTime = Environment.TickCount;
             if (VERBOSE)
             {
                 Console.WriteLine("BUILD took " + (endTime - startTime));
@@ -140,8 +139,8 @@ namespace Lucene.Net.Search
                 {
                     long totHits = 0;
                     long totSearch = 0;
-                    long stopAt = DateTime.Now.Millisecond + OuterInstance.RUN_TIME_MSEC;
-                    while (DateTime.Now.Millisecond < stopAt && !Failed.Get())
+                    long stopAt = Environment.TickCount + OuterInstance.RUN_TIME_MSEC;
+                    while (Environment.TickCount < stopAt && !Failed.Get())
                     {
                         s.Search(new TermQuery(new Term("body", "aaa")), col);
                         totHits += col.TotalHits;


[2/3] lucenenet git commit: Merge remote-tracking branch 'upstream/master' into timing_fixes

Posted by sy...@apache.org.
Merge remote-tracking branch 'upstream/master' into timing_fixes


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/6133cf8b
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6133cf8b
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6133cf8b

Branch: refs/heads/master
Commit: 6133cf8b66b41f7411f828120fdc7eb78ab6cadf
Parents: ee1635f f963b1d
Author: Laimonas Simutis <la...@gmail.com>
Authored: Sat May 16 13:59:24 2015 -0400
Committer: Laimonas Simutis <la...@gmail.com>
Committed: Sat May 16 13:59:24 2015 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj                           | 2 +-
 .../Taxonomy/Directory/DirectoryTaxonomyWriter.cs               | 2 +-
 .../Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs           | 5 -----
 .../core/Codecs/Lucene41/TestBlockPostingsFormat2.cs            | 4 ++--
 src/Lucene.Net.Tests/core/Index/TestIndexWriter.cs              | 2 +-
 src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs              | 2 +-
 6 files changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6133cf8b/src/Lucene.Net.Tests/core/Index/TestTermdocPerf.cs
----------------------------------------------------------------------


[3/3] lucenenet git commit: put back commented out code

Posted by sy...@apache.org.
put back commented out code


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e3833d6c
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e3833d6c
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e3833d6c

Branch: refs/heads/master
Commit: e3833d6ccac28ed7879336e826cdeb5e3f9bdc77
Parents: 6133cf8
Author: Laimonas Simutis <la...@gmail.com>
Authored: Sat May 16 14:17:00 2015 -0400
Committer: Laimonas Simutis <la...@gmail.com>
Committed: Sat May 16 14:17:00 2015 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/OfflineSorter.cs | 482 +++++++++++++++++++++++++
 1 file changed, 482 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3833d6c/src/Lucene.Net.Core/Util/OfflineSorter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/OfflineSorter.cs b/src/Lucene.Net.Core/Util/OfflineSorter.cs
index afc0159..db0a86b 100644
--- a/src/Lucene.Net.Core/Util/OfflineSorter.cs
+++ b/src/Lucene.Net.Core/Util/OfflineSorter.cs
@@ -34,6 +34,488 @@ namespace Lucene.Net.Util
     /// </summary>
     public sealed class OfflineSorter
     {
+        // LUCENENET TODO: keep this code as it will be used by subprojects once ported
+        //        private bool InstanceFieldsInitialized = false;
+        //
+        //        private void InitializeInstanceFields()
+        //        {
+        //            Buffer = new BytesRefArray(BufferBytesUsed);
+        //        }
+        //
+        //        /// <summary>
+        //        /// Convenience constant for megabytes </summary>
+        //        public const long MB = 1024 * 1024;
+        //        /// <summary>
+        //        /// Convenience constant for gigabytes </summary>
+        //        public static readonly long GB = MB * 1024;
+        //
+        //        /// <summary>
+        //        /// Minimum recommended buffer size for sorting.
+        //        /// </summary>
+        //        public const long MIN_BUFFER_SIZE_MB = 32;
+        //
+        //        /// <summary>
+        //        /// Absolute minimum required buffer size for sorting.
+        //        /// </summary>
+        //        public static readonly long ABSOLUTE_MIN_SORT_BUFFER_SIZE = MB / 2;
+        //        private const string MIN_BUFFER_SIZE_MSG = "At least 0.5MB RAM buffer is needed";
+        //
+        //        /// <summary>
+        //        /// Maximum number of temporary files before doing an intermediate merge.
+        //        /// </summary>
+        //        public const int MAX_TEMPFILES = 128;
+        //
+        //        /// <summary>
+        //        /// A bit more descriptive unit for constructors.
+        //        /// </summary>
+        //        /// <seealso cref= #automatic() </seealso>
+        //        /// <seealso cref= #megabytes(long) </seealso>
+        //        public sealed class BufferSize
+        //        {
+        //            internal readonly int Bytes;
+        //
+        //            internal BufferSize(long bytes)
+        //            {
+        //                if (bytes > int.MaxValue)
+        //                {
+        //                    throw new System.ArgumentException("Buffer too large for Java (" + (int.MaxValue / MB) + "mb max): " + bytes);
+        //                }
+        //
+        //                if (bytes < ABSOLUTE_MIN_SORT_BUFFER_SIZE)
+        //                {
+        //                    throw new System.ArgumentException(MIN_BUFFER_SIZE_MSG + ": " + bytes);
+        //                }
+        //
+        //                this.Bytes = (int)bytes;
+        //            }
+        //
+        //            /// <summary>
+        //            /// Creates a <seealso cref="BufferSize"/> in MB. The given
+        //            /// values must be &gt; 0 and &lt; 2048.
+        //            /// </summary>
+        //            public static BufferSize Megabytes(long mb)
+        //            {
+        //                return new BufferSize(mb * MB);
+        //            }
+        //
+        //            /// <summary>
+        //            /// Approximately half of the currently available free heap, but no less
+        //            /// than <seealso cref="#ABSOLUTE_MIN_SORT_BUFFER_SIZE"/>. However if current heap allocation
+        //            /// is insufficient or if there is a large portion of unallocated heap-space available
+        //            /// for sorting consult with max allowed heap size.
+        //            /// </summary>
+        //            public static BufferSize Automatic()
+        //            {
+        //                var proc = Process.GetCurrentProcess();
+        //
+        //                // take sizes in "conservative" order
+        //                long max = proc.PeakVirtualMemorySize64; // max allocated; java has it as Runtime.maxMemory();
+        //                long total = proc.VirtualMemorySize64; // currently allocated; java has it as Runtime.totalMemory();
+        //                long free = rt.freeMemory(); // unused portion of currently allocated
+        //                long totalAvailableBytes = max - total + free;
+        //
+        //                // by free mem (attempting to not grow the heap for this)
+        //                long sortBufferByteSize = free / 2;
+        //                const long minBufferSizeBytes = MIN_BUFFER_SIZE_MB * MB;
+        //                if (sortBufferByteSize < minBufferSizeBytes || totalAvailableBytes > 10 * minBufferSizeBytes) // lets see if we need/should to grow the heap
+        //                {
+        //                    if (totalAvailableBytes / 2 > minBufferSizeBytes) // there is enough mem for a reasonable buffer
+        //                    {
+        //                        sortBufferByteSize = totalAvailableBytes / 2; // grow the heap
+        //                    }
+        //                    else
+        //                    {
+        //                        //heap seems smallish lets be conservative fall back to the free/2
+        //                        sortBufferByteSize = Math.Max(ABSOLUTE_MIN_SORT_BUFFER_SIZE, sortBufferByteSize);
+        //                    }
+        //                }
+        //                return new BufferSize(Math.Min((long)int.MaxValue, sortBufferByteSize));
+        //            }
+        //        }
+        //
+        //        /// <summary>
+        //        /// Sort info (debugging mostly).
+        //        /// </summary>
+        //        public class SortInfo
+        //        {
+        //            internal bool InstanceFieldsInitialized = false;
+        //
+        //            internal virtual void InitializeInstanceFields()
+        //            {
+        //                BufferSize = OuterInstance.RamBufferSize.Bytes;
+        //            }
+        //
+        //            private readonly OfflineSorter OuterInstance;
+        //
+        //            /// <summary>
+        //            /// number of temporary files created when merging partitions </summary>
+        //            public int TempMergeFiles;
+        //            /// <summary>
+        //            /// number of partition merges </summary>
+        //            public int MergeRounds;
+        //            /// <summary>
+        //            /// number of lines of data read </summary>
+        //            public int Lines;
+        //            /// <summary>
+        //            /// time spent merging sorted partitions (in milliseconds) </summary>
+        //            public long MergeTime;
+        //            /// <summary>
+        //            /// time spent sorting data (in milliseconds) </summary>
+        //            public long SortTime;
+        //            /// <summary>
+        //            /// total time spent (in milliseconds) </summary>
+        //            public long TotalTime;
+        //            /// <summary>
+        //            /// time spent in i/o read (in milliseconds) </summary>
+        //            public long ReadTime;
+        //            /// <summary>
+        //            /// read buffer size (in bytes) </summary>
+        //            public long BufferSize;
+        //
+        //            /// <summary>
+        //            /// create a new SortInfo (with empty statistics) for debugging </summary>
+        //            public SortInfo(OfflineSorter outerInstance)
+        //            {
+        //                this.OuterInstance = outerInstance;
+        //
+        //                if (!InstanceFieldsInitialized)
+        //                {
+        //                    InitializeInstanceFields();
+        //                    InstanceFieldsInitialized = true;
+        //                }
+        //            }
+        //
+        //            public override string ToString()
+        //            {
+        //                return string.Format("time=%.2f sec. total (%.2f reading, %.2f sorting, %.2f merging), lines=%d, temp files=%d, merges=%d, soft ram limit=%.2f MB", TotalTime / 1000.0d, ReadTime / 1000.0d, SortTime / 1000.0d, MergeTime / 1000.0d, Lines, TempMergeFiles, MergeRounds, (double)BufferSize / MB);
+        //            }
+        //        }
+        //
+        //        private readonly BufferSize RamBufferSize;
+        //
+        //        private readonly Counter BufferBytesUsed = Counter.NewCounter();
+        //        private BytesRefArray Buffer;
+        //        private SortInfo sortInfo;
+        //        private readonly int MaxTempFiles;
+        //        private readonly IComparer<BytesRef> comparator;
+        //
+        //        /// <summary>
+        //        /// Default comparator: sorts in binary (codepoint) order </summary>
+        //        public static readonly IComparer<BytesRef> DEFAULT_COMPARATOR = BytesRef.UTF8SortedAsUnicodeComparator.Instance;
+        //
+        //        /// <summary>
+        //        /// Defaults constructor.
+        //        /// </summary>
+        //        /// <seealso cref= #defaultTempDir() </seealso>
+        //        /// <seealso cref= BufferSize#automatic() </seealso>
+        //        public OfflineSorter()
+        //            : this(DEFAULT_COMPARATOR, BufferSize.Automatic(), DefaultTempDir(), MAX_TEMPFILES)
+        //        {
+        //            if (!InstanceFieldsInitialized)
+        //            {
+        //                InitializeInstanceFields();
+        //                InstanceFieldsInitialized = true;
+        //            }
+        //        }
+        //
+        //        /// <summary>
+        //        /// Defaults constructor with a custom comparator.
+        //        /// </summary>
+        //        /// <seealso cref= #defaultTempDir() </seealso>
+        //        /// <seealso cref= BufferSize#automatic() </seealso>
+        //        public OfflineSorter(IComparer<BytesRef> comparator)
+        //            : this(comparator, BufferSize.Automatic(), DefaultTempDir(), MAX_TEMPFILES)
+        //        {
+        //            if (!InstanceFieldsInitialized)
+        //            {
+        //                InitializeInstanceFields();
+        //                InstanceFieldsInitialized = true;
+        //            }
+        //        }
+        //
+        //        /// <summary>
+        //        /// All-details constructor.
+        //        /// </summary>
+        //        public OfflineSorter(IComparer<BytesRef> comparator, BufferSize ramBufferSize, /*DirectoryInfo tempDirectory,*/ int maxTempfiles)
+        //        {
+        //            if (!InstanceFieldsInitialized)
+        //            {
+        //                InitializeInstanceFields();
+        //                InstanceFieldsInitialized = true;
+        //            }
+        //            if (ramBufferSize.Bytes < ABSOLUTE_MIN_SORT_BUFFER_SIZE)
+        //            {
+        //                throw new System.ArgumentException(MIN_BUFFER_SIZE_MSG + ": " + ramBufferSize.Bytes);
+        //            }
+        //
+        //            if (maxTempfiles < 2)
+        //            {
+        //                throw new System.ArgumentException("maxTempFiles must be >= 2");
+        //            }
+        //
+        //            this.RamBufferSize = ramBufferSize;
+        //            this.MaxTempFiles = maxTempfiles;
+        //            this.comparator = comparator;
+        //        }
+        //
+        //        /// <summary>
+        //        /// Sort input to output, explicit hint for the buffer size. The amount of allocated
+        //        /// memory may deviate from the hint (may be smaller or larger).
+        //        /// </summary>
+        //        public SortInfo Sort(FileInfo input, FileInfo output)
+        //        {
+        //            sortInfo = new SortInfo(this) {TotalTime = DateTime.Now.Millisecond};
+        //
+        //            output.Delete();
+        //
+        //            var merges = new List<FileInfo>();
+        //            bool success2 = false;
+        //            try
+        //            {
+        //                var inputStream = new ByteSequencesReader(input);
+        //                bool success = false;
+        //                try
+        //                {
+        //                    int lines = 0;
+        //                    while ((lines = ReadPartition(inputStream)) > 0)
+        //                    {
+        //                        merges.Add(SortPartition(lines));
+        //                        sortInfo.TempMergeFiles++;
+        //                        sortInfo.Lines += lines;
+        //
+        //                        // Handle intermediate merges.
+        //                        if (merges.Count == MaxTempFiles)
+        //                        {
+        //                            var intermediate = new FileInfo(Path.GetTempFileName());
+        //                            try
+        //                            {
+        //                                MergePartitions(merges, intermediate);
+        //                            }
+        //                            finally
+        //                            {
+        //                                foreach (var file in merges)
+        //                                {
+        //                                    file.Delete();
+        //                                }
+        //                                merges.Clear();
+        //                                merges.Add(intermediate);
+        //                            }
+        //                            sortInfo.TempMergeFiles++;
+        //                        }
+        //                    }
+        //                    success = true;
+        //                }
+        //                finally
+        //                {
+        //                    if (success)
+        //                    {
+        //                        IOUtils.Close(inputStream);
+        //                    }
+        //                    else
+        //                    {
+        //                        IOUtils.CloseWhileHandlingException(inputStream);
+        //                    }
+        //                }
+        //
+        //                // One partition, try to rename or copy if unsuccessful.
+        //                if (merges.Count == 1)
+        //                {
+        //                    FileInfo single = merges[0];
+        //                    Copy(single, output);
+        //                    try
+        //                    {
+        //                        File.Delete(single.FullName);
+        //                    }
+        //                    catch (Exception)
+        //                    {
+        //                        // ignored
+        //                    }
+        //                }
+        //                else
+        //                {
+        //                    // otherwise merge the partitions with a priority queue.
+        //                    MergePartitions(merges, output);
+        //                }
+        //                success2 = true;
+        //            }
+        //            finally
+        //            {
+        //                foreach (FileInfo file in merges)
+        //                {
+        //                    file.Delete();
+        //                }
+        //                if (!success2)
+        //                {
+        //                    output.Delete();
+        //                }
+        //            }
+        //
+        //            sortInfo.TotalTime = (DateTime.Now.Millisecond - sortInfo.TotalTime);
+        //            return sortInfo;
+        //        }
+        //
+        //        /// <summary>
+        //        /// Returns the default temporary directory. By default, the System's temp folder. If not accessible
+        //        /// or not available, an IOException is thrown
+        //        /// </summary>
+        //        public static DirectoryInfo DefaultTempDir()
+        //        {
+        //            return new DirectoryInfo(Path.GetTempPath());
+        //        }
+        //
+        //        /// <summary>
+        //        /// Copies one file to another.
+        //        /// </summary>
+        //        private static void Copy(FileInfo file, FileInfo output)
+        //        {
+        //            File.Copy(file.FullName, output.FullName);
+        //        }
+        //
+        //        /// <summary>
+        //        /// Sort a single partition in-memory. </summary>
+        //        internal FileInfo SortPartition(int len)
+        //        {
+        //            var data = this.Buffer;
+        //            var tempFile = new FileInfo(Path.GetTempFileName());
+        //            //var tempFile1 = File.Create(new ());
+        //            //FileInfo tempFile = FileInfo.createTempFile("sort", "partition", TempDirectory);
+        //
+        //            long start = DateTime.Now.Millisecond;
+        //            sortInfo.SortTime += (DateTime.Now.Millisecond - start);
+        //
+        //            var @out = new ByteSequencesWriter(tempFile);
+        //            BytesRef spare;
+        //            try
+        //            {
+        //                BytesRefIterator iter = Buffer.Iterator(comparator);
+        //                while ((spare = iter.Next()) != null)
+        //                {
+        //                    Debug.Assert(spare.Length <= short.MaxValue);
+        //                    @out.Write(spare);
+        //                }
+        //
+        //                @out.Dispose();
+        //
+        //                // Clean up the buffer for the next partition.
+        //                data.Clear();
+        //                return tempFile;
+        //            }
+        //            finally
+        //            {
+        //                IOUtils.Close(@out);
+        //            }
+        //        }
+        //
+        //        /// <summary>
+        //        /// Merge a list of sorted temporary files (partitions) into an output file </summary>
+        //        internal void MergePartitions(IList<FileInfo> merges, FileInfo outputFile)
+        //        {
+        //            long start = DateTime.Now.Millisecond;
+        //
+        //            var @out = new ByteSequencesWriter(outputFile);
+        //
+        //            PriorityQueue<FileAndTop> queue = new PriorityQueueAnonymousInnerClassHelper(this, merges.Count);
+        //
+        //            var streams = new ByteSequencesReader[merges.Count];
+        //            try
+        //            {
+        //                // Open streams and read the top for each file
+        //                for (int i = 0; i < merges.Count; i++)
+        //                {
+        //                    streams[i] = new ByteSequencesReader(merges[i]);
+        //                    sbyte[] line = streams[i].Read();
+        //                    if (line != null)
+        //                    {
+        //                        queue.InsertWithOverflow(new FileAndTop(i, line));
+        //                    }
+        //                }
+        //
+        //                // Unix utility sort() uses ordered array of files to pick the next line from, updating
+        //                // it as it reads new lines. The PQ used here is a more elegant solution and has
+        //                // a nicer theoretical complexity bound :) The entire sorting process is I/O bound anyway
+        //                // so it shouldn't make much of a difference (didn't check).
+        //                FileAndTop top;
+        //                while ((top = queue.Top()) != null)
+        //                {
+        //                    @out.Write(top.Current);
+        //                    if (!streams[top.Fd].Read(top.Current))
+        //                    {
+        //                        queue.Pop();
+        //                    }
+        //                    else
+        //                    {
+        //                        queue.UpdateTop();
+        //                    }
+        //                }
+        //
+        //                SortInfo.MergeTime += DateTime.UtcNow.Ticks - start;
+        //                SortInfo.MergeRounds++;
+        //            }
+        //            finally
+        //            {
+        //                // The logic below is: if an exception occurs in closing out, it has a priority over exceptions
+        //                // happening in closing streams.
+        //                try
+        //                {
+        //                    IOUtils.Close(streams);
+        //                }
+        //                finally
+        //                {
+        //                    IOUtils.Close(@out);
+        //                }
+        //            }
+        //        }
+        //
+        //        private class PriorityQueueAnonymousInnerClassHelper : PriorityQueue<FileAndTop>
+        //        {
+        //            private readonly OfflineSorter OuterInstance;
+        //
+        //            public PriorityQueueAnonymousInnerClassHelper(OfflineSorter outerInstance, int size)
+        //                : base(size)
+        //            {
+        //                this.OuterInstance = outerInstance;
+        //            }
+        //
+        //            public override bool LessThan(FileAndTop a, FileAndTop b)
+        //            {
+        //                return OuterInstance.comparator.Compare(a.Current, b.Current) < 0;
+        //            }
+        //        }
+        //
+        //        /// <summary>
+        //        /// Read in a single partition of data </summary>
+        //        internal int ReadPartition(ByteSequencesReader reader)
+        //        {
+        //            long start = DateTime.Now.Millisecond;
+        //            var scratch = new BytesRef();
+        //            while ((scratch.Bytes = reader.Read()) != null)
+        //            {
+        //                scratch.Length = scratch.Bytes.Length;
+        //                Buffer.Append(scratch);
+        //                // Account for the created objects.
+        //                // (buffer slots do not account to buffer size.)
+        //                if (RamBufferSize.Bytes < BufferBytesUsed.Get())
+        //                {
+        //                    break;
+        //                }
+        //            }
+        //            sortInfo.ReadTime += (DateTime.Now.Millisecond - start);
+        //            return Buffer.Size();
+        //        }
+        //
+        //        internal class FileAndTop
+        //        {
+        //            internal readonly int Fd;
+        //            internal readonly BytesRef Current;
+        //
+        //            internal FileAndTop(int fd, sbyte[] firstLine)
+        //            {
+        //                this.Fd = fd;
+        //                this.Current = new BytesRef(firstLine);
+        //            }
+        //        }
+        //
+
         /// <summary>
         /// Utility class to emit length-prefixed byte[] entries to an output stream for sorting.
         /// Complementary to <seealso cref="ByteSequencesReader"/>.