Exemple #1
0
        public virtual void TestNotDirectory()
        {
            //File path = CreateTempDir("testnotdir");
            DirectoryInfo path  = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "testnotdir"));
            Directory     fsDir = new SimpleFSDirectory(path, null);

            try
            {
                IndexOutput @out = fsDir.CreateOutput("afile", NewIOContext(Random()));
                @out.Dispose();
                Assert.IsTrue(SlowFileExists(fsDir, "afile"));
                try
                {
                    new SimpleFSDirectory(new DirectoryInfo(Path.Combine(path.FullName, "afile")), null);
                    Assert.Fail("did not hit expected exception");
                }
                catch (NoSuchDirectoryException nsde)
                {
                    // Expected
                }
            }
            finally
            {
                fsDir.Dispose();
                System.IO.Directory.Delete(path.FullName, true);
            }
        }
Exemple #2
0
        public virtual void  TestNotDirectory()
        {
            System.IO.FileInfo path  = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testnotdir"));
            Directory          fsDir = new SimpleFSDirectory(path, null);

            try
            {
                IndexOutput out_Renamed = fsDir.CreateOutput("afile");
                out_Renamed.Close();
                Assert.IsTrue(fsDir.FileExists("afile"));
                try
                {
                    new SimpleFSDirectory(new System.IO.FileInfo(System.IO.Path.Combine(path.FullName, "afile")), null);
                    Assert.Fail("did not hit expected exception");
                }
                catch (NoSuchDirectoryException nsde)
                {
                    // Expected
                }
            }
            finally
            {
                fsDir.Close();
                _TestUtil.RmDir(path);
            }
        }
Exemple #3
0
        public virtual void TestNotDirectory()
        {
            DirectoryInfo path  = CreateTempDir("testnotdir");
            Directory     fsDir = new SimpleFSDirectory(path, null);

            try
            {
                IndexOutput @out = fsDir.CreateOutput("afile", NewIOContext(Random()));
                @out.Dispose();
                Assert.IsTrue(SlowFileExists(fsDir, "afile"));
                try
                {
                    var d = new SimpleFSDirectory(new DirectoryInfo(Path.Combine(path.FullName, "afile")), null);
                    Assert.Fail("did not hit expected exception");
                }
#pragma warning disable 168
                catch (DirectoryNotFoundException nsde)
#pragma warning restore 168
                {
                    // Expected
                }
            }
            finally
            {
                fsDir.Dispose();
                System.IO.Directory.Delete(path.FullName, true);
            }
        }
Exemple #4
0
        public virtual void ConcurrentIndexAccessThrowsWithoutSynchronizedStaleFiles()
        {
            DirectoryInfo tempDir = CreateTempDir(GetType().Name);

            using (Directory dir = new SimpleFSDirectory(tempDir))
            {
                var       ioContext = NewIOContext(Random());
                var       threads   = new Thread[Environment.ProcessorCount];
                int       file      = 0;
                Exception exception = null;
                bool      stopped   = false;

                using (var @event = new ManualResetEvent(false))
                {
                    for (int i = 0; i < threads.Length; i++)
                    {
                        var thread = new Thread(() =>
                        {
                            while (!stopped)
                            {
                                int nextFile = Interlocked.Increment(ref file);
                                try
                                {
                                    dir.CreateOutput("test" + nextFile, ioContext).Dispose();
                                }
                                catch (Exception ex)
                                {
                                    exception = ex;
                                    @event.Set();
                                    break;
                                }
                            }
                        });
                        thread.Start();
                        threads[i] = thread;
                    }

                    bool raised = @event.WaitOne(TimeSpan.FromSeconds(5));

                    stopped = true;

                    if (raised)
                    {
                        throw new Exception("Test failed", exception);
                    }
                }

                foreach (var thread in threads)
                {
                    thread.Join();
                }
            }
        }
Exemple #5
0
        public virtual void TestFsyncDoesntCreateNewFiles()
        {
            var path = CreateTempDir("nocreate");

            Console.WriteLine(path.FullName);

            using (Directory fsdir = new SimpleFSDirectory(path))
            {
                // write a file
                using (var o = fsdir.CreateOutput("afile", NewIOContext(Random())))
                {
                    o.WriteString("boo");
                }

                // delete it
                try
                {
                    File.Delete(Path.Combine(path.FullName, "afile"));
                }
                catch (Exception e)
                {
                    Assert.Fail("Deletion of new Directory should never fail.\nException thrown: {0}", e);
                }

                // directory is empty
                Assert.AreEqual(0, fsdir.ListAll().Length);


                // LUCENENET specific: Since FSDirectory.Sync() does not actually do anything in .NET
                // we decided to remove the exception as well. This is safe to ignore here.
                //// fsync it
                //try
                //{
                //    fsdir.Sync(Collections.Singleton("afile"));
                //    Assert.Fail("didn't get expected exception, instead fsync created new files: " +
                //                Collections.ToString(fsdir.ListAll()));
                //}
                //catch (FileNotFoundException)
                //{
                //    // ok
                //}
                //// LUCENENET specific - since NoSuchDirectoryException subclasses FileNotFoundException
                //// in Lucene, we need to catch it here to be on the safe side.
                //catch (System.IO.DirectoryNotFoundException)
                //{
                //    // ok
                //}

                // directory is still empty
                Assert.AreEqual(0, fsdir.ListAll().Length);
            }
        }
