Vixen
02b45cc4
csharp
public sealed class MemoryPersistence

The whole of persistence in a process. What every test in this tier runs against.

Read the guide page for this →

Remarks

⚠ This is Vixen.Net.Transport.Local's place in doc 27's testing story, and Placement.Process's. § Testing asks for a conservation oracle over thousands of randomised concurrent transfers, aborts and crashes; nobody runs that against a database on every push, so nobody runs it. Here it is a unit test that finishes in a second, and the property it proves — that the semantics conserve value — is a property of the semantics rather than of Postgres.

⚠ It is not a deployment target. Nothing here survives the process, and doc 27 M-Q3's one implementation behind an interface means SqlPersistence is the shipped one. A game that ran on this would lose every character on restart, which is why the type name says what it is.

One lock over everything, deliberately. A store whose whole state is three dictionaries has no contention worth optimising, and a coarse lock is how the atomicity the interface promises — an intent applies whole or not at all — is obviously correct rather than argued.

Fields and properties (5)

  • public Func<DateTimeOffset> Clock

    The store's own clock, so a test can make "recorded at" deterministic.

  • public IAccountRepository Accounts

    Accounts.

  • public IPlayerRepository Players

    Characters.

  • public ILedger Ledger

    The journal.

  • public int JournalLength

    How many rows the journal holds.

Methods (16)

  • public Task<int> MigrateAsync(CancellationToken cancellation)
  • public ValueTask DisposeAsync()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

  • public Task<AccountRecord?> ReadAsync(Guid id, CancellationToken cancellation)

    Reads an account.

  • public Task<AccountRecord?> ByHandleAsync(string handle, CancellationToken cancellation)

    Finds the account an authority's handle maps to.

  • public Task<(AccountRecord Account, bool Created)> EnsureAsync(string handle, DateTimeOffset now, CancellationToken cancellation)

    Makes an account for a handle that has none.

  • public Task<WriteOutcome> SetSuspendedAsync(Guid id, bool suspended, CancellationToken cancellation)

    Suspends an account, or lifts it.

  • public Task<PlayerRecord?> ReadAsync(PlayerKey key, CancellationToken cancellation)

    Reads a character.

  • public Task<IReadOnlyList<PlayerRecord>> ForAccountAsync(Guid account, CancellationToken cancellation)

    Every character on an account — the list the gate serves at character select.

  • public Task<WriteOutcome> CreateAsync(PlayerRecord record, CancellationToken cancellation)

    Makes a character.

  • public Task<WriteOutcome> WriteAsync(PlayerRecord record, CancellationToken cancellation)

    Writes a character, if the writer still holds the lease.

  • public Task<long> FenceAsync(PlayerKey key, CancellationToken cancellation)

    The epoch this character's row will accept a write at or above.

  • public Task<LedgerResult> AppendAsync(LedgerIntent intent, CancellationToken cancellation)

    Applies an intent, or recognises that it already was.

  • public Task<long> BalanceAsync(LedgerAccount account, AssetId asset, CancellationToken cancellation)

    What an account holds of an asset.

  • public Task<IReadOnlyDictionary<AssetId, long>> HoldingsAsync(LedgerAccount account, CancellationToken cancellation)

    Everything an account holds.

  • public Task<IReadOnlyList<LedgerEntry>> HistoryAsync(LedgerQuery query, CancellationToken cancellation)

    Reads the journal.

  • public Task<IReadOnlyList<LedgerDiscrepancy>> ReconcileAsync(CancellationToken cancellation)

    Checks the running balances against the journal they were derived from.

Used by (5)

  • ConservationTestsVixen.Live.Persistence.Tests
  • GateServiceTestsVixen.Live.Gate.Tests
  • LedgerTestsVixen.Live.Persistence.Tests
  • RepositoryTestsVixen.Live.Persistence.Tests
  • TransferFleetVixen.Live.Realm.Tests