Skip to content

Commit

Permalink
Semi-fixed the test, now throws UnauthorizedAccessException
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Dec 31, 2014
1 parent 4128ced commit f81d543
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Lucene.Net.Core/Store/FSDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public override long Length
/// <param name="name"></param>
protected void Fsync(String name, bool isDir = false)
{
IOUtils.Fsync(Path.Combine(directory.FullName, name), false);
IOUtils.Fsync(Path.Combine(directory.FullName, name), isDir);
}
}
}
67 changes: 33 additions & 34 deletions src/Lucene.Net.Tests/core/Store/TestDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public virtual void TestDirectInstantiation()
[Test]
public virtual void TestDontCreate()
{
DirectoryInfo path = new DirectoryInfo(Path.Combine(AppSettings.Get("tmpDir", ""), "doesnotexist"));
var path = new DirectoryInfo(Path.Combine(AppSettings.Get("tmpDir", ""), "doesnotexist"));
try
{
Assert.IsTrue(!path.Exists);
Expand Down Expand Up @@ -358,46 +358,45 @@ public virtual void TestNotDirectory()
[Test]
public virtual void TestFsyncDoesntCreateNewFiles()
{
//File path = CreateTempDir("nocreate");
DirectoryInfo path = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "nocreate"));
var path = CreateTempDir("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 e)
using (Directory fsdir = new SimpleFSDirectory(path))
{
Assert.Fail("Deletion of new Directory should never fail.\nException thrown: {0}", e);
}
// write a file
using (var o = fsdir.CreateOutput("afile", NewIOContext(Random())))
{
o.WriteString("boo");
}

// directory is empty
Assert.AreEqual(0, fsdir.ListAll().Length);
// 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);
}

// 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 empty
Assert.AreEqual(0, fsdir.ListAll().Length);

// directory is still 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)
{
// ok
}

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

0 comments on commit f81d543

Please sign in to comment.