Skip to content

Commit

Permalink
adds logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Jul 18, 2024
1 parent 5a5c5f2 commit 7c17e5d
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Examine.Lucene.Providers;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
Expand All @@ -18,6 +19,13 @@ namespace Examine.Test.Examine.Lucene.Directories
[TestFixture]
public class SyncedFileSystemDirectoryFactoryTests : ExamineBaseTest
{
private readonly ILogger _logger;

public SyncedFileSystemDirectoryFactoryTests()
{
_logger = LoggerFactory.CreateLogger<SyncedFileSystemDirectoryFactoryTests>();
}

[TestCase(true, false, SyncedFileSystemDirectoryFactory.CreateResult.NotClean | SyncedFileSystemDirectoryFactory.CreateResult.Fixed | SyncedFileSystemDirectoryFactory.CreateResult.OpenedSuccessfully)]
[TestCase(true, true, SyncedFileSystemDirectoryFactory.CreateResult.MissingSegments | SyncedFileSystemDirectoryFactory.CreateResult.CorruptCreatedNew, Ignore = "testing")]
[TestCase(false, false, SyncedFileSystemDirectoryFactory.CreateResult.OpenedSuccessfully, Ignore = "testing")]
Expand Down Expand Up @@ -115,7 +123,10 @@ public void Given_CorruptMainIndex_And_HealthyLocalIndex_When_CreatingDirectory_

private void CreateIndex(string rootPath, bool corruptIndex, bool removeSegments)
{
using var luceneDir = FSDirectory.Open(Path.Combine(rootPath, TestIndex.TestIndexName));
var indexPath = Path.Combine(rootPath, TestIndex.TestIndexName);
_logger.LogInformation("Creating index at " + indexPath);

using var luceneDir = FSDirectory.Open(indexPath);

using (var writer = new IndexWriter(luceneDir, new IndexWriterConfig(LuceneInfo.CurrentVersion, new CultureInvariantStandardAnalyzer())))
using (var indexer = GetTestIndex(writer))
Expand All @@ -138,6 +149,7 @@ private void CreateIndex(string rootPath, bool corruptIndex, bool removeSegments
});
}

_logger.LogInformation("Created index at " + luceneDir.Directory);
Assert.IsTrue(DirectoryReader.IndexExists(luceneDir));

if (corruptIndex)
Expand All @@ -155,6 +167,7 @@ private void CorruptIndex(DirectoryInfo dir, bool removeSegments)
: !x.Name.Contains("segments", StringComparison.OrdinalIgnoreCase))
.First();

Console.WriteLine($"Deleting {indexFile.FullName}");
File.Delete(indexFile.FullName);
}
}
Expand Down

0 comments on commit 7c17e5d

Please sign in to comment.