2024-08-02 08:44:15 +00:00
|
|
|
|
using Logging;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using OverwatchTranscript;
|
|
|
|
|
|
2024-10-10 13:31:38 +00:00
|
|
|
|
namespace FrameworkTests.OverwatchTranscriptTests
|
2024-08-02 08:44:15 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TranscriptLargeTests
|
|
|
|
|
{
|
|
|
|
|
private const int NumberOfThreads = 10;
|
|
|
|
|
private const int NumberOfEventsPerThread = 1000000;
|
|
|
|
|
private const string TranscriptFilename = "testtranscriptlarge.owts";
|
2024-08-05 12:16:44 +00:00
|
|
|
|
private ITranscriptWriter writer = null!;
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
2024-08-05 10:24:13 +00:00
|
|
|
|
[Ignore("Takes about 25 minutes to run.")]
|
2024-08-02 08:44:15 +00:00
|
|
|
|
public void MillionsOfEvents()
|
|
|
|
|
{
|
|
|
|
|
var log = new FileLog(nameof(MillionsOfEvents));
|
2024-08-05 12:16:44 +00:00
|
|
|
|
writer = Transcript.NewWriter(log);
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
2024-08-05 10:24:13 +00:00
|
|
|
|
Stopwatch.Measure(log, "Generate", () =>
|
2024-08-02 08:44:15 +00:00
|
|
|
|
{
|
2024-08-05 10:24:13 +00:00
|
|
|
|
var tasks = new List<Task>();
|
|
|
|
|
for (var i = 0; i < NumberOfThreads; i++)
|
|
|
|
|
{
|
|
|
|
|
tasks.Add(RunGeneratorThread());
|
|
|
|
|
}
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
2024-08-05 10:24:13 +00:00
|
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
|
|
});
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
2024-08-05 10:24:13 +00:00
|
|
|
|
Stopwatch.Measure(log, "Write", () =>
|
|
|
|
|
{
|
|
|
|
|
writer.Write(TranscriptFilename);
|
|
|
|
|
});
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
2024-08-05 10:24:13 +00:00
|
|
|
|
Stopwatch.Measure(log, "Read", () =>
|
|
|
|
|
{
|
2024-08-05 12:16:44 +00:00
|
|
|
|
ReadTranscript();
|
2024-08-05 10:24:13 +00:00
|
|
|
|
});
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
|
|
|
|
File.Delete(TranscriptFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task RunGeneratorThread()
|
|
|
|
|
{
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var remaining = NumberOfEventsPerThread;
|
|
|
|
|
while (remaining > 0)
|
|
|
|
|
{
|
|
|
|
|
writer.Add(DateTime.UtcNow, new MyEvent
|
|
|
|
|
{
|
|
|
|
|
EventData = Guid.NewGuid().ToString()
|
|
|
|
|
});
|
|
|
|
|
remaining--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("exception in thread: " + ex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 12:16:44 +00:00
|
|
|
|
private void ReadTranscript()
|
2024-08-02 08:44:15 +00:00
|
|
|
|
{
|
2024-08-05 12:16:44 +00:00
|
|
|
|
var reader = Transcript.NewReader(TranscriptFilename);
|
2024-08-02 08:44:15 +00:00
|
|
|
|
|
|
|
|
|
var expectedNumberOfEvents = NumberOfThreads * NumberOfEventsPerThread;
|
|
|
|
|
Assert.That(reader.Header.NumberOfEvents, Is.EqualTo(expectedNumberOfEvents));
|
|
|
|
|
|
|
|
|
|
var counter = 0;
|
2024-08-05 10:24:13 +00:00
|
|
|
|
var current = DateTime.MinValue;
|
2024-08-02 08:44:15 +00:00
|
|
|
|
reader.AddEventHandler<MyEvent>(e =>
|
|
|
|
|
{
|
|
|
|
|
counter++;
|
2024-08-05 10:24:13 +00:00
|
|
|
|
if (e.Moment.Utc < current)
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("Event has moment BEFORE previous one.");
|
|
|
|
|
}
|
|
|
|
|
current = e.Moment.Utc;
|
2024-08-02 08:44:15 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var run = true;
|
|
|
|
|
while (run)
|
|
|
|
|
{
|
|
|
|
|
run = reader.Next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|