bane 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +10 -0
  2. data/README.md +95 -0
  3. data/Rakefile +54 -2
  4. data/lib/bane/compatibility.rb +16 -0
  5. metadata +56 -22
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2010, Daniel J. Wellman
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10
+
@@ -0,0 +1,95 @@
1
+ # Bane
2
+
3
+ Bane is a test harness used to test your application's interaction with other servers. It is based upon the material from Michael Nygard's ["Release It!"](http://www.pragprog.com/titles/mnee/release-it) book as described in the "Test Harness" chapter.
4
+
5
+ ## Setup
6
+
7
+ Bane is available as a gem. Install it with
8
+
9
+ `sudo gem install bane`
10
+
11
+ Note that Bane installs an executable, `bane`. Simply invoke `bane` with no arguments to get a usage description.
12
+
13
+ ## Usage
14
+
15
+ Bane is designed with a few usage scenarios in mind:
16
+
17
+ 1. Quick start with a specific behavior from the command line. If your application talks to another server on a given port, you can start Bane from the command line by specifying the desired port and a name of server behavior. For example, if your server talks to a third-party server on port 8080, you could start the "Never Respond" behavior on port 8080 to observe how your application behaves.
18
+
19
+ Example: `$ bane 8080 NeverRespond`
20
+
21
+ 2. Quick start with multiple specific behaviors from the command line. This will start each behavior on consecutive ports.
22
+
23
+ Example: `$ bane 8080 NeverRespond CloseImmediately`
24
+
25
+ 3. Quick start with all known behaviors from the command line. This also starts each behavior on a consecutive port, starting from the supplied starting port. If you just want a general purpose test harness to run, and you can easily control the ports that your application talks to, you can start Bane up with a base port number and it will start all its known behaviors. This way you can leave Bane running and tweak your application to talk to each of the various behaviors.
26
+
27
+ Example: `$ bane 3000`
28
+
29
+ 4. Advanced Configuration using Ruby. If you want to modify some of the defaults used in the included behaviors, you can initialize Bane with a Hash of port numbers, behavior names, and configuration parameters. For example, you might want to specify a response for the FixedResponse behavior:
30
+
31
+ Example:
32
+
33
+ require 'bane'
34
+
35
+ include Bane
36
+ include Behaviors
37
+
38
+ launcher = Launcher.new(Configuration(
39
+ 3000 => {:behavior => FixedResponse, :message => "Shall we play a game?"},
40
+ )
41
+ )
42
+ launcher.start
43
+ launcher.join
44
+
45
+ See `examples/specify_behavior_options.rb` for another example. For a list of options supported by the
46
+ basic behaviors, see the source for the behaviors in `Bane::Behaviors` at `lib/bane/behaviors.rb`.
47
+
48
+ ## Background
49
+
50
+ See the "Test Harness" chapter from "Release It!" to read about the inspiration of Bane.
51
+
52
+ The following behaviors are currently supported in Bane, with the name of the behavior after the description in parenthesis.
53
+ Note that these are simple protocol-independent socket behaviors:
54
+
55
+ * The connection can be established, but the remote end never sends a byte of data (NeverRespond)
56
+ * The service can send one byte of the response every thirty seconds (SlowResponse)
57
+ * The server establishes a connection but sends a random reply (RandomResponse)
58
+ * The server accepts a connection and then drops it immediately (CloseImmediately)
59
+ * The service can send megabytes when kilobytes are expected. (rough approximation with the DelugeReponse)
60
+ * The service can refuse all authentication credentials. (HttpRefuseAllCredentials)
61
+
62
+ The following behaviors are not yet supported; they require the configuration of an HTTP server.
63
+ See the implementation of HttpRefuseAllCredentials for a simple example of an HTTP behavior.
64
+
65
+ * The service can accept a request, send response headers (supposing HTTP), and never send the response body.
66
+ * The service can send a response of HTML instead of the expected XML.
67
+
68
+ The following behaviors are not yet supported. These require the ability to manipulate
69
+ TCP packets at a low level; which may require a C or C++ extension.
70
+
71
+ * The connection can be refused.
72
+ * The request can sit in a listen queue until the caller times out.
73
+ * The remote end can reply with a SYN/ACK and then never send any data.
74
+ * The remote end can send nothing but RESET packets.
75
+ * The remote end can report a full receive window and never drain the data.
76
+ * The connection can be established, but packets could be lost causing retransmit delays
77
+ * The connection can be established, but the remote end never acknowledges receiving a packet, causing endless retransmits
78
+
79
+ ## Design
80
+
81
+ Bane Behaviors are simple objects which implement the Strategy pattern. This makes them
82
+ simple to unit test and allows them to be independent of the underlying server implementation.
83
+ Bane currently serves all Behaviors using Ruby's built-in GServer, which provides a simple
84
+ multi-threaded TCP server. Behaviors currently:
85
+
86
+ * Accept an IO stream used to read from or send a response.
87
+ * Accept a hash of configuration options to allow overriding of default behavior parameters.
88
+ * Provide a meaningful name to appear in the Bane log. This is especially helpful if your application
89
+ under test dies and you'd like to identify which behavior killed it.
90
+
91
+ To enable support of different types of behaviors such as HTTP responses or low-level TCP packet
92
+ munging, a different base server instead of GServer may be required. In that case, it should
93
+ be possible to change how Behaviors are associated with a server, perhaps by making
94
+ Behaviors extend a server base class.
95
+
data/Rakefile CHANGED
@@ -1,8 +1,60 @@
1
- require 'rake/testtask'
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "bane"
8
+ gem.summary = "A test harness for socket connections based upon ideas from Michael Nygard's 'Release It!'"
9
+ gem.description = <<-END
10
+ Bane is a test harness used to test your application's interaction with
11
+ other servers. It is based upon the material from Michael Nygard's "Release
12
+ It!" book as described in the "Test Harness" chapter.
13
+ END
14
+ gem.authors = ["Daniel Wellman"]
15
+ gem.email = "dan@danielwellman.com"
16
+ gem.homepage = "http://github.com/danielwellman/bane"
17
+ gem.files = FileList[ 'lib/**/*', 'bin/*', 'test/**/*', 'examples/*',
18
+ 'Rakefile' ]
19
+ gem.add_development_dependency('mocha', '>= 0.9.8')
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
2
25
 
26
+ require 'rake/testtask'
3
27
  desc "Run all tests"
4
28
  Rake::TestTask.new do |test|
5
29
  test.libs << 'test'
6
30
  test.test_files = FileList['test/**/*_test.rb']
7
31
  test.verbose = true
8
- end
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+
48
+ task :test => :check_dependencies
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "bane #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
@@ -18,3 +18,19 @@ class String
18
18
  alias_method :lines, :to_a
19
19
  end
20
20
  end
21
+
22
+ # Copied from ActiveSupport
23
+ unless :to_proc.respond_to?(:to_proc)
24
+ class Symbol
25
+ # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
26
+ #
27
+ # # The same as people.collect { |p| p.name }
28
+ # people.collect(&:name)
29
+ #
30
+ # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
31
+ # people.select(&:manager?).collect(&:salary)
32
+ def to_proc
33
+ Proc.new { |*args| args.shift.__send__(self, *args) }
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Daniel Wellman
@@ -9,28 +15,43 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-05-16 00:00:00 -04:00
13
- default_executable:
18
+ date: 2010-05-28 00:00:00 -04:00
19
+ default_executable: bane
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: mocha
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 43
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 8
23
34
  version: 0.9.8
24
- version:
25
- description: " Bane is a test harness used to test your application's interaction with \n other servers. It is based upon the material from Michael Nygard's \"Release\n It!\" book as described in the \"Test Harness\" chapter.\n"
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: " Bane is a test harness used to test your application's interaction with\n other servers. It is based upon the material from Michael Nygard's \"Release\n It!\" book as described in the \"Test Harness\" chapter.\n"
26
38
  email: dan@danielwellman.com
27
39
  executables:
28
40
  - bane
29
41
  extensions: []
30
42
 
31
43
  extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
32
46
  - TODO
33
47
  files:
48
+ - Rakefile
49
+ - bin/bane
50
+ - examples/simple_port_and_class_as_constant.rb
51
+ - examples/simple_port_and_class_as_string.rb
52
+ - examples/specify_behavior_options.rb
53
+ - examples/specify_ports.rb
54
+ - lib/bane.rb
34
55
  - lib/bane/behaviors.rb
35
56
  - lib/bane/compatibility.rb
36
57
  - lib/bane/configuration.rb
@@ -39,8 +60,6 @@ files:
39
60
  - lib/bane/launcher.rb
40
61
  - lib/bane/naive_http_response.rb
41
62
  - lib/bane/service_registry.rb
42
- - lib/bane.rb
43
- - bin/bane
44
63
  - test/bane/behaviors_test.rb
45
64
  - test/bane/configuration_parser_test.rb
46
65
  - test/bane/configuration_test.rb
@@ -50,39 +69,54 @@ files:
50
69
  - test/bane/naive_http_response_test.rb
51
70
  - test/bane/service_registry_test.rb
52
71
  - test/test_helper.rb
53
- - examples/simple_port_and_class_as_constant.rb
54
- - examples/simple_port_and_class_as_string.rb
55
- - examples/specify_behavior_options.rb
56
- - examples/specify_ports.rb
57
- - Rakefile
72
+ - LICENSE
73
+ - README.md
58
74
  - TODO
59
75
  has_rdoc: true
60
76
  homepage: http://github.com/danielwellman/bane
61
77
  licenses: []
62
78
 
63
79
  post_install_message:
64
- rdoc_options: []
65
-
80
+ rdoc_options:
81
+ - --charset=UTF-8
66
82
  require_paths:
67
83
  - lib
68
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
69
86
  requirements:
70
87
  - - ">="
71
88
  - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
72
92
  version: "0"
73
- version:
74
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
75
95
  requirements:
76
96
  - - ">="
77
97
  - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
78
101
  version: "0"
79
- version:
80
102
  requirements: []
81
103
 
82
104
  rubyforge_project:
83
- rubygems_version: 1.3.5
105
+ rubygems_version: 1.3.7
84
106
  signing_key:
85
107
  specification_version: 3
86
108
  summary: A test harness for socket connections based upon ideas from Michael Nygard's 'Release It!'
87
- test_files: []
88
-
109
+ test_files:
110
+ - test/bane/behaviors_test.rb
111
+ - test/bane/configuration_parser_test.rb
112
+ - test/bane/configuration_test.rb
113
+ - test/bane/delegating_gserver_test.rb
114
+ - test/bane/integration_test.rb
115
+ - test/bane/launcher_test.rb
116
+ - test/bane/naive_http_response_test.rb
117
+ - test/bane/service_registry_test.rb
118
+ - test/test_helper.rb
119
+ - examples/simple_port_and_class_as_constant.rb
120
+ - examples/simple_port_and_class_as_string.rb
121
+ - examples/specify_behavior_options.rb
122
+ - examples/specify_ports.rb