Class TemporaryDb

java.lang.Object
All Implemented Interfaces:
CloseableNativeProxy, Database, java.lang.AutoCloseable

public final class TemporaryDb
extends AbstractCloseableNativeProxy
implements Database
A MerkleDB which stores its data in the temporary directory for testing purposes. It can create both read-only snapshots and read-write forks. The changes made to database forks can be applied to the database state.

The corresponding database is deleted when TemporaryDb is closed.

See Also:
NodeFake
  • Method Details

    • newInstance

      public static TemporaryDb newInstance()
      Creates a new empty TemporaryDb.
    • createSnapshot

      public Snapshot createSnapshot​(Cleaner cleaner)
      Description copied from interface: Database
      Creates a new snapshot of the database state.
      Specified by:
      createSnapshot in interface Database
      Parameters:
      cleaner - a cleaner to register the snapshot
      Returns:
      a new snapshot of the database state
    • createFork

      public Fork createFork​(Cleaner cleaner)
      Description copied from interface: Database
      Creates a new database fork.

      A fork allows to perform a transaction: a number of independent writes to a database, which then may be atomically applied to the database.

      Specified by:
      createFork in interface Database
      Parameters:
      cleaner - a cleaner to register the fork
      Returns:
      a new database fork
    • merge

      public void merge​(Fork fork)
      Applies the changes from the given fork to the database state. TemporaryDb can only merge forks that it created itself.

      Once this method completes, any indexes created with the fork and the fork itself are closed and cannot be used anymore. Any subsequent operations on these objects will result in IllegalStateException.

      Parameters:
      fork - a fork to get changes from
      Throws:
      java.lang.RuntimeException - if the fork cannot be applied to the database state. The provided fork will be closed
    • disposeInternal

      protected void disposeInternal()
      Description copied from class: AbstractCloseableNativeProxy
      Releases any resources owned by this proxy (e.g., the corresponding native object).

      This method is only called once from AbstractCloseableNativeProxy.close() for a valid proxy and shall not be called directly.

      Specified by:
      disposeInternal in class AbstractCloseableNativeProxy