Created
December 1, 2011 10:56
-
-
Save DominicFinn/1415816 to your computer and use it in GitHub Desktop.
Lucene test. Concurrency pain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Cms51.Search.Lucene; | |
using Lucene.Net.Analysis.Standard; | |
using Lucene.Net.Documents; | |
using Lucene.Net.Index; | |
using Lucene.Net.Store; | |
using North51.Commons.Testing; | |
using North51.Commons.Web; | |
using Rhino.Mocks; | |
using Version = Lucene.Net.Util.Version; | |
namespace Cms51.Search.Tests.Lucene | |
{ | |
public class ConcurrencyTest : Specification | |
{ | |
RAMDirectory directory; | |
protected override void Given() | |
{ | |
var luceneConfiguration = Dependency<ILuceneConfiguration>(); | |
var analyzer = new StandardAnalyzer(Version.LUCENE_29); | |
luceneConfiguration | |
.Stub(x => x.GetAnalyzer()) | |
.Return(analyzer); | |
this.Inject<IEncoder>(new DefaultEncoder()); | |
// creates the search index | |
directory = new RAMDirectory(); | |
var indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); | |
indexWriter.Close(); | |
} | |
protected override void When() | |
{ | |
for (int i = 0; i < 1000; i++) | |
{ | |
new Thread(delegate() | |
{ | |
var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_29), false, IndexWriter.MaxFieldLength.UNLIMITED); | |
try | |
{ | |
var document = new Document(); | |
document.Add(new Field("testId", Guid.NewGuid().ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); | |
document.Add(new Field("resourceId", Guid.NewGuid().ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); | |
document.Add(new Field("Testfield", "A larger amount of test data for lucence to have a think about", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); | |
indexWriter.AddDocument(document, new StandardAnalyzer(Version.LUCENE_29)); | |
indexWriter.Commit(); | |
} | |
finally | |
{ | |
indexWriter.Close(); | |
} | |
}).Start(); | |
} | |
Thread.Sleep(1000); | |
} | |
[Then] | |
public void Test() | |
{ | |
//Should pass but not without considerable amount of complaining from visual studio unable to obtain locks and clicking msgboxs | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment