LiteBus
CatalogStorage

Inbox InMemory Adapter

  • ID: storage.inbox.adapter.inmemory
  • Name: Inbox InMemory adapter
  • Maturity: GA
  • Summary: Thread-safe in-process inbox store for unit tests, samples, and local development without external database dependencies.

What It Does

InMemoryInboxStore implements all inbox store roles in memory with locking semantics aligned to PostgreSQL contract tests. Registration:

inbox.UseInMemoryStorage();

Optional builder configures tenant defaults and strictness for tests. No schema management, NOTIFY, or transactional bindings.

Public Surface

Consumer Contracts

TypeRole
InMemoryInboxStoreAll inbox store roles in-process
InMemoryInboxStorageModuleBuilderCapacity, lease duration, TimeProvider
IInboxStore through IInboxOperationsStoreSame abstractions as relational adapters

Invocation

MethodTypical caller
IInboxStore.AddAsyncUnit tests, samples, local dev
IInboxLeaseStore.LeasePendingAsyncProcessor tests with in-process dispatch
GetAll (test helper)Filter diagnostics in unit tests

Registration

inbox.UseInMemoryStorage(o => o.UseTimeProvider(timeProvider));
  • Registers all inbox store roles on one singleton instance.
  • Second UseInMemoryStorage on same builder throws.

Configuration

Option surfacePurpose
InMemoryInboxStoreOptions.MaxCapacityThrow on append when capacity exceeded (unless idempotent)
InMemoryInboxStoreOptions.DefaultLeaseDurationLease duration when zero passed to lease API
UseTimeProviderDeterministic lease expiry in tests

Extension Points

  • None for durability or cross-process visibility; swap to PostgreSQL or EF adapter for production.

Packages

PackageDependency role
LiteBus.Inbox.Storage.InMemoryFeature bridge

No external NuGet dependencies beyond inbox abstractions.

Requires

  • AddInbox with dispatch for processor tests

Invariants

  • Contract behavior matches relational stores per InboxStoreContractTests.
  • Process restart clears all data (non-durable by design).

Non-Goals

  • Production durability
  • Cross-process visibility
  • Transactional participation with real databases

Observability

MeterInstrumentTypeWhen observedTagsStorage coupling
LiteBus.Inboxlitebus.inbox.queue.depthObservable gaugeOpenTelemetry scrapelitebus.inbox.statusIn-memory counts from diagnostics role
LiteBus.Inboxlitebus.inbox.processor.leases_acquiredCounterProcessor pass in test host:In-memory lease store
LiteBus.Inboxlitebus.inbox.processor.stateObservable gaugeProcessor loopState enumTest hosts with processor enabled

In-memory stores report synthetic schema info suitable for tests. Register through AddLiteBusInboxMetrics(). Constants on LiteBusInboxTelemetry.

Deep Docs

Test Coverage

Covered

InboxStoreContractTests (in LiteBus.Inbox.Storage.InMemory.UnitTests)

  • Use case: Full inbox store contract in memory
  • Test kind: Contract (unit)
  • Description: Complete shared inbox contract suite against InMemoryInboxStore
  • Behavior: All append, lease, persist, query, diagnostics tests
  • Expected outcome: Parity with LiteBus.Storage.Testing expectations
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InboxRetentionStoreContractTests (in LiteBus.Inbox.Storage.InMemory.UnitTests)

  • Use case: Full inbox retention contract in memory
  • Test kind: Contract (unit)
  • Description: Retention delete eligibility tests
  • Behavior: DeleteCompletedOlderThanAsync variants
  • Expected outcome: Same outcomes as shared retention contract
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStorageModuleTests.UseInMemoryStorage_ShouldRegisterAllStoreRoles

  • Use case: Register all inbox store roles
  • Test kind: Unit
  • Description: Build module with in-memory storage
  • Behavior: Resolve store interfaces
  • Expected outcome: All roles registered on singleton
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStorageModuleTests.UseInMemoryStorage_WithCustomTimeProvider_ShouldRegisterTimeProvider

  • Use case: Register custom TimeProvider on module
  • Test kind: Unit
  • Description: Pass custom TimeProvider to builder
  • Behavior: Resolve store and check time source
  • Expected outcome: Custom provider used for lease timing
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStorageModuleTests.UseInMemoryStorage_WhenCalledTwiceOnBuilder_ShouldThrow

  • Use case: Throw when UseInMemoryStorage called twice
  • Test kind: Unit
  • Description: Duplicate storage registration on same builder
  • Behavior: Second UseInMemoryStorage call
  • Expected outcome: Configuration exception
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStoreOptionsTests.AddAsync_WhenCapacityReached_ShouldThrow

  • Use case: Throw when capacity reached on append
  • Test kind: Unit
  • Description: Store at max capacity
  • Behavior: Append new non-idempotent message
  • Expected outcome: Capacity exception thrown
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStoreOptionsTests.AddAsync_WhenCapacityReachedButSubmissionIsIdempotent_ShouldReturnExistingCommand

  • Use case: Return existing row when capacity reached but idempotent
  • Test kind: Unit
  • Description: Store at capacity; duplicate idempotency key
  • Behavior: Append with existing idempotency key
  • Expected outcome: Existing envelope returned without throw
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStoreOptionsTests.LeasePendingAsync_WhenLeaseDurationIsZero_ShouldUseDefaultLeaseDuration

  • Use case: Default lease duration when zero configured
  • Test kind: Unit
  • Description: Lease with zero duration parameter
  • Behavior: LeasePendingAsync
  • Expected outcome: Default from options applied
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxStoreOptionsTests.LeasePendingAsync_WhenNowIsOmitted_ShouldUseTimeProviderForLeaseExpiry

  • Use case: TimeProvider drives lease expiry when now omitted
  • Test kind: Unit
  • Description: Custom TimeProvider on store
  • Behavior: Lease without explicit now; advance time
  • Expected outcome: Reclaim follows provider clock
  • Remarks: LiteBus.Inbox.Storage.InMemory.UnitTests

InMemoryInboxGetAllFilterTests.GetAll_WithStatusAndContractName_ShouldFilterResults

  • Use case: Filter InMemory inbox via GetAll test helper
  • Test kind: Unit
  • Description: Test-only GetAll with status and contract filters
  • Behavior: Filter predicates
  • Expected outcome: Matching subset returned
  • Remarks: Test-only surface; LiteBus.Inbox.Storage.InMemory.UnitTests

Untested

  • Cross-process visibility between two hosts (by design in-process only).

Out-of-Scope

  • Production durability and NOTIFY.
  • Transactional participation with real databases.
  • Schema management.

On this page