Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Jul 31, 2024
1 parent 5129af2 commit 7c25530
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private CreateResult CheckIndexHealthAndFix(

if (status.MissingSegments)
{
_logger.LogError("{IndexName} index is missing segments, it will be deleted.", indexName);
_logger.LogWarning("{IndexName} index is missing segments, it will be deleted.", indexName);
result = CreateResult.MissingSegments;
}
else if (!status.Clean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Examine.Lucene.Analyzers;
using Examine.Lucene.Directories;
using Examine.Lucene.Providers;
using Lucene.Net.Codecs.Lucene46;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Microsoft.Extensions.Logging;
Expand All @@ -21,8 +22,8 @@ namespace Examine.Test.Examine.Lucene.Directories
public class SyncedFileSystemDirectoryFactoryTests : ExamineBaseTest
{
[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")]
[TestCase(true, true, SyncedFileSystemDirectoryFactory.CreateResult.MissingSegments | SyncedFileSystemDirectoryFactory.CreateResult.CorruptCreatedNew)]
[TestCase(false, false, SyncedFileSystemDirectoryFactory.CreateResult.OpenedSuccessfully)]
[Test]
public void Given_ExistingCorruptIndex_When_CreatingDirectory_Then_IndexCreatedOrOpened(
bool corruptIndex,
Expand Down Expand Up @@ -94,7 +95,7 @@ public void Given_CorruptMainIndex_And_HealthyLocalIndex_When_CreatingDirectory_
var result = syncedDirFactory.TryCreateDirectory(index, false, out var dir);

Assert.IsTrue(result.HasFlag(SyncedFileSystemDirectoryFactory.CreateResult.SyncedFromLocal));
}
}

// Ensure the docs are there in main
using var mainIndex = new LuceneIndex(
Expand Down Expand Up @@ -156,11 +157,16 @@ private void CreateIndex(string rootPath, bool corruptIndex, bool removeSegments

private void CorruptIndex(DirectoryInfo dir, bool removeSegments, ILogger logger)
{
// index file extensions (no segments, no gen)
var indexFileExtensions = IndexFileNames.INDEX_EXTENSIONS
.Except(new[] { IndexFileNames.GEN_EXTENSION })
.ToArray();

// Get an index (non segments file) and delete it (corrupt index)
var indexFile = dir.GetFiles()
.Where(x => removeSegments
? x.Name.Contains("segments_", StringComparison.OrdinalIgnoreCase)
: !x.Name.Contains("segments", StringComparison.OrdinalIgnoreCase))
? x.Extension.Contains(Lucene46SegmentInfoFormat.SI_EXTENSION, StringComparison.OrdinalIgnoreCase)
: indexFileExtensions.Any(e => IndexFileNames.MatchesExtension(x.Extension, e)))
.First();

logger.LogInformation($"Deleting {indexFile.FullName}");
Expand Down

0 comments on commit 7c25530

Please sign in to comment.