lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r836138 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/Store/ Test/Index/ Test/Store/ Test/Util/
Date Sat, 14 Nov 2009 08:07:05 GMT
Author: digy
Date: Sat Nov 14 08:07:04 2009
New Revision: 836138

URL: http://svn.apache.org/viewvc?rev=836138&view=rev
Log:
LUCENENET-235 TestIndexWriter.patch
LUCENENET-244 Remaining Tests in Lucene.Net.Store

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
    incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexWriter.cs
    incubator/lucene.net/trunk/C#/src/Test/Store/TestDirectory.cs
    incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs
    incubator/lucene.net/trunk/C#/src/Test/Store/TestRAMDirectory.cs
    incubator/lucene.net/trunk/C#/src/Test/Store/TestWindowsMMap.cs
    incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/FSDirectory.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs Sat Nov 14 08:07:04
2009
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Generic;
 
 // Used only for WRITE_LOCK_NAME in deprecated create=true case:
 using IndexFileNameFilter = Lucene.Net.Index.IndexFileNameFilter;
@@ -119,7 +120,7 @@
 		/// </summary>
 		/// <deprecated> Not used by any non-deprecated methods anymore
 		/// </deprecated>
-		private static readonly System.Collections.IDictionary DIRECTORIES = new System.Collections.Hashtable();
+        private static readonly Dictionary<string, FSDirectory> DIRECTORIES = new Dictionary<string,
FSDirectory>();
 		
 		private static bool disableLocks = false;
 		
@@ -171,7 +172,7 @@
 		
 		/// <summary>The default class which implements filesystem-based directories. </summary>
 		// deprecated
-		private static readonly System.Type IMPL = typeof(Lucene.Net.Store.FSDirectory);
+        private static readonly System.Type IMPL = typeof(Lucene.Net.Store.SimpleFSDirectory);
 		
 		private static System.Security.Cryptography.HashAlgorithm DIGESTER;
 		
@@ -278,21 +279,20 @@
         public static FSDirectory GetDirectory(System.IO.DirectoryInfo file, LockFactory
lockFactory)
         {
             FSDirectory dir;
-            lock (DIRECTORIES.SyncRoot)
+            lock (DIRECTORIES)
             {
-                dir = (FSDirectory)DIRECTORIES[file];
-                if (dir == null)
+                if(!DIRECTORIES.TryGetValue(file.FullName, out dir))
                 {
                     try
                     {
-                        dir = (FSDirectory)System.Activator.CreateInstance(IMPL);
+                        dir = (FSDirectory)System.Activator.CreateInstance(IMPL, true);
                     }
                     catch (System.Exception e)
                     {
                         throw new System.SystemException("cannot load FSDirectory class:
" + e.ToString(), e);
                     }
                     dir.Init(file, lockFactory);
-                    DIRECTORIES[file] = dir;
+                    DIRECTORIES.Add(file.FullName, dir);
                 }
                 else
                 {
@@ -409,21 +409,11 @@
 		{
 			if (!checked_Renamed)
 			{
-				bool tmpBool;
-				if (System.IO.File.Exists(directory.FullName))
-					tmpBool = true;
-				else
-					tmpBool = System.IO.Directory.Exists(directory.FullName);
-				if (!tmpBool)
-				{
-					try {
-                        System.IO.Directory.CreateDirectory(directory.FullName);
-                    }
-                    catch (Exception)
-                    {
-						throw new System.IO.IOException("Cannot create directory: " + directory);
-                    }
-				}
+                if (!this.directory.Exists)
+                {
+                    this.directory.Create();
+                    this.directory.Refresh(); // need to see the creation
+                }
 				
 				checked_Renamed = true;
 			}
@@ -437,27 +427,10 @@
 			EnsureOpen();
 			CreateDir();
 			System.IO.FileInfo file = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
name));
-			bool tmpBool;
-			if (System.IO.File.Exists(file.FullName))
-				tmpBool = true;
-			else
-				tmpBool = System.IO.Directory.Exists(file.FullName);
-			bool tmpBool2;
-			if (System.IO.File.Exists(file.FullName))
-			{
-				System.IO.File.Delete(file.FullName);
-				tmpBool2 = true;
-			}
-			else if (System.IO.Directory.Exists(file.FullName))
-			{
-				System.IO.Directory.Delete(file.FullName);
-				tmpBool2 = true;
-			}
-			else
-				tmpBool2 = false;
-			if (tmpBool && !tmpBool2)
-			// delete existing, if any
-				throw new System.IO.IOException("Cannot overwrite: " + file);
+            if (file.Exists)
+            {
+                file.Delete(); // handled by caller if error
+            }
 		}
 		
 		/// <summary>The underlying filesystem directory </summary>
@@ -495,6 +468,9 @@
 		/// <summary>Creates an FSDirectory instance, trying to pick the
 		/// best implementation given the current environment.
 		/// The directory returned uses the {@link NativeFSLockFactory}.
+        /// 
+        /// <p>Currently this returns {@link SimpleFSDirectory} as
+        /// NIOFSDirectory is currently not supported.
 		/// 
 		/// <p>Currently this returns {@link SimpleFSDirectory} as
 		/// NIOFSDirectory is currently not supported.
@@ -563,7 +539,7 @@
 			{
 				return new NIOFSDirectory(path, lockFactory);
 			}
-		}
+        }
 		
 		/* will move to ctor, when reflection is removed in 3.0 */
 		private void  Init(System.IO.DirectoryInfo path, LockFactory lockFactory)