Exemple #6
0
 public void TestFSDirectorySync()
 {
     System.IO.FileInfo         path      = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testsync"));
     Lucene.Net.Store.Directory directory = new Lucene.Net.Store.SimpleFSDirectory(path, null);
     try
     {
         Lucene.Net.Store.IndexOutput io = directory.CreateOutput("syncfile");
         io.Close();
         directory.Sync("syncfile");
     }
     finally
     {
         directory.Close();
         Lucene.Net.Util._TestUtil.RmDir(path);
     }
 }
Exemple #7
0
        public virtual void TestFsyncDoesntCreateNewFiles()
        {
            //File path = CreateTempDir("nocreate");
            DirectoryInfo path = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "nocreate"));

            Console.WriteLine(path.FullName);
            Directory fsdir = new SimpleFSDirectory(path);

            // write a file
            IndexOutput @out = fsdir.CreateOutput("afile", NewIOContext(Random()));

            @out.WriteString("boo");
            @out.Dispose();

            // delete it
            try
            {
                var newDir = new DirectoryInfo(Path.Combine(path.FullName, "afile"));
                newDir.Create();
                newDir.Delete();
            }
            catch (Exception)
            {
                Assert.Fail("Deletion of new Directory should never fail.");
            }

            // directory is empty
            Assert.AreEqual(0, fsdir.ListAll().Length);

            // fsync it
            try
            {
                fsdir.Sync(CollectionsHelper.Singleton("afile"));
                Assert.Fail("didn't get expected exception, instead fsync created new files: " + Arrays.AsList(fsdir.ListAll()));
            }
            catch (FileNotFoundException /*| NoSuchFileException*/ expected)
            {
                // ok
            }

            // directory is still empty
            Assert.AreEqual(0, fsdir.ListAll().Length);

            fsdir.Dispose();
        }
Exemple #8
0
        public virtual void TestFsyncDoesntCreateNewFiles()
        {
            var path = CreateTempDir("nocreate");

            Console.WriteLine(path.FullName);

            using (Directory fsdir = new SimpleFSDirectory(path))
            {
                // write a file
                using (var o = fsdir.CreateOutput("afile", NewIOContext(Random())))
                {
                    o.WriteString("boo");
                }

                // delete it
                try
                {
                    File.Delete(Path.Combine(path.FullName, "afile"));
                }
                catch (Exception e)
                {
                    Assert.Fail("Deletion of new Directory should never fail.\nException thrown: {0}", e);
                }

                // directory is empty
                Assert.AreEqual(0, fsdir.ListAll().Length);

                // fsync it
                try
                {
                    fsdir.Sync(Collections.Singleton("afile"));
                    Assert.Fail("didn't get expected exception, instead fsync created new files: " +
                                Arrays.AsList(fsdir.ListAll()));
                }
                catch (FileNotFoundException)
                {
                    // ok
                }

                // directory is still empty
                Assert.AreEqual(0, fsdir.ListAll().Length);
            }
        }
