ExWapp.Store.Memory (ExWapp v0.1.2)

Copy Markdown View Source

In-memory store adapter for testing.

Data is stored in an Agent process and is not persisted to disk. Useful for unit tests and development scenarios where persistence is not required.

Examples

# Create a memory store
store = ExWapp.Store.Memory.new()

# Use in tests
ExWapp.connect(store: ExWapp.Store.Memory)

# Pre-populate with data
store = ExWapp.Store.Memory.new(initial_data: %{foo: "bar"})

Testing Usage

defmodule MyTest do
  use ExUnit.Case

  setup do
    store = ExWapp.Store.Memory.new()
    {:ok, store: store}
  end

  test "stores data", %{store: store} do
    assert :ok = ExWapp.Store.persist(store, %{key: "value"})
    assert {:ok, %{key: "value"}} = ExWapp.Store.load(store)
  end
end

Summary

Types

t()

@type t() :: %ExWapp.Store.Memory{
  agent: pid(),
  message_table: ExWapp.Store.MessageTable.t()
}

Functions

get(memory, key, default \\ nil)

@spec get(t(), atom(), term()) :: term()

load_device_cache(store)

@spec load_device_cache(t()) :: map()

load_signal_sessions(store)

@spec load_signal_sessions(t()) :: term()

persist_device_cache(memory, cache)

@spec persist_device_cache(t(), map()) :: :ok

persist_signal_sessions(memory, sessions)

@spec persist_signal_sessions(t(), term()) :: :ok

stop(memory)

@spec stop(t()) :: :ok

Stops the underlying Agent process.

Call this in test teardown if you want to clean up the process.

update(memory, key, value)

@spec update(t(), atom(), term()) :: :ok

Updates specific keys in the store without replacing all data.

This is a convenience function for tests that need to modify specific fields.

Examples

store = ExWapp.Store.Memory.new()
ExWapp.Store.Memory.update(store, :noise, %{static_private: <<...>>})