Class ScenarioLockManager

java.lang.Object
io.karatelabs.core.ScenarioLockManager

public class ScenarioLockManager extends Object
Manages locks for parallel scenario execution.

Supports two types of locks via the @lock tag:

  • @lock=<name> - Named lock for mutual exclusion. Scenarios with the same lock name will run sequentially, but scenarios with different lock names can run concurrently.
  • @lock=* - Exclusive lock. The scenario runs exclusively - no other scenarios can run concurrently, even those with different lock names.

Implementation uses a read-write lock pattern:

  • Named locks acquire the global read lock (allows concurrent execution with other named locks)
  • Exclusive locks acquire the global write lock (blocks all other scenarios)
  • Field Details

    • EXCLUSIVE_LOCK

      public static final String EXCLUSIVE_LOCK
      The special lock name that indicates exclusive execution.
      See Also:
  • Constructor Details

    • ScenarioLockManager

      public ScenarioLockManager()
  • Method Details

    • acquire

      public ScenarioLockManager.LockHandle acquire(Scenario scenario)
      Acquire locks for a scenario based on its @lock tags. Returns a handle that must be used to release the locks.

      All scenarios acquire at least the global read lock to ensure @lock=* scenarios can truly run exclusively. The overhead is minimal (~100ns) for uncontended read locks.

      Parameters:
      scenario - the scenario to acquire locks for
      Returns:
      a LockHandle to release the locks (never null)
    • release

      public void release(ScenarioLockManager.LockHandle handle)
      Release locks previously acquired for a scenario.
      Parameters:
      handle - the lock handle returned by acquire()