From fb3108fd86ede7942ef0ae90748573856e98bd40 Mon Sep 17 00:00:00 2001 From: halgari Date: Tue, 20 Feb 2024 21:25:40 -0700 Subject: [PATCH] More code cleanup --- .../AppHost.cs | 1 + .../Benchmarks/ReadTests.cs | 2 +- .../Benchmarks/WriteTests.cs | 32 ++++++++++++++----- qodana.yaml | 1 + .../Datom.cs | 32 +++++++++++++++++-- .../IDatomSink.cs | 8 +++++ .../IDatomStore.cs | 4 --- .../IEntityIterator.cs | 1 - .../Ids.cs | 2 +- .../Symbol.cs | 6 ++-- .../AttributeRegistry.cs | 13 +++++--- .../BuiltInAttributes.cs | 1 - .../Indexes/AETVIndex.cs | 2 -- .../Indexes/EATVIndex.cs | 2 +- .../PooledMemoryBufferWriter.cs | 2 +- .../RocksDBDatomStore.cs | 11 ++----- .../Services.cs | 3 -- src/NexusMods.EventSourcing/CommitResult.cs | 2 +- src/NexusMods.EventSourcing/Connection.cs | 2 +- src/NexusMods.EventSourcing/ModelReflector.cs | 2 -- src/NexusMods.EventSourcing/Services.cs | 3 -- src/NexusMods.EventSourcing/Transaction.cs | 3 +- .../ADatomStoreTest.cs | 5 ++- .../Startup.cs | 1 + .../TransactionLogTest.cs | 32 ------------------- .../Services.cs | 2 +- .../AEventSourcingTest.cs | 10 +++--- .../NexusMods.EventSourcing.Tests/DbTests.cs | 6 ++-- .../NexusMods.EventSourcing.Tests/Startup.cs | 1 + 29 files changed, 99 insertions(+), 93 deletions(-) delete mode 100644 tests/NexusMods.EventSourcing.DatomStore.Tests/TransactionLogTest.cs diff --git a/benchmarks/NexusMods.EventSourcing.Benchmarks/AppHost.cs b/benchmarks/NexusMods.EventSourcing.Benchmarks/AppHost.cs index 5b16a922..83410a42 100644 --- a/benchmarks/NexusMods.EventSourcing.Benchmarks/AppHost.cs +++ b/benchmarks/NexusMods.EventSourcing.Benchmarks/AppHost.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using NexusMods.EventSourcing.DatomStore; +using NexusMods.EventSourcing.TestModel; using NexusMods.Paths; namespace NexusMods.EventSourcing.Benchmarks; diff --git a/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/ReadTests.cs b/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/ReadTests.cs index 1933ad70..39150af0 100644 --- a/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/ReadTests.cs +++ b/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/ReadTests.cs @@ -83,7 +83,7 @@ public ulong ReadFiles() { sum += itm.Index; } - return (ulong)sum; + return sum; } } diff --git a/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/WriteTests.cs b/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/WriteTests.cs index d523783c..facbc292 100644 --- a/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/WriteTests.cs +++ b/benchmarks/NexusMods.EventSourcing.Benchmarks/Benchmarks/WriteTests.cs @@ -1,6 +1,10 @@ -using BenchmarkDotNet.Attributes; +using System.Collections.Generic; +using System.Linq; +using BenchmarkDotNet.Attributes; +using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NexusMods.EventSourcing.Abstractions; +using NexusMods.EventSourcing.TestModel.Model; namespace NexusMods.EventSourcing.Benchmarks.Benchmarks; @@ -22,17 +26,29 @@ public WriteTests() [Benchmark] public void AddFiles() { - /* var tx = _connection.BeginTransaction(); + var ids = new List(); for (var i = 0; i < Count; i++) { - var id = Ids.MakeId(Ids.Partition.Entity, (ulong)i); - File.Hash.Assert(tx.TempId(), (ulong)i, tx); - File.Path.Assert(tx.TempId(), $"C:\\test_{i}.txt", tx); - File.Index.Assert(tx.TempId(), (ulong)i, tx); + var file = new File(tx) + { + Hash = (ulong)i, + Path = $"C:\\test_{i}.txt", + Index = (ulong)i + }; + ids.Add(file.Id); + } + var result = tx.Commit(); + + ids = ids.Select(id => result[id]).ToList(); + + var db = _connection.Db; + foreach (var id in ids) + { + var loaded = db.Get(id); + + loaded.Should().NotBeNull("the entity should be in the database"); } - tx.Commit(); - */ } } diff --git a/qodana.yaml b/qodana.yaml index 752990cf..bedeed30 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -7,3 +7,4 @@ profile: name: qodana.recommended exclude: - name: ClassNeverInstantiated.Global + - name: UnusedAutoPropertyAccessor.Global diff --git a/src/NexusMods.EventSourcing.Abstractions/Datom.cs b/src/NexusMods.EventSourcing.Abstractions/Datom.cs index acef9a2b..d81c53c2 100644 --- a/src/NexusMods.EventSourcing.Abstractions/Datom.cs +++ b/src/NexusMods.EventSourcing.Abstractions/Datom.cs @@ -2,6 +2,9 @@ namespace NexusMods.EventSourcing.Abstractions; +/// +/// Represents a single fact in the database. Consists of an entity, attribute, value, and transaction id. +/// public interface IDatom { /// @@ -34,19 +37,44 @@ public interface IDatom void Remap(Func remapFn); } +/// +/// A datom that includes a transaction id +/// public interface IDatomWithTx : IDatom { + /// + /// The transaction id of the datom + /// TxId Tx { get; } } + +/// +/// An assertion datom, most datoms are assertions, so these are called out in a specific class +/// here to save memory +/// +/// +/// +/// +/// public class AssertDatom(ulong e, TVal v) : IDatom where TAttr : IAttribute { + /// public ulong Entity => e; + /// + /// The value of the datom + /// public TVal V => v; + + /// public Type Attribute => typeof(TAttr); + + /// public Type ValueType => typeof(TVal); + + /// public void Emit(ref TSink sink) where TSink : IDatomSink { sink.Datom(e, v, true); @@ -77,14 +105,12 @@ public class AssertDatomWithTx : AssertDatom, IDatomWi /// /// Default Constructor /// - /// - /// - /// public AssertDatomWithTx(ulong e, TVal v, TxId tx) : base(e, v) { Tx = tx; } + /// public override string ToString() { return $"(assert! {Entity}, {Attribute.Namespace}/{Attribute.Name}, {V}, {Tx})"; diff --git a/src/NexusMods.EventSourcing.Abstractions/IDatomSink.cs b/src/NexusMods.EventSourcing.Abstractions/IDatomSink.cs index 4e7a0fcc..a5fb798c 100644 --- a/src/NexusMods.EventSourcing.Abstractions/IDatomSink.cs +++ b/src/NexusMods.EventSourcing.Abstractions/IDatomSink.cs @@ -1,7 +1,15 @@ namespace NexusMods.EventSourcing.Abstractions; +/// +/// A sink is a typed interface that accepts the parts of a datom as values. It is generic and strongly typed +/// so that most of the data is transferred via the stack and does not require boxing. Think of all of this +/// something like IEnumerable, but as a pushed base interface instead of a pulled one. +/// public interface IDatomSink { + /// + /// Inject a datom into the sink. + /// public void Datom(ulong e, TVal v, bool isAssert) where TAttr : IAttribute; } diff --git a/src/NexusMods.EventSourcing.Abstractions/IDatomStore.cs b/src/NexusMods.EventSourcing.Abstractions/IDatomStore.cs index cf489c33..af325a26 100644 --- a/src/NexusMods.EventSourcing.Abstractions/IDatomStore.cs +++ b/src/NexusMods.EventSourcing.Abstractions/IDatomStore.cs @@ -37,10 +37,6 @@ public interface IDatomStore : IDisposable /// Gets the attributeId for the given attribute. And returns an expression that reads the attribute /// value from the expression valueSpan. /// - /// - /// - /// - /// Expression GetValueReadExpression(Type attribute, Expression valueSpan, out ulong attributeId); /// diff --git a/src/NexusMods.EventSourcing.Abstractions/IEntityIterator.cs b/src/NexusMods.EventSourcing.Abstractions/IEntityIterator.cs index ffda6137..b2fea8f2 100644 --- a/src/NexusMods.EventSourcing.Abstractions/IEntityIterator.cs +++ b/src/NexusMods.EventSourcing.Abstractions/IEntityIterator.cs @@ -1,5 +1,4 @@ using System; -using NexusMods.EventSourcing.Abstractions.Models; namespace NexusMods.EventSourcing.Abstractions; diff --git a/src/NexusMods.EventSourcing.Abstractions/Ids.cs b/src/NexusMods.EventSourcing.Abstractions/Ids.cs index 1b015e51..62a82ef4 100644 --- a/src/NexusMods.EventSourcing.Abstractions/Ids.cs +++ b/src/NexusMods.EventSourcing.Abstractions/Ids.cs @@ -71,7 +71,7 @@ public static Partition GetPartition(ulong id) 1 => Partition.Tx, 2 => Partition.Entity, 3 => Partition.Tmp, - > 3 => Partition.Unknown, + _ => Partition.Unknown, }; } diff --git a/src/NexusMods.EventSourcing.Abstractions/Symbol.cs b/src/NexusMods.EventSourcing.Abstractions/Symbol.cs index 7df9d353..0bed58b4 100644 --- a/src/NexusMods.EventSourcing.Abstractions/Symbol.cs +++ b/src/NexusMods.EventSourcing.Abstractions/Symbol.cs @@ -21,7 +21,7 @@ private Symbol(string nsAndName) Namespace = nsAndName[..splitOn]; } - private static readonly ConcurrentDictionary _internedSymbols = new(); + private static readonly ConcurrentDictionary InternedSymbols = new(); /// /// Construct a new symbol, or return an existing one that matches the given name @@ -30,11 +30,11 @@ private Symbol(string nsAndName) /// public static Symbol Intern(string nsAndName) { - if (_internedSymbols.TryGetValue(nsAndName, out var symbol)) + if (InternedSymbols.TryGetValue(nsAndName, out var symbol)) return symbol; symbol = new Symbol(nsAndName); - return !_internedSymbols.TryAdd(nsAndName, symbol) ? _internedSymbols[nsAndName] : symbol; + return !InternedSymbols.TryAdd(nsAndName, symbol) ? InternedSymbols[nsAndName] : symbol; } /// diff --git a/src/NexusMods.EventSourcing.DatomStore/AttributeRegistry.cs b/src/NexusMods.EventSourcing.DatomStore/AttributeRegistry.cs index 8d97004f..4ed3d3d9 100644 --- a/src/NexusMods.EventSourcing.DatomStore/AttributeRegistry.cs +++ b/src/NexusMods.EventSourcing.DatomStore/AttributeRegistry.cs @@ -26,12 +26,15 @@ public class AttributeRegistry /// public AttributeRegistry(IEnumerable valueSerializers, IEnumerable attributes) { - _valueSerializersByNativeType = valueSerializers.ToDictionary(x => x.NativeType); - _valueSerializersByUniqueId = valueSerializers.ToDictionary(x => x.UniqueId); - _attributesById = attributes.ToDictionary(x => x.Id); - _attributesByType = attributes.ToDictionary(x => x.GetType()); + var serializers = valueSerializers.ToArray(); + _valueSerializersByNativeType = serializers.ToDictionary(x => x.NativeType); + _valueSerializersByUniqueId = serializers.ToDictionary(x => x.UniqueId); - foreach (var attr in attributes) + var attributeArray = attributes.ToArray(); + _attributesById = attributeArray.ToDictionary(x => x.Id); + _attributesByType = attributeArray.ToDictionary(x => x.GetType()); + + foreach (var attr in attributeArray) { attr.SetSerializer(_valueSerializersByNativeType[attr.ValueType]); } diff --git a/src/NexusMods.EventSourcing.DatomStore/BuiltInAttributes.cs b/src/NexusMods.EventSourcing.DatomStore/BuiltInAttributes.cs index 83f4f886..4f0e5186 100644 --- a/src/NexusMods.EventSourcing.DatomStore/BuiltInAttributes.cs +++ b/src/NexusMods.EventSourcing.DatomStore/BuiltInAttributes.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Extensions.DependencyInjection; using NexusMods.EventSourcing.Abstractions; using NexusMods.EventSourcing.DatomStore.BuiltInSerializers; diff --git a/src/NexusMods.EventSourcing.DatomStore/Indexes/AETVIndex.cs b/src/NexusMods.EventSourcing.DatomStore/Indexes/AETVIndex.cs index 89f3c4a2..f8dbab13 100644 --- a/src/NexusMods.EventSourcing.DatomStore/Indexes/AETVIndex.cs +++ b/src/NexusMods.EventSourcing.DatomStore/Indexes/AETVIndex.cs @@ -26,7 +26,6 @@ public static unsafe int Compare(AIndexDefinition idx, KeyHeader* a, public struct AEVTByAIterator : IIterator where TAttr : IAttribute { - private readonly AETVIndex _idx; private KeyHeader _key; private readonly Iterator _iterator; private readonly ulong _attrId; @@ -34,7 +33,6 @@ public struct AEVTByAIterator : IIterator public AEVTByAIterator(ulong txId, AttributeRegistry registry, AETVIndex idx) { - _idx = idx; _registry = registry; _iterator = idx.Db.NewIterator(idx.ColumnFamilyHandle); _attrId = registry.GetAttributeId(); diff --git a/src/NexusMods.EventSourcing.DatomStore/Indexes/EATVIndex.cs b/src/NexusMods.EventSourcing.DatomStore/Indexes/EATVIndex.cs index 51b4948a..5d4c21d9 100644 --- a/src/NexusMods.EventSourcing.DatomStore/Indexes/EATVIndex.cs +++ b/src/NexusMods.EventSourcing.DatomStore/Indexes/EATVIndex.cs @@ -55,7 +55,7 @@ public bool MaxId(Ids.Partition partition, out ulong o) return false; } - public unsafe struct EATVIterator : IEntityIterator, IDisposable + public unsafe struct EATVIterator : IEntityIterator { private readonly KeyHeader* _key; private KeyHeader* _current; diff --git a/src/NexusMods.EventSourcing.DatomStore/PooledMemoryBufferWriter.cs b/src/NexusMods.EventSourcing.DatomStore/PooledMemoryBufferWriter.cs index 419f5d65..e6e73011 100644 --- a/src/NexusMods.EventSourcing.DatomStore/PooledMemoryBufferWriter.cs +++ b/src/NexusMods.EventSourcing.DatomStore/PooledMemoryBufferWriter.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using Reloaded.Memory.Extensions; -namespace NexusMods.EventSourcing; +namespace NexusMods.EventSourcing.DatomStore; /// /// A IBufferWriter that uses pooled memory to reduce allocations. diff --git a/src/NexusMods.EventSourcing.DatomStore/RocksDBDatomStore.cs b/src/NexusMods.EventSourcing.DatomStore/RocksDBDatomStore.cs index febd8ba4..d58c128a 100644 --- a/src/NexusMods.EventSourcing.DatomStore/RocksDBDatomStore.cs +++ b/src/NexusMods.EventSourcing.DatomStore/RocksDBDatomStore.cs @@ -7,15 +7,13 @@ using NexusMods.EventSourcing.Abstractions; using NexusMods.EventSourcing.DatomStore.Indexes; using RocksDbSharp; +// ReSharper disable InconsistentNaming namespace NexusMods.EventSourcing.DatomStore; public class RocksDBDatomStore : IDatomStore { private readonly object _lock = new(); - private readonly ILogger _logger; - private readonly DatomStoreSettings _settings; - private readonly DbOptions _options; private readonly RocksDb _db; private readonly PooledMemoryBufferWriter _pooledWriter; private readonly AttributeRegistry _registry; @@ -26,17 +24,14 @@ public class RocksDBDatomStore : IDatomStore public RocksDBDatomStore(ILogger logger, AttributeRegistry registry, DatomStoreSettings settings) { - _settings = settings; - _logger = logger; - _registry = registry; _registry.Populate(BuiltInAttributes.Initial); - _options = new DbOptions() + var options = new DbOptions() .SetCreateIfMissing() .SetCompression(Compression.Zstd); - _db = RocksDb.Open(_options, _settings.Path.ToString(), new ColumnFamilies()); + _db = RocksDb.Open(options, settings.Path.ToString(), new ColumnFamilies()); _eatvIndex = new EATVIndex(_registry); _eatvIndex.Init(_db); diff --git a/src/NexusMods.EventSourcing.DatomStore/Services.cs b/src/NexusMods.EventSourcing.DatomStore/Services.cs index b2a8799e..a2317abb 100644 --- a/src/NexusMods.EventSourcing.DatomStore/Services.cs +++ b/src/NexusMods.EventSourcing.DatomStore/Services.cs @@ -12,9 +12,6 @@ public static class Services /// /// Registers the event sourcing services with the service collection. /// - /// - /// - /// public static IServiceCollection AddDatomStore(this IServiceCollection services) { services diff --git a/src/NexusMods.EventSourcing/CommitResult.cs b/src/NexusMods.EventSourcing/CommitResult.cs index 7adf0cbc..8bae449c 100644 --- a/src/NexusMods.EventSourcing/CommitResult.cs +++ b/src/NexusMods.EventSourcing/CommitResult.cs @@ -4,7 +4,7 @@ namespace NexusMods.EventSourcing; /// -public class CommitResult(TxId newTxId, IDictionary remaps, Connection connection, IDatom[] datoms) : ICommitResult +public class CommitResult(TxId newTxId, IDictionary remaps, IDatom[] datoms) : ICommitResult { /// public EntityId this[EntityId id] => diff --git a/src/NexusMods.EventSourcing/Connection.cs b/src/NexusMods.EventSourcing/Connection.cs index f95eb8e9..2a7a8fea 100644 --- a/src/NexusMods.EventSourcing/Connection.cs +++ b/src/NexusMods.EventSourcing/Connection.cs @@ -133,7 +133,7 @@ EntityId RemapFn(EntityId input) } var newTx = _store.Transact(newDatoms); TxId = newTx; - var result = new CommitResult(newTx, remaps, this, datomsArray); + var result = new CommitResult(newTx, remaps, datomsArray); _updates.OnNext(result); return result; } diff --git a/src/NexusMods.EventSourcing/ModelReflector.cs b/src/NexusMods.EventSourcing/ModelReflector.cs index 34066aaf..65588bc5 100644 --- a/src/NexusMods.EventSourcing/ModelReflector.cs +++ b/src/NexusMods.EventSourcing/ModelReflector.cs @@ -43,8 +43,6 @@ public void Add(TTransaction tx, IReadModel model) /// /// Reflects over /// - /// - /// private EmitterFn CreateEmitter(Type readModel) { var properties = GetModelProperties(readModel); diff --git a/src/NexusMods.EventSourcing/Services.cs b/src/NexusMods.EventSourcing/Services.cs index 20a707b7..3e417864 100644 --- a/src/NexusMods.EventSourcing/Services.cs +++ b/src/NexusMods.EventSourcing/Services.cs @@ -11,9 +11,6 @@ public static class Services /// /// Registers the event sourcing services with the service collection. /// - /// - /// - /// public static IServiceCollection AddEventSourcing(this IServiceCollection services) { services.AddSingleton(); diff --git a/src/NexusMods.EventSourcing/Transaction.cs b/src/NexusMods.EventSourcing/Transaction.cs index 314659b3..410fa9fc 100644 --- a/src/NexusMods.EventSourcing/Transaction.cs +++ b/src/NexusMods.EventSourcing/Transaction.cs @@ -5,7 +5,8 @@ namespace NexusMods.EventSourcing; -public class Transaction(Connection connection) : ITransaction +/// +internal class Transaction(Connection connection) : ITransaction { private ulong _tempId = Ids.MinId(Ids.Partition.Tmp) + 1; private readonly ConcurrentBag _datoms = new(); diff --git a/tests/NexusMods.EventSourcing.DatomStore.Tests/ADatomStoreTest.cs b/tests/NexusMods.EventSourcing.DatomStore.Tests/ADatomStoreTest.cs index 5dbcdfb2..a3e55893 100644 --- a/tests/NexusMods.EventSourcing.DatomStore.Tests/ADatomStoreTest.cs +++ b/tests/NexusMods.EventSourcing.DatomStore.Tests/ADatomStoreTest.cs @@ -8,7 +8,6 @@ namespace NexusMods.EventSourcing.DatomStore.Tests; public abstract class ADatomStoreTest : IDisposable { private readonly AbsolutePath _tmpPath; - private readonly AttributeRegistry _registry; protected readonly RocksDBDatomStore Store; protected readonly Connection Connection; @@ -19,8 +18,8 @@ protected ADatomStoreTest(IEnumerable valueSerializers, IEnume { Path = _tmpPath, }; - _registry = new AttributeRegistry(valueSerializers, attributes); - Store = new RocksDBDatomStore(new NullLogger(), _registry, dbSettings); + var registry = new AttributeRegistry(valueSerializers, attributes); + Store = new RocksDBDatomStore(new NullLogger(), registry, dbSettings); Connection = new Connection(Store, attributes, valueSerializers); } diff --git a/tests/NexusMods.EventSourcing.DatomStore.Tests/Startup.cs b/tests/NexusMods.EventSourcing.DatomStore.Tests/Startup.cs index 623e54b0..385e51b5 100644 --- a/tests/NexusMods.EventSourcing.DatomStore.Tests/Startup.cs +++ b/tests/NexusMods.EventSourcing.DatomStore.Tests/Startup.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using NexusMods.EventSourcing.TestModel; namespace NexusMods.EventSourcing.DatomStore.Tests; diff --git a/tests/NexusMods.EventSourcing.DatomStore.Tests/TransactionLogTest.cs b/tests/NexusMods.EventSourcing.DatomStore.Tests/TransactionLogTest.cs deleted file mode 100644 index 8da8e188..00000000 --- a/tests/NexusMods.EventSourcing.DatomStore.Tests/TransactionLogTest.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NexusMods.EventSourcing.Abstractions; -using NexusMods.Paths; - -namespace NexusMods.EventSourcing.DatomStore.Tests; - -public class TransactionLogTest -{ - private readonly DatomStoreSettings _options; - private readonly RocksDBDatomStore _db; - private readonly IConnection _connection; - - - public TransactionLogTest(IServiceProvider s) - { - _options = new DatomStoreSettings - { - Path = FileSystem.Shared.GetKnownPath(KnownPath.TempDirectory).Combine("TransactionLogTest" + Guid.NewGuid()) - }; - _db = new RocksDBDatomStore(s.GetRequiredService>(), s.GetRequiredService(), _options); - _connection = null!; - } - - [Fact] - public void BasicTest() - { - - - } - -} diff --git a/tests/NexusMods.EventSourcing.TestModel/Services.cs b/tests/NexusMods.EventSourcing.TestModel/Services.cs index 72cf7667..c65b36a3 100644 --- a/tests/NexusMods.EventSourcing.TestModel/Services.cs +++ b/tests/NexusMods.EventSourcing.TestModel/Services.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using NexusMods.EventSourcing.Abstractions; using NexusMods.EventSourcing.TestModel.Model.Attributes; - +namespace NexusMods.EventSourcing.TestModel; public static class Services { diff --git a/tests/NexusMods.EventSourcing.Tests/AEventSourcingTest.cs b/tests/NexusMods.EventSourcing.Tests/AEventSourcingTest.cs index 1b9c0696..a91cedfb 100644 --- a/tests/NexusMods.EventSourcing.Tests/AEventSourcingTest.cs +++ b/tests/NexusMods.EventSourcing.Tests/AEventSourcingTest.cs @@ -8,7 +8,6 @@ namespace NexusMods.EventSourcing.Tests; public class AEventSourcingTest : IDisposable { private readonly AbsolutePath _tmpPath; - private readonly AttributeRegistry _registry; protected readonly RocksDBDatomStore Store; protected readonly Connection Connection; @@ -20,9 +19,12 @@ protected AEventSourcingTest(IEnumerable valueSerializers, { Path = _tmpPath, }; - _registry = new AttributeRegistry(valueSerializers, attributes); - Store = new RocksDBDatomStore(new NullLogger(), _registry, dbSettings); - Connection = new Connection(Store, attributes, valueSerializers); + var valueSerializerArray = valueSerializers.ToArray(); + + var attributeArray = attributes.ToArray(); + var registry = new AttributeRegistry(valueSerializerArray, attributeArray); + Store = new RocksDBDatomStore(new NullLogger(), registry, dbSettings); + Connection = new Connection(Store, attributeArray, valueSerializerArray); } public void Dispose() diff --git a/tests/NexusMods.EventSourcing.Tests/DbTests.cs b/tests/NexusMods.EventSourcing.Tests/DbTests.cs index 63d9b299..28759764 100644 --- a/tests/NexusMods.EventSourcing.Tests/DbTests.cs +++ b/tests/NexusMods.EventSourcing.Tests/DbTests.cs @@ -11,12 +11,12 @@ public class DbTests(IEnumerable valueSerializers, IEnumerable [Fact] public void ReadDatomsForEntity() { - const int TOTAL_COUNT = 10; + const int totalCount = 10; var tx = Connection.BeginTransaction(); var ids = new List(); - for (ulong idx = 0; idx < TOTAL_COUNT; idx++) + for (ulong idx = 0; idx < totalCount; idx++) { var file = new File(tx) { @@ -35,7 +35,7 @@ public void ReadDatomsForEntity() var db = Connection.Db; var resolved = db.Get(ids.Select(id => result[id])).ToArray(); - resolved.Should().HaveCount(TOTAL_COUNT); + resolved.Should().HaveCount(totalCount); foreach (var readModel in resolved) { var idx = readModel.Index; diff --git a/tests/NexusMods.EventSourcing.Tests/Startup.cs b/tests/NexusMods.EventSourcing.Tests/Startup.cs index b2b678dc..49ad71b2 100644 --- a/tests/NexusMods.EventSourcing.Tests/Startup.cs +++ b/tests/NexusMods.EventSourcing.Tests/Startup.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using NexusMods.EventSourcing.DatomStore; +using NexusMods.EventSourcing.TestModel; namespace NexusMods.EventSourcing.Tests;