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 } // 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); } }
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); } }
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(); }
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 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); } }
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(); }