From aa098e18e9824217556ca217c8d2ebd5ad9a8885 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Aug 2024 09:58:06 -0600 Subject: [PATCH] Updates ConcurrencyTests --- .../Examine.Lucene/Search/ConcurrencyTests.cs | 33 +++++++++++++------ src/Examine.Test/ExamineBaseTest.cs | 5 ++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Examine.Test/Examine.Lucene/Search/ConcurrencyTests.cs b/src/Examine.Test/Examine.Lucene/Search/ConcurrencyTests.cs index b6caea1a..c7ac067f 100644 --- a/src/Examine.Test/Examine.Lucene/Search/ConcurrencyTests.cs +++ b/src/Examine.Test/Examine.Lucene/Search/ConcurrencyTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Lucene.Net.Analysis.Standard; using Lucene.Net.Store; +using Microsoft.Extensions.Logging; using NUnit.Framework; namespace Examine.Test.Examine.Lucene.Search @@ -15,11 +16,16 @@ namespace Examine.Test.Examine.Lucene.Search [TestFixture] public class ConcurrencyTests : ExamineBaseTest { + protected override ILoggerFactory CreateLoggerFactory() + => Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)); + [TestCase(1)] [TestCase(10)] [TestCase(25)] + [TestCase(100)] public async Task BenchmarkConcurrentSearching(int threads) { + var logger = LoggerFactory.CreateLogger(); var tempBasePath = Path.Combine(Path.GetTempPath(), "ExamineTests"); try @@ -34,14 +40,20 @@ public async Task BenchmarkConcurrentSearching(int threads) luceneDir, analyzer)) { - indexer.IndexItems(new[] { - ValueSet.FromObject(1.ToString(), "content", - new { nodeName = "location 1", bodyText = "Zanzibar is in Africa"}), - ValueSet.FromObject(2.ToString(), "content", - new { nodeName = "location 2", bodyText = "In Canada there is a town called Sydney in Nova Scotia"}), - ValueSet.FromObject(3.ToString(), "content", - new { nodeName = "location 3", bodyText = "Sydney is the capital of NSW in Australia"}) - }); + var random = new Random(); + var valueSets = new List(); + + for (var i = 0; i < 1000; i++) + { + valueSets.Add(ValueSet.FromObject(Guid.NewGuid().ToString(), "content", + new + { + nodeName = "location " + i, + bodyText = Enumerable.Range(0, random.Next(10, 100)).Select(x => Guid.NewGuid().ToString()) + })); + } + + indexer.IndexItems(valueSets); var tasks = new List(); @@ -56,7 +68,8 @@ public async Task BenchmarkConcurrentSearching(int threads) var results = query.Execute(); // enumerate (forces the result to execute) - Console.WriteLine("ThreadID: " + Thread.CurrentThread.ManagedThreadId + ", Results: " + string.Join(',', results.Select(x => $"{x.Id}-{x.Values.Count}-{x.Score}").ToArray())); + var logOutput = "ThreadID: " + Thread.CurrentThread.ManagedThreadId + ", Results: " + string.Join(',', results.Select(x => $"{x.Id}-{x.Values.Count}-{x.Score}").ToArray()); + logger.LogDebug(logOutput); })); } @@ -75,7 +88,7 @@ public async Task BenchmarkConcurrentSearching(int threads) finally { stopwatch.Stop(); - Console.WriteLine("Completed in ms: " + stopwatch.ElapsedMilliseconds); + logger.LogInformation("Completed in ms: " + stopwatch.ElapsedMilliseconds); } } } diff --git a/src/Examine.Test/ExamineBaseTest.cs b/src/Examine.Test/ExamineBaseTest.cs index baf341f3..47dbf80e 100644 --- a/src/Examine.Test/ExamineBaseTest.cs +++ b/src/Examine.Test/ExamineBaseTest.cs @@ -18,7 +18,7 @@ public abstract class ExamineBaseTest [SetUp] public virtual void Setup() { - LoggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug)); + LoggerFactory = CreateLoggerFactory(); LoggerFactory.CreateLogger(typeof(ExamineBaseTest)).LogDebug("Initializing test"); } @@ -42,5 +42,8 @@ public TestIndex GetTestIndex(IndexWriter writer) LoggerFactory, Mock.Of>(x => x.Get(TestIndex.TestIndexName) == new LuceneIndexOptions()), writer); + + protected virtual ILoggerFactory CreateLoggerFactory() + => Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug)); } }