Spex.InstanceManager behaviour (spex v0.1.1)

Copy Markdown View Source

Behaviour contract plus shared helpers for Spex instance managers.

Summary

Callbacks

Returns all currently known implementation models.

Returns all instances managed by this instance manager.

Returns all instances for a given specification module.

Returns a child spec for supervising the instance manager.

Deletes one instance by identifier.

Deletes all instances matching the provided filter function.

Serialises and exports implementation models as {filename, content} tuples.

Fetches one instance by identifier.

Initializes a new instance and records initialisation as the first transition.

Same as init_instance/4, but raises on errors.

Same as init_instance/4, but performs operation asynchronously. Errors are still routed to the specification's error handler, but its return value is ignored.

Inserts or updates a mock instance at a given state for testing purposes.

Starts the instance manager process tree.

Records an observed transition for an existing instance.

Same as transition/3, but raises on errors.

Same as transition/3, but performs operation asynchronously. Errors are still routed to the specification's error handler, but its return value is ignored.

Functions

Injects the Spex.InstanceManager behaviour and shared convenience functions.

Returns the compile-time configured default instance manager module.

Returns compile-time options for the default instance manager.

Types

instance_manager_opt()

@type instance_manager_opt() ::
  Spex.InstanceManager.Server.server_opt() | (other_opt :: {atom(), term()})

Callbacks

all_impl_models()

@callback all_impl_models() :: {:ok, [Spex.ImplModel.t()]}

Returns all currently known implementation models.

all_instances()

@callback all_instances() ::
  {:ok, [Spex.InstanceManager.Instance.t()]}
  | {:error, Spex.Errors.DetsError.t()}

Returns all instances managed by this instance manager.

all_instances(t)

@callback all_instances(Spex.Specification.t()) ::
  {:ok, [Spex.InstanceManager.Instance.t()]}
  | {:error, Spex.Errors.DetsError.t()}

Returns all instances for a given specification module.

child_spec(term)

@callback child_spec(term()) :: Supervisor.child_spec()

Returns a child spec for supervising the instance manager.

delete_instance(instance_identifier)

@callback delete_instance(Spex.InstanceManager.Instance.instance_identifier()) ::
  :ok | {:error, Spex.Errors.DetsError.t()}

Deletes one instance by identifier.

delete_instances(function)

@callback delete_instances((Spex.InstanceManager.Instance.t() -> as_boolean(term()))) ::
  :ok | {:error, Spex.Errors.DetsError.t()}

Deletes all instances matching the provided filter function.

export_impl_models()

@callback export_impl_models() ::
  {:ok, [{filename :: String.t(), Spex.ImplModel.serialisation()}]}

Serialises and exports implementation models as {filename, content} tuples.

get_instance(instance_identifier)

Fetches one instance by identifier.

init_instance(t, instance_identifier, arg3, arg4)

Initializes a new instance and records initialisation as the first transition.

Returns :ok on success. On failure, the error is routed to the specification's error handler and its return is returned.

init_instance!(t, instance_identifier, arg3, arg4)

Same as init_instance/4, but raises on errors.

init_instance_async(t, instance_identifier, arg3, arg4)

(optional)

Same as init_instance/4, but performs operation asynchronously. Errors are still routed to the specification's error handler, but its return value is ignored.

mock_instance!(t, instance_identifier, state, arg4)

Inserts or updates a mock instance at a given state for testing purposes.

start_link(list)

@callback start_link([instance_manager_opt()]) :: Supervisor.on_start()

Starts the instance manager process tree.

transition(instance_identifier, action, state)

Records an observed transition for an existing instance.

Returns :ok on success. On failure, the error is routed to the specification's error handler and its return is returned.

Note that errors of the form %Spex.Errors.InstanceError{reason: :instance_identifier_not_found} are routed to the default error handler Spex.Specification.default_error_handler/2 directly, which logs and returns it, since the specification cannot be determined without an instance.

transition!(instance_identifier, action, state)

Same as transition/3, but raises on errors.

transition_async(instance_identifier, action, state)

(optional)
@callback transition_async(
  Spex.InstanceManager.Instance.instance_identifier(),
  Spex.action(),
  Spex.state()
) :: :ok

Same as transition/3, but performs operation asynchronously. Errors are still routed to the specification's error handler, but its return value is ignored.

Functions

__using__(_)

(macro)

Injects the Spex.InstanceManager behaviour and shared convenience functions.

Generated convenience functions:

  • child_spec/1
  • init_instance!/4
  • transition!/3

default_instance_manager()

@spec default_instance_manager() :: module()

Returns the compile-time configured default instance manager module.

default_instance_manager_opts()

@spec default_instance_manager_opts() :: keyword()

Returns compile-time options for the default instance manager.