Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database validation #35

Merged
merged 36 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0a378c1
Database validation
sakari-malkki Jul 19, 2024
e79ad47
Benchmarks for database validation
sakari-malkki Jul 19, 2024
1023350
Tests for database validator functions
sakari-malkki Jul 19, 2024
11c5230
Tests for database validator class
sakari-malkki Jul 19, 2024
336565e
Exclude defautl file system wrapper from test coverage
sakari-malkki Jul 22, 2024
249b687
Reset stream position after finding encoding
sakari-malkki Jul 22, 2024
4f37840
Additional tests for single language database
sakari-malkki Jul 22, 2024
410b1ed
Clear entrybuilder after processing entries
sakari-malkki Jul 22, 2024
e930b13
Trim whitespace from entries
sakari-malkki Jul 22, 2024
7bd62da
Add cancellation token to async px file info
sakari-malkki Jul 22, 2024
19bee5c
Reduce duplication
sakari-malkki Jul 22, 2024
ea1e26a
Summaries
sakari-malkki Jul 22, 2024
e7b3d60
Readme documentation for database validation
sakari-malkki Jul 22, 2024
153af16
Solve sonar issues (incompleted summary todos and seal a mock data cl…
sakari-malkki Jul 22, 2024
7319a74
Fix bunch of previous px file validator issues
sakari-malkki Jul 23, 2024
6d9c7bc
Improve test coverage and reduce duplication
sakari-malkki Jul 23, 2024
a8f101a
Asynchronous and parallel execution of database validation
sakari-malkki Jul 24, 2024
150e181
Pass cancellation token to the encoding function and reduce duplication
sakari-malkki Jul 24, 2024
b697fc4
Cleaning up utility methods
sakari-malkki Jul 24, 2024
0289094
Async alias file handling
sakari-malkki Jul 24, 2024
20863de
Makes time stamp regex dictionary thread safe
sakari-malkki Jul 24, 2024
d75d6d4
Fix file based benchmarks
sakari-malkki Jul 24, 2024
6a85986
Fixes for various file validation breaking edge cases
sakari-malkki Sep 9, 2024
ccd3afc
Stores validation feedbacks in a dictionary to group duplicates
sakari-malkki Sep 11, 2024
67f78af
Update documentation on relevant parts and fix sonar complaint from t…
sakari-malkki Sep 11, 2024
dec7f93
Benchmark cleanup, updated documentation and validation fixes
sakari-malkki Sep 11, 2024
7526954
Improved test coverage
sakari-malkki Sep 11, 2024
b9b8327
Edge case fix for duplicate dimensions
sakari-malkki Sep 11, 2024
a9967c0
Removes wrapping error in benchmark and makes rule violation coordina…
sakari-malkki Sep 12, 2024
c7bd34a
Separate file stream validator and generic validator interfaces
sakari-malkki Sep 12, 2024
9ca6405
Makes encoding optional for file stream validators - tries to find en…
sakari-malkki Sep 13, 2024
3048441
Fix failing tests
sakari-malkki Sep 13, 2024
e4b9ae9
Moves default FileSystem to its own file and uses existing encoding d…
sakari-malkki Sep 13, 2024
235813e
Renames default file system to LocalFileSystem
sakari-malkki Sep 13, 2024
3630901
Removes utility method with a linq function
sakari-malkki Sep 13, 2024
ea524d7
Changes made on based various pr suggestions
sakari-malkki Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Px.Utils.TestingApp/Commands/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal BenchmarkRunner()
_benchmarks.Add("data-validation", new DataValidationBenchmark());
_benchmarks.Add("file-validation", new PxFileValidationBenchmark());
_benchmarks.Add("computation", new ComputationBenchmark());
_benchmarks.Add("database-validation", new DatabaseValidationBenchmark());
}

internal override string Help
Expand Down
8 changes: 4 additions & 4 deletions Px.Utils.TestingApp/Commands/DataValidationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ private void ValidateDataBenchmarks()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Position = start + dataKeyword.Length + readStartOffset; // skip the '=' and linechange
DataValidator validator = new(stream, expectedCols, expectedRows, TestFilePath, 0, encoding);
validator.Validate();
DataValidator validator = new(expectedCols, expectedRows, 0);
validator.Validate(stream, TestFilePath, encoding);
}

private async Task ValidateDataBenchmarksAsync()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Position = start + dataKeyword.Length + readStartOffset; // skip the '=' and linechange
DataValidator validator = new(stream, expectedCols, expectedRows, TestFilePath, 0, encoding);
DataValidator validator = new(expectedCols, expectedRows, 0);

await validator.ValidateAsync();
await validator.ValidateAsync(stream, TestFilePath, encoding);
}

protected override void SetRunParameters()
Expand Down
69 changes: 69 additions & 0 deletions Px.Utils.TestingApp/Commands/DatabaseValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Px.Utils.Validation.DatabaseValidation;

