Class: Synthra::Behaviors::CloseConnection

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/behaviors/close_connection.rb

Overview

Close connection behavior - simulates connection drop

Raises SimulatedConnectionDrop exception when activated, simulating a network connection failure.

Examples:

Apply close connection behavior

behavior = CloseConnection.new(5, rng)  # 5% probability
begin
  behavior.apply({ "name" => "John" })
rescue SimulatedConnectionDrop => e
  # Handle connection drop
end

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Synthra::Behaviors::Base

Instance Method Details

#apply(result, context = nil) ⇒ Object

Apply close connection behavior

Raises SimulatedConnectionDrop if the behavior should be applied based on probability.

Parameters:

  • result (Object)

    generated data (not modified)

  • context (Generator::Context, nil) (defaults to: nil)

    generation context (not used)

Returns:

  • (Object)

    result (if behavior not applied)

Raises:



50
51
52
53
54
55
56
# File 'lib/synthra/behaviors/close_connection.rb', line 50

def apply(result, context = nil)
  if should_apply?
    probability = extract_probability
    raise SimulatedConnectionDrop.new(probability: probability)
  end
  result
end