Exemple #9
0
        public virtual void  TestNotDirectory()
        {
            System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testnotdir"));
            Directory fsDir = new SimpleFSDirectory(path, null);

            try
            {
                IndexOutput out_Renamed = fsDir.CreateOutput("afile", null);
                out_Renamed.Close();
                Assert.IsTrue(fsDir.FileExists("afile", null));

                Assert.Throws <NoSuchDirectoryException>(
                    () =>
                    new SimpleFSDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(path.FullName, "afile")), null),
                    "did not hit expected exception");
            }
            finally
            {
                fsDir.Close();
                _TestUtil.RmDir(path);
            }
        }
		public virtual void  TestNotDirectory()
		{
			System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testnotdir"));
			Directory fsDir = new SimpleFSDirectory(path, null);
			try
			{
				IndexOutput out_Renamed = fsDir.CreateOutput("afile");
				out_Renamed.Close();
				Assert.IsTrue(fsDir.FileExists("afile"));

			    Assert.Throws<NoSuchDirectoryException>(
			        () =>
			        new SimpleFSDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(path.FullName, "afile")), null),
			        "did not hit expected exception");
			}
			finally
			{
				fsDir.Close();
				_TestUtil.RmDir(path);
			}
		}
        public virtual void TestFsyncDoesntCreateNewFiles()
        {
            var path = CreateTempDir("nocreate");
            Console.WriteLine(path.FullName);

            using (Directory fsdir = new SimpleFSDirectory(path))
            {
                // write a file
                using (var o = fsdir.CreateOutput("afile", NewIOContext(Random())))
                {
                    o.WriteString("boo");
                }

                // delete it
                try
                {
                    File.Delete(Path.Combine(path.FullName, "afile"));
                }
                catch (Exception e)
                {
                    Assert.Fail("Deletion of new Directory should never fail.\nException thrown: {0}", e);
                }

                // directory is empty
                Assert.AreEqual(0, fsdir.ListAll().Length);

                // fsync it
                try
                {
                    fsdir.Sync(Collections.Singleton("afile"));
                    Assert.Fail("didn't get expected exception, instead fsync created new files: " +
                                Arrays.AsList(fsdir.ListAll()));
                }
                catch (FileNotFoundException)
                {
                    // ok
                }

                // directory is still empty
                Assert.AreEqual(0, fsdir.ListAll().Length);
            }
        }
 public virtual void TestNotDirectory()
 {
     DirectoryInfo path = CreateTempDir("testnotdir");
     Directory fsDir = new SimpleFSDirectory(path, null);
     try
     {
         IndexOutput @out = fsDir.CreateOutput("afile", NewIOContext(Random()));
         @out.Dispose();
         Assert.IsTrue(SlowFileExists(fsDir, "afile"));
         try
         {
             var d = new SimpleFSDirectory(new DirectoryInfo(Path.Combine(path.FullName, "afile")), null);
             Assert.Fail("did not hit expected exception");
         }
         catch (NoSuchDirectoryException nsde)
         {
             // Expected
         }
     }
     finally
     {
         fsDir.Dispose();
         System.IO.Directory.Delete(path.FullName, true);
     }
 }
 public void TestFSDirectorySync()
 {
     System.IO.FileInfo path = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testsync"));
     Lucene.Net.Store.Directory directory = new Lucene.Net.Store.SimpleFSDirectory(path, null);
     try
     {
         Lucene.Net.Store.IndexOutput io = directory.CreateOutput("syncfile");
         io.Close();
         directory.Sync("syncfile");
     }
     finally
     {
         directory.Close();
         Lucene.Net.Util._TestUtil.RmDir(path);
     }
 }
Exemple #14
0
		public virtual void  TestNotDirectory()
		{
			System.IO.FileInfo path = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testnotdir"));
			Directory fsDir = new SimpleFSDirectory(path, null);
			try
			{
				IndexOutput out_Renamed = fsDir.CreateOutput("afile");
				out_Renamed.Close();
				Assert.IsTrue(fsDir.FileExists("afile"));
				try
				{
					new SimpleFSDirectory(new System.IO.FileInfo(System.IO.Path.Combine(path.FullName, "afile")), null);
					Assert.Fail("did not hit expected exception");
				}
				catch (NoSuchDirectoryException nsde)
				{
					// Expected
				}
			}
			finally
			{
				fsDir.Close();
				_TestUtil.RmDir(path);
			}
		}
Exemple #15
0
        public virtual void TestFsyncDoesntCreateNewFiles()
        {
            //File path = CreateTempDir("nocreate");
            DirectoryInfo path = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "nocreate"));
            Console.WriteLine(path.FullName);
            Directory fsdir = new SimpleFSDirectory(path);

            // write a file
            IndexOutput @out = fsdir.CreateOutput("afile", NewIOContext(Random()));
            @out.WriteString("boo");
            @out.Dispose();

            // delete it
            try
            {
                var newDir = new DirectoryInfo(Path.Combine(path.FullName, "afile"));
                newDir.Create();
                newDir.Delete();
            }
            catch (Exception)
            {
                Assert.Fail("Deletion of new Directory should never fail.");
            }

            // directory is empty
            Assert.AreEqual(0, fsdir.ListAll().Length);

            // fsync it
            try
            {
                fsdir.Sync(CollectionsHelper.Singleton("afile"));
                Assert.Fail("didn't get expected exception, instead fsync created new files: " + Arrays.AsList(fsdir.ListAll()));
            }
            catch (FileNotFoundException /*| NoSuchFileException*/ expected)
            {
                // ok
            }

            // directory is still empty
            Assert.AreEqual(0, fsdir.ListAll().Length);

            fsdir.Dispose();
        }