bane 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +30 -30
- data/Rakefile +31 -40
- data/TODO +18 -10
- data/bin/bane +15 -10
- data/examples/multiple_behaviors.rb +24 -0
- data/examples/readme_example.rb +9 -0
- data/examples/single_behavior.rb +18 -0
- data/lib/bane.rb +2 -2
- data/lib/bane/{delegating_gserver.rb → behavior_server.rb} +11 -6
- data/lib/bane/behaviors.rb +29 -20
- data/lib/bane/command_line_configuration.rb +96 -0
- data/lib/bane/configuration_parser.rb +19 -4
- data/lib/bane/launcher.rb +7 -8
- data/lib/bane/service_registry.rb +4 -0
- data/test/bane/{delegating_gserver_test.rb → behavior_server_test.rb} +19 -16
- data/test/bane/behaviors_test.rb +32 -36
- data/test/bane/command_line_configuration_test.rb +100 -0
- data/test/bane/configuration_parser_test.rb +42 -55
- data/test/bane/fake_connection_test.rb +1 -1
- data/test/bane/integration_test.rb +45 -20
- data/test/bane/naive_http_response_test.rb +1 -1
- data/test/bane/service_registry_test.rb +1 -1
- metadata +63 -44
- data/examples/simple_port_and_class_as_constant.rb +0 -9
- data/examples/simple_port_and_class_as_string.rb +0 -7
- data/examples/specify_behavior_options.rb +0 -16
- data/examples/specify_ports.rb +0 -15
- data/lib/bane/configuration.rb +0 -50
- data/test/bane/configuration_test.rb +0 -52
- data/test/bane/launcher_test.rb +0 -16
@@ -1,16 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
require 'bane'
|
3
|
-
|
4
|
-
include Bane
|
5
|
-
include Behaviors
|
6
|
-
|
7
|
-
launcher = Launcher.new(Configuration(
|
8
|
-
10256 => {:behavior => CloseAfterPause, :duration => 3},
|
9
|
-
10593 => {:behavior => FixedResponse, :message => "Hey!"},
|
10
|
-
10689 => {:behavior => SlowResponse, :message => "Custom message", :pause_duration => 15},
|
11
|
-
11239 => CloseAfterPause # Use the defaults for this behavior, don't need a Hash
|
12
|
-
)
|
13
|
-
)
|
14
|
-
launcher.start
|
15
|
-
launcher.join
|
16
|
-
# runs until interrupt...
|
data/examples/specify_ports.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
require 'bane'
|
3
|
-
|
4
|
-
include Bane
|
5
|
-
include Behaviors
|
6
|
-
|
7
|
-
launcher = Launcher.new(Configuration(
|
8
|
-
10256 => CloseAfterPause,
|
9
|
-
10689 => CloseAfterPause, # severs may be repeated
|
10
|
-
11999 => CloseImmediately
|
11
|
-
)
|
12
|
-
)
|
13
|
-
launcher.start
|
14
|
-
launcher.join
|
15
|
-
# runs until interrupt...
|
data/lib/bane/configuration.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Bane
|
2
|
-
|
3
|
-
class Configuration
|
4
|
-
|
5
|
-
def initialize(configurations)
|
6
|
-
@configurations = configurations
|
7
|
-
end
|
8
|
-
|
9
|
-
def start(logger)
|
10
|
-
@configurations.map do |config|
|
11
|
-
config.start(logger)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ConfigurationRecord
|
16
|
-
|
17
|
-
def initialize(port, behavior, options = {})
|
18
|
-
@port = port
|
19
|
-
@behavior = behavior
|
20
|
-
@options = options
|
21
|
-
end
|
22
|
-
|
23
|
-
def start(logger)
|
24
|
-
new_server = DelegatingGServer.new(@port, @behavior.new, @options, logger)
|
25
|
-
new_server.start
|
26
|
-
new_server
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class ConfigurationError < RuntimeError; end
|
33
|
-
|
34
|
-
class UnknownBehaviorError < RuntimeError
|
35
|
-
def initialize(name)
|
36
|
-
super "Unknown behavior: #{name}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
# Helper method to easily create configuration.
|
43
|
-
#
|
44
|
-
# This should likely take the constructor block from the Configuration class
|
45
|
-
# and then we can simplify this class so it's not so big.
|
46
|
-
module Kernel
|
47
|
-
def Configuration(*args)
|
48
|
-
Bane::Configuration.new(Bane::ConfigurationParser.new(*args).configurations)
|
49
|
-
end
|
50
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
module Bane
|
5
|
-
module Behaviors
|
6
|
-
class FakeTestServer < BasicBehavior
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ConfigurationTest < Test::Unit::TestCase
|
12
|
-
|
13
|
-
include Bane
|
14
|
-
|
15
|
-
def test_starts_server_on_specified_port
|
16
|
-
target_port = 4000
|
17
|
-
DelegatingGServer.expects(:new).with(equals(target_port), anything(), anything(), anything()).returns(fake_server)
|
18
|
-
|
19
|
-
start_configuration(target_port, Behaviors::FakeTestServer)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_starts_server_with_specified_behavior
|
23
|
-
behavior_instance = stub('constructed behavior instance')
|
24
|
-
Behaviors::FakeTestServer.expects(:new).returns(behavior_instance)
|
25
|
-
DelegatingGServer.expects(:new).with(anything(), equals(behavior_instance), anything(), anything()).returns(fake_server)
|
26
|
-
|
27
|
-
start_configuration(IRRELEVANT_PORT, Behaviors::FakeTestServer)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_constructs_server_with_specified_options
|
31
|
-
options = { :an_option => :a_value, :another_option => :another_value }
|
32
|
-
DelegatingGServer.expects(:new).with(anything(), anything, has_entries(options), anything()).returns(fake_server)
|
33
|
-
|
34
|
-
start_configuration(IRRELEVANT_PORT, Behaviors::FakeTestServer, options)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def start_configuration(target_port, behavior, options = {})
|
40
|
-
configuration = configuration_with(target_port, behavior, options)
|
41
|
-
configuration.start(StringIO.new)
|
42
|
-
end
|
43
|
-
|
44
|
-
def configuration_with(port, behavior, options)
|
45
|
-
Configuration.new([Configuration::ConfigurationRecord.new(port, behavior, options)])
|
46
|
-
end
|
47
|
-
|
48
|
-
def fake_server
|
49
|
-
stub_everything('fake_server')
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/test/bane/launcher_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class LauncherTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Bane
|
7
|
-
|
8
|
-
def test_start_delegates_to_configuration
|
9
|
-
configuration = mock()
|
10
|
-
logger = stub()
|
11
|
-
launcher = Launcher.new(configuration, logger)
|
12
|
-
|
13
|
-
configuration.expects(:start).with(equals(logger))
|
14
|
-
launcher.start
|
15
|
-
end
|
16
|
-
end
|