@@ -723,12 +699,7 @@
 		{
 			EnsureOpen();
 			System.IO.FileInfo file = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
name));
-			bool tmpBool;
-			if (System.IO.File.Exists(file.FullName))
-				tmpBool = true;
-			else
-				tmpBool = System.IO.Directory.Exists(file.FullName);
-			return tmpBool;
+            return file.Exists;
 		}
 		
 		/// <summary>Returns the time the named file was last modified. </summary>
@@ -767,21 +738,7 @@
 		{
 			EnsureOpen();
 			System.IO.FileInfo file = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
name));
-			bool tmpBool;
-			if (System.IO.File.Exists(file.FullName))
-			{
-				System.IO.File.Delete(file.FullName);
-				tmpBool = true;
-			}
-			else if (System.IO.Directory.Exists(file.FullName))
-			{
-				System.IO.Directory.Delete(file.FullName);
-				tmpBool = true;
-			}
-			else
-				tmpBool = false;
-			if (!tmpBool)
-				throw new System.IO.IOException("Cannot delete " + file);
+            file.Delete();
 		}
 		
 		/// <summary>Renames an existing file in the directory. 
@@ -794,118 +751,8 @@
 			lock (this)
 			{
 				EnsureOpen();
-				System.IO.FileInfo old = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
from));
-				System.IO.FileInfo nu = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
to));
-				
-				/* This is not atomic.  If the program crashes between the call to
-				delete() and the call to renameTo() then we're screwed, but I've
-				been unable to figure out how else to do this... */
-				
-				bool tmpBool;
-				if (System.IO.File.Exists(nu.FullName))
-					tmpBool = true;
-				else
-					tmpBool = System.IO.Directory.Exists(nu.FullName);
-				if (tmpBool)
-				{
-					bool tmpBool2;
-					if (System.IO.File.Exists(nu.FullName))
-					{
-						System.IO.File.Delete(nu.FullName);
-						tmpBool2 = true;
-					}
-					else if (System.IO.Directory.Exists(nu.FullName))
-					{
-						System.IO.Directory.Delete(nu.FullName);
-						tmpBool2 = true;
-					}
-					else
-						tmpBool2 = false;
-					if (!tmpBool2)
-						throw new System.IO.IOException("Cannot delete " + nu);
-				}
-				
-				// Rename the old file to the new one. Unfortunately, the renameTo()
-				// method does not work reliably under some JVMs.  Therefore, if the
-				// rename fails, we manually rename by copying the old file to the new one
-                try
-                {
-                    old.MoveTo(nu.FullName);
-                }
-                catch
-				{
-					System.IO.Stream in_Renamed = null;
-					System.IO.Stream out_Renamed = null;
-					try
-					{
-						in_Renamed = new System.IO.FileStream(old.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
-						out_Renamed = new System.IO.FileStream(nu.FullName, System.IO.FileMode.Create);
-						// see if the buffer needs to be initialized. Initialization is
-						// only done on-demand since many VM's will never run into the renameTo
-						// bug and hence shouldn't waste 1K of mem for no reason.
-						if (buffer == null)
-						{
-							buffer = new byte[1024];
-						}
-						int len;
-						while ((len = in_Renamed.Read(buffer, 0, buffer.Length)) >= 0)
-						{
-							out_Renamed.Write(buffer, 0, len);
-						}
-						
-						// delete the old file.
-						bool tmpBool3;
-						if (System.IO.File.Exists(old.FullName))
-						{
-							System.IO.File.Delete(old.FullName);
-							tmpBool3 = true;
-						}
-						else if (System.IO.Directory.Exists(old.FullName))
-						{
-							System.IO.Directory.Delete(old.FullName);
-							tmpBool3 = true;
-						}
-						else
-							tmpBool3 = false;
-						bool generatedAux = tmpBool3;
-					}
-					catch (System.IO.IOException ioe)
-					{
-						System.IO.IOException newExc = new System.IO.IOException("Cannot rename " + old + "
to " + nu, ioe);
-						throw newExc;
-					}
-					finally
-					{
-						try
-						{
-							if (in_Renamed != null)
-							{
-								try
-								{
-									in_Renamed.Close();
-								}
-								catch (System.IO.IOException e)
-								{
-									throw new System.SystemException("Cannot close input stream: " + e.ToString(), e);
-								}
-							}
-						}
-						finally
-						{
-							if (out_Renamed != null)
-							{
-								try
-								{
-									out_Renamed.Close();
-								}
-								catch (System.IO.IOException e)
-								{
-									throw new System.SystemException("Cannot close output stream: " + e.ToString(),
e);
-								}
-							}
-						}
-					}
-				}
+                System.IO.FileInfo old = new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName,
from));
+                old.MoveTo(System.IO.Path.Combine(directory.FullName, to));
 			}
 		}
 		
