Added test case which throws on concurrent directory access.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/33401007 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/33401007 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/33401007 Branch: refs/heads/master Commit: 33401007061e339ed692432abcbb5feb33ed50a0 Parents: d581572 Author: Pieter van Ginkel <[email protected]> Authored: Mon May 8 15:21:00 2017 +0200 Committer: Pieter van Ginkel <[email protected]> Committed: Mon May 8 15:21:00 2017 +0200 ---------------------------------------------------------------------- src/Lucene.Net.Tests/Store/TestDirectory.cs | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/33401007/src/Lucene.Net.Tests/Store/TestDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Store/TestDirectory.cs b/src/Lucene.Net.Tests/Store/TestDirectory.cs index e796640..3753818 100644 --- a/src/Lucene.Net.Tests/Store/TestDirectory.cs +++ b/src/Lucene.Net.Tests/Store/TestDirectory.cs @@ -6,6 +6,7 @@ using Lucene.Net.Util; using NUnit.Framework; using System; using System.IO; +using System.Threading; namespace Lucene.Net.Store { @@ -423,5 +424,59 @@ namespace Lucene.Net.Store Assert.AreEqual(0, fsdir.ListAll().Length); } } + + [Test] + [Ignore("Not deterministic; depends on a race condition")] + [LuceneNetSpecific] + 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(); + } + } + } } } \ No newline at end of file
