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/01/06 04:46:19 UTC
[03/18] lucenenet git commit: Cleanup temporary files after test run
Cleanup temporary files after test run
And a few other minor cleanups
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/26de7b85
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/26de7b85
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/26de7b85
Branch: refs/heads/master
Commit: 26de7b85a6c45b13cb425174144ba3cafb96299c
Parents: 7a5aa5c
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 15:42:09 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 15:42:09 2015 +0200
----------------------------------------------------------------------
src/Lucene.Net.Core/Index/SegmentInfos.cs | 4 +-
.../Index/StandardDirectoryReader.cs | 8 +-
.../Util/LuceneTestCase.cs | 90 +++++++++-----------
3 files changed, 45 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.Core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs
index 72ac8ea..c4e29ca 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfos.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs
@@ -348,7 +348,7 @@ namespace Lucene.Net.Index
/// <exception cref="IOException"> if there is a low-level IO error </exception>
public void Read(Directory directory, string segmentFileName)
{
- bool success = false;
+ var success = false;
// Clear any previous segments:
this.Clear();
@@ -357,7 +357,7 @@ namespace Lucene.Net.Index
_lastGeneration = _generation;
- ChecksumIndexInput input = directory.OpenChecksumInput(segmentFileName, IOContext.READ);
+ var input = directory.OpenChecksumInput(segmentFileName, IOContext.READ);
try
{
int format = input.ReadInt();
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs b/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
index c256d7b..72e4b26 100644
--- a/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
+++ b/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
@@ -55,8 +55,8 @@ namespace Lucene.Net.Index
private class FindSegmentsFileAnonymousInnerClassHelper : SegmentInfos.FindSegmentsFile
{
- private new Directory Directory;
- private int TermInfosIndexDivisor;
+ private new readonly Directory Directory;
+ private readonly int TermInfosIndexDivisor;
public FindSegmentsFileAnonymousInnerClassHelper(Directory directory, int termInfosIndexDivisor)
: base(directory)
@@ -67,9 +67,9 @@ namespace Lucene.Net.Index
protected internal override object DoBody(string segmentFileName)
{
- SegmentInfos sis = new SegmentInfos();
+ var sis = new SegmentInfos();
sis.Read(Directory, segmentFileName);
- SegmentReader[] readers = new SegmentReader[sis.Size()];
+ var readers = new SegmentReader[sis.Size()];
for (int i = sis.Size() - 1; i >= 0; i--)
{
System.IO.IOException prior = null;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 42ce3ee..9d829ea 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Lucene.Net.Documents;
using Lucene.Net.Index;
@@ -293,11 +294,11 @@ namespace Lucene.Net.Util
/// </summary>
public static bool VERBOSE = RandomizedTest.SystemPropertyAsBoolean("tests.verbose",
#if DEBUG
- true
+ true
#else
false
#endif
- );
+);
/// <summary>
/// TODO: javadoc? </summary>
@@ -438,10 +439,11 @@ namespace Lucene.Net.Util
/// </summary>
private static TestRuleSetupAndRestoreClassEnv ClassEnvRule;
+ // LUCENENET TODO
/// <summary>
/// Suite failure marker (any error in the test or suite scope).
/// </summary>
- //public static TestRuleMarkFailure SuiteFailureMarker;
+ public static /*TestRuleMarkFailure*/ bool SuiteFailureMarker = true; // Means: was successful
/// <summary>
/// Ignore tests after hitting a designated number of initial failures. this
@@ -576,6 +578,7 @@ namespace Lucene.Net.Util
/* LUCENE TO-DO: Not sure how to convert these
ParentChainCallRule.TeardownCalled = true;
*/
+ CleanupTemporaryFiles();
}
// -----------------------------------------------------------------
@@ -1369,7 +1372,7 @@ namespace Lucene.Net.Util
Type clazz = CommandLineUtil.LoadDirectoryClass(clazzName);
// If it is a FSDirectory type, try its ctor(File)
- if (clazz.IsSubclassOf(typeof (FSDirectory)))
+ if (clazz.IsSubclassOf(typeof(FSDirectory)))
{
DirectoryInfo dir = CreateTempDir("index-" + clazzName);
dir.Create(); // ensure it's created so we 'have' it.
@@ -1377,7 +1380,7 @@ namespace Lucene.Net.Util
}
// try empty ctor
- return (Directory) Activator.CreateInstance(clazz);
+ return (Directory)Activator.CreateInstance(clazz);
}
/// <summary>
@@ -2597,7 +2600,7 @@ namespace Lucene.Net.Util
/// A queue of temporary resources to be removed after the
/// suite completes. </summary>
/// <seealso cref= #registerToRemoveAfterSuite(File) </seealso>
- private static List<FileSystemInfo> CleanupQueue = new List<FileSystemInfo>();
+ private static readonly ConcurrentQueue<string> CleanupQueue = new ConcurrentQueue<string>();
/// <summary>
/// Register temporary folder for removal after the suite completes.
@@ -2612,10 +2615,7 @@ namespace Lucene.Net.Util
return;
}
- lock (CleanupQueue)
- {
- CleanupQueue.Add(f);
- }
+ CleanupQueue.Enqueue(f.FullName);
}
[MethodImpl(MethodImplOptions.NoInlining)]
@@ -2627,59 +2627,47 @@ namespace Lucene.Net.Util
return string.Format("{0}+{1}", this.GetType().Name, sf.GetMethod().Name);
}
- /*private static class TemporaryFilesCleanupRule : TestRuleAdapter
+ private void CleanupTemporaryFiles()
{
- protected void Before()
- {
- base.Before();
- Debug.Assert(TempDirBase == null);
- }
+ // Drain cleanup queue and clear it.
+ var tempDirBasePath = (TempDirBase != null ? TempDirBase.FullName : null);
+ TempDirBase = null;
- protected void AfterAlways(IList<Exception> errors)
+ // Only check and throw an IOException on un-removable files if the test
+ // was successful. Otherwise just report the path of temporary files
+ // and leave them there.
+ if (LuceneTestCase.SuiteFailureMarker /*.WasSuccessful()*/)
{
- // Drain cleanup queue and clear it.
- DirectoryInfo[] everything;
- string tempDirBasePath;
- lock (CleanupQueue)
- {
- tempDirBasePath = (TempDirBase != null ? TempDirBase.FullName : null);
- TempDirBase = null;
-
- CleanupQueue.Reverse();
- everything = new DirectoryInfo[CleanupQueue.Count];
- CleanupQueue.ToArray(everything);
- CleanupQueue.Clear();
- }
-
- // Only check and throw an IOException on un-removable files if the test
- // was successful. Otherwise just report the path of temporary files
- // and leave them there.
- if (LuceneTestCase.SuiteFailureMarker.WasSuccessful())
+ string f;
+ while (CleanupQueue.TryDequeue(out f))
{
try
{
- TestUtil.Rm(everything);
+ if (System.IO.Directory.Exists(f))
+ System.IO.Directory.Delete(f, true);
+ else if (System.IO.File.Exists(f))
+ File.Delete(f);
}
- catch (IOException e)
+ catch (IOException)
{
- Type suiteClass = RandomizedContext.Current.GetTargetType;
- if (suiteClass.isAnnotationPresent(typeof(SuppressTempFileChecks)))
- {
- Console.Error.WriteLine("WARNING: Leftover undeleted temporary files (bugUrl: " + suiteClass.GetAnnotation(typeof(SuppressTempFileChecks)).bugUrl() + "): " + e.Message);
- return;
- }
- throw e;
+ // Type suiteClass = RandomizedContext.Current.GetTargetType;
+ // if (suiteClass.IsAnnotationPresent(typeof(SuppressTempFileChecks)))
+ // {
+ // Console.Error.WriteLine("WARNING: Leftover undeleted temporary files (bugUrl: " + suiteClass.GetAnnotation(typeof(SuppressTempFileChecks)).bugUrl() + "): " + e.Message);
+ // return;
+ // }
+ throw;
}
}
- else
+ }
+ else
+ {
+ if (tempDirBasePath != null)
{
- if (tempDirBasePath != null)
- {
- Console.Error.WriteLine("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
- }
+ Console.Error.WriteLine("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
}
}
- }*/
+ }
}
/*internal class ReaderClosedListenerAnonymousInnerClassHelper : IndexReader.ReaderClosedListener
@@ -2708,7 +2696,7 @@ namespace Lucene.Net.Util
public virtual int Compare(object arg0, object arg1)
{
- return ((IndexableField)arg0).Name().CompareTo(((IndexableField)arg1).Name());
+ return System.String.Compare(((IndexableField)arg0).Name(), ((IndexableField)arg1).Name(), System.StringComparison.Ordinal);
}
}
}
\ No newline at end of file