@@ -1045,20 +892,22 @@
 				if (isOpen && --refCount <= 0)
 				{
 					isOpen = false;
-					lock (DIRECTORIES.SyncRoot)
+					lock (DIRECTORIES)
 					{
-						DIRECTORIES.Remove(directory);
+						DIRECTORIES.Remove(directory.FullName);
 					}
 				}
 			}
 		}
-		
+
+        [System.Obsolete("A DirectoryInfo is more appropriate, however this is here for backwards
compatibility. This will be removed in the 3.0 release")]
 		public virtual System.IO.FileInfo GetFile()
 		{
 			EnsureOpen();
 			return new System.IO.FileInfo(directory.FullName);
 		}
 
+
         // Java Lucene implements GetFile() which returns a FileInfo.
         // For Lucene.Net, GetDirectory() is more appropriate
         public virtual System.IO.DirectoryInfo GetDirectory()

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestIndexWriter.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexWriter.cs Sat Nov 14 08:07:04 2009
@@ -420,6 +420,10 @@
 		public TestIndexWriter(System.String name):base(name, testWithNewApiData)
 		{
 		}
+
+        public TestIndexWriter() : base("", testWithNewApiData)
+        {
+        }
 		
         [Test]
 		public virtual void  TestDocCount()
@@ -4569,7 +4573,7 @@
 			
 			internal virtual void  LaunchThreads(int numIter)
 			{
-				
+                threads = new SupportClass.ThreadClass[NUM_THREADS]; //{{DIGY}} Should this
be created somewhere else?
 				for (int i = 0; i < NUM_THREADS; i++)
 				{
 					threads[i] = new AnonymousClassThread2(numIter, this);

Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestDirectory.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestDirectory.cs Sat Nov 14 08:07:04 2009
@@ -69,7 +69,7 @@
 			dirs[0] = new SimpleFSDirectory(path, null);
 			// dirs[1] = new NIOFSDirectory(path, null);
             System.Console.WriteLine("Skipping NIOFSDirectory() test under Lucene.Net");
-			dirs[2] = new MMapDirectory(path, null);
+			dirs[1] = new MMapDirectory(path, null);
 			
 			for (int i = 0; i < sz; i++)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestLockFactory.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs Sat Nov 14 08:07:04 2009
@@ -428,7 +428,7 @@
 			System.IO.FileInfo fdir2 = _TestUtil.GetTempDir("TestLockFactory.8.Lockdir");
 			Directory dir1 = FSDirectory.Open(new System.IO.DirectoryInfo(fdir1.FullName), new NativeFSLockFactory(fdir1));
 			// same directory, but locks are stored somewhere else. The prefix of the lock factory
should != null
-			Directory dir2 = FSDirectory.Open(new System.IO.DirectoryInfo(fdir2.FullName), new NativeFSLockFactory(fdir2));
+			Directory dir2 = FSDirectory.Open(new System.IO.DirectoryInfo(fdir1.FullName), new NativeFSLockFactory(fdir2));
 			
 			System.String prefix1 = dir1.GetLockFactory().GetLockPrefix();
 			Assert.IsNull(prefix1, "Lock prefix for lockDir same as directory should be null");

Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestRAMDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestRAMDirectory.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestRAMDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestRAMDirectory.cs Sat Nov 14 08:07:04 2009
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.IO;
 
 using NUnit.Framework;
 
@@ -94,14 +95,14 @@
 		private int docsToAdd = 500;
 		
 		// setup the index
-		[Test]
+		[SetUp]
 		public override void  SetUp()
 		{
 			base.SetUp();
 			System.String tempDir = System.IO.Path.GetTempPath();
 			if (tempDir == null)
 				throw new System.IO.IOException("java.io.tmpdir undefined, cannot run test");
-			indexDir = new System.IO.FileInfo(tempDir + "\\" + "RAMDirIndex");
+			indexDir = new System.IO.FileInfo(Path.Combine(tempDir, "RAMDirIndex"));
 			
 			IndexWriter writer = new IndexWriter(indexDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			// add some documents
@@ -255,15 +256,10 @@
 		{
 			base.TearDown();
 			// cleanup 
-			bool tmpBool;
-			if (System.IO.File.Exists(indexDir.FullName))
-				tmpBool = true;
-			else
-				tmpBool = System.IO.Directory.Exists(indexDir.FullName);
-			if (indexDir != null && tmpBool)
-			{
-				RmDir(indexDir);
-			}
+            if(System.IO.Directory.Exists(indexDir.FullName))
+            {
+                System.IO.Directory.Delete(indexDir.FullName, true);
+            }
 		}
 		
 		// LUCENE-1196
@@ -280,41 +276,5 @@
 			i.Close();
 			dir.Close();
 		}
-		
-		private void  RmDir(System.IO.FileInfo dir)
-		{
-			System.IO.FileInfo[] files = SupportClass.FileSupport.GetFiles(dir);
-			for (int i = 0; i < files.Length; i++)
-			{
-				bool tmpBool;
-				if (System.IO.File.Exists(files[i].FullName))
-				{
-					System.IO.File.Delete(files[i].FullName);
-					tmpBool = true;
-				}
-				else if (System.IO.Directory.Exists(files[i].FullName))
-				{
-					System.IO.Directory.Delete(files[i].FullName);
-					tmpBool = true;
-				}
-				else
-					tmpBool = false;
-				bool generatedAux = tmpBool;
-			}
-			bool tmpBool2;
-			if (System.IO.File.Exists(dir.FullName))
-			{
-				System.IO.File.Delete(dir.FullName);
-				tmpBool2 = true;
-			}
-			else if (System.IO.Directory.Exists(dir.FullName))
-			{
-				System.IO.Directory.Delete(dir.FullName);
-				tmpBool2 = true;
-			}
-			else
-				tmpBool2 = false;
-			bool generatedAux2 = tmpBool2;
-		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestWindowsMMap.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestWindowsMMap.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestWindowsMMap.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestWindowsMMap.cs Sat Nov 14 08:07:04 2009
@@ -36,7 +36,7 @@
 		private const System.String alphabet = "abcdefghijklmnopqrstuvwzyz";
 		private System.Random random;
 		
-		[Test]
+		[SetUp]
 		public override void  SetUp()
 		{
 			base.SetUp();

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/LuceneTestCase.cs?rev=836138&r1=836137&r2=836138&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs Sat Nov 14 08:07:04 2009
@@ -116,6 +116,7 @@
 			
 			TokenStream.SetOnlyUseNewAPI(savedAPISetting);
 			//base.TearDown();  // {{Aroush-2.9}}
+            this.seed_init = false;
 		}
 		
 		/// <summary> Asserts that FieldCacheSanityChecker does not detect any 



Mime
View raw message