namespace Px.Utils.TestingApp.Commands
{
internal sealed class DatabaseValidationBenchmark : Benchmark
{
internal override string Help => "Validates a px path database.";

internal override string Description => "Validates a px path database.";
private static readonly string[] directoryFlags = ["-d", "-directory"];

private DatabaseValidator validator;

internal DatabaseValidationBenchmark()
{
ParameterFlags.Add(directoryFlags);
BenchmarkFunctions = [ValidationBenchmark];
BenchmarkFunctionsAsync = [ValidationBenchmarkAsync];
}

protected override void SetRunParameters()
{
foreach (string key in directoryFlags)
{
if (Parameters.TryGetValue(key, out List<string>? value) && value.Count == 1)
{
TestFilePath = value[0];
base.SetRunParameters();
return;
}
}

throw new ArgumentException("Directory not found.");
}

protected override void StartInteractiveMode()
{
base.StartInteractiveMode();

Console.WriteLine("Enter the path to the PX database root to benchmark");
string path = Console.ReadLine() ?? "";

while (!Directory.Exists(path))
{
Console.WriteLine("Path provided is not valid, please enter a path to a valid directory.");
path = Console.ReadLine() ?? "";
}

TestFilePath = path;
}

protected override void OneTimeBenchmarkSetup()
{
base.OneTimeBenchmarkSetup();

validator = new(TestFilePath, new LocalFileSystem());
}

private void ValidationBenchmark()
{
validator.Validate();
}

private async Task ValidationBenchmarkAsync()
{
await validator.ValidateAsync();
}
}
}
2 changes: 1 addition & 1 deletion Px.Utils.TestingApp/Commands/FileBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void SetRunParameters()
}
}

throw new ArgumentException("File path parameter not found for a file based benchmark.");
StartInteractiveMode();
}

protected override void StartInteractiveMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected override void OneTimeBenchmarkSetup()

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);
SyntaxValidator syntaxValidator = new(stream, Encoding.Default, TestFilePath);
SyntaxValidationResult validatorResult = syntaxValidator.Validate();
SyntaxValidator syntaxValidator = new();
SyntaxValidationResult validatorResult = syntaxValidator.Validate(stream, TestFilePath, Encoding.Default);
_entries = validatorResult.Result;
}

Expand Down
19 changes: 8 additions & 11 deletions Px.Utils.TestingApp/Commands/MetadataSyntaxValidationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Px.Utils.TestingApp.Commands
{
internal sealed class MetadataSyntaxValidationBenchmark : Benchmark
internal sealed class MetadataSyntaxValidationBenchmark : FileBenchmark
{
internal override string Help =>
"Validates the syntax of the Px file metadata given amount of times." + Environment.NewLine +
Expand All @@ -13,8 +13,7 @@ internal sealed class MetadataSyntaxValidationBenchmark : Benchmark

internal override string Description => "Benchmarks the metadata syntax validation of Px.Utils/Validation/SyntaxValidator.";

private Encoding encoding;
private SyntaxValidator validator;
private Encoding encoding = Encoding.Default;

internal MetadataSyntaxValidationBenchmark()
{
Expand All @@ -29,24 +28,22 @@ protected override void OneTimeBenchmarkSetup()
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileMetadataReader reader = new();
encoding = reader.GetEncoding(stream);
stream.Seek(0, SeekOrigin.Begin);
validator = new(stream, encoding, TestFilePath);
}

private void SyntaxValidationBenchmark()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);

validator.Validate();
SyntaxValidator validator = new();
validator.Validate(stream, TestFilePath, encoding);
stream.Close();
}

private async Task SyntaxValidationBenchmarkAsync()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);

await validator.ValidateAsync();
SyntaxValidator validator = new();
await validator.ValidateAsync(stream, TestFilePath, encoding);
stream.Close();
}
}
}
23 changes: 16 additions & 7 deletions Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Px.Utils.PxFile.Metadata;
using Px.Utils.Exceptions;
using Px.Utils.PxFile.Metadata;
using Px.Utils.Validation;
using System.Text;

namespace Px.Utils.TestingApp.Commands
{
internal class PxFileValidationBenchmark : Benchmark
internal sealed class PxFileValidationBenchmark : FileBenchmark
{
internal override string Help =>
"Runs through the whole px file validation process (metadata syntax- and contents-, data-) for the given file.";
Expand All @@ -26,21 +27,29 @@ protected override void OneTimeBenchmarkSetup()

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileMetadataReader reader = new();
encoding = reader.GetEncoding(stream);
try
{
encoding = reader.GetEncoding(stream);
}
catch (InvalidPxFileMetadataException)
{
encoding = Encoding.Default;
throw;
}
}

private void ValidatePxFileBenchmarks()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileValidator validator = new(stream, TestFilePath, encoding);
validator.Validate();
PxFileValidator validator = new();
validator.Validate(stream, TestFilePath, encoding);
}

private async Task ValidatePxFileBenchmarksAsync()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileValidator validator = new(stream, TestFilePath, encoding);
await validator.ValidateAsync();
PxFileValidator validator = new();
await validator.ValidateAsync(stream, TestFilePath, encoding);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task CancelReadDoubleDataValuesAsyncValidIntegersIsCancelled()
DataIndexer indexer = new(testMeta, matrixMap);

using CancellationTokenSource cts = new();
cts.Cancel();
await cts.CancelAsync();
CancellationToken cToken = cts.Token;

async Task call() => await reader.ReadDoubleDataValuesAsync(targetBuffer, 0, indexer, cToken);
Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task CancelReadAddDecimalDataValuesAsyncValidIntegersIsCancelled()
DataIndexer indexer = new(testMeta, matrixMap);

using CancellationTokenSource cts = new();
cts.Cancel();
await cts.CancelAsync();
CancellationToken cToken = cts.Token;

async Task call() => await reader.ReadDecimalDataValuesAsync(targetBuffer, 0, indexer, cToken);
Expand Down Expand Up @@ -283,7 +283,7 @@ public async Task CancelReadUnsafeDoubleValuesAsyncValidIntegersIsCancelled()
DataIndexer indexer = new(testMeta, matrixMap);

using CancellationTokenSource cts = new();
cts.Cancel();
await cts.CancelAsync();
CancellationToken cToken = cts.Token;

// Act and Assert
Expand Down
Loading