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