Skip to main content

managed_db_test.go

managed_db_test.go - Overview

This file contains tests for the DB struct, specifically focusing on managed transactions, dropping data (all or with prefix), and write batch functionalities within the Badger database.

Detailed Documentation

Functions:

val(large bool) []byte

  • Purpose: Generates a byte slice of either 16 or 8192 bytes, filled with random data.
  • Parameters:
    • large (bool): If true, returns a larger (8192 bytes) byte slice; otherwise, returns a smaller (16 bytes) byte slice.
  • Returns: A byte slice containing random data.

numKeys(db *DB) int

  • Purpose: Counts the number of keys in the database using a read-only transaction.
  • Parameters:
    • db (*DB): A pointer to the Badger database.
  • Returns: The number of keys in the database.

numKeysManaged(db *DB, readTs uint64) int

  • Purpose: Counts the number of keys in the database at a given read timestamp using a read-only transaction.
  • Parameters:
    • db (*DB): A pointer to the Badger database.
    • readTs (uint64): The timestamp to read at.
  • Returns: The number of keys in the database at the specified timestamp.

TestDropAllManaged(t *testing.T)

  • Purpose: Tests the DropAll functionality in managed transaction mode.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropAll(t *testing.T)

  • Purpose: Tests the DropAll functionality in normal (non-managed) mode.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropAllTwice(t *testing.T)

  • Purpose: Tests calling DropAll twice in a row. This test covers both disk and in-memory modes.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropAllWithPendingTxn(t *testing.T)

  • Purpose: Tests the DropAll functionality when there is a pending transaction.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropReadOnly(t *testing.T)

  • Purpose: Tests that DropAll panics when the database is opened in read-only mode.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestWriteAfterClose(t *testing.T)

  • Purpose: Tests that writing to the database after it has been closed returns an error.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropAllRace(t *testing.T)

  • Purpose: Tests for race conditions when DropAll is called concurrently with writes.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropPrefix(t *testing.T)

  • Purpose: Tests the DropPrefix functionality.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropPrefixWithPendingTxn(t *testing.T)

  • Purpose: Tests the DropPrefix functionality when there is a pending transaction.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropPrefixReadOnly(t *testing.T)

  • Purpose: Tests that DropPrefix panics when the database is opened in read-only mode.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestDropPrefixRace(t *testing.T)

  • Purpose: Tests for race conditions when DropPrefix is called concurrently with writes.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestWriteBatchManagedMode(t *testing.T)

  • Purpose: Tests the WriteBatch functionality in managed transaction mode, specifically when using NewWriteBatchAt.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestWriteBatchManaged(t *testing.T)

  • Purpose: Tests the ManagedWriteBatch functionality.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestWriteBatchDuplicate(t *testing.T)

  • Purpose: Tests the behavior of write batches when multiple versions of the same key are written.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

TestZeroDiscardStats(t *testing.T)

  • Purpose: Tests that discard stats are zeroed after a value log rewrite or a DropAll operation.
  • Parameters:
    • t (*testing.T): Testing object for running test cases.
  • Returns: None.

Getting Started Relevance