turnout_proxy 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -7,3 +7,5 @@ rvm:
7
7
  branches:
8
8
  only:
9
9
  - master
10
+ env:
11
+ - rvmsudo_secure_path=1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
data/lib/turnout_proxy.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  require 'em-proxy'
2
2
  require 'turnout_proxy/host_chooser'
3
+ require 'turnout_proxy/version'
3
4
 
4
5
  module TurnoutProxy
5
- version_file = File.expand_path('../VERSION', File.dirname(__FILE__))
6
- VERSION = File.read(version_file).freeze
7
-
8
6
  def self.run(options = {})
9
7
  Proxy.start(options) do |conn|
10
8
  callbacks = HostChooser.new(conn, options)
@@ -1,31 +1,37 @@
1
1
  module TurnoutProxy
2
2
 
3
3
  class HostChooser
4
- attr_accessor :file_checker
5
-
6
4
  def initialize(connection, options = {})
7
5
  @connection = connection
8
- @file_checker = File
6
+ @file_checker = options.fetch(:file_checker) { File }
9
7
 
10
8
  @default = validate_host(options[:default])
11
9
  @alternate = validate_host(options[:alternate])
12
10
 
13
11
  @lock_file = options[:lock_file]
12
+
13
+ choose_destination_server!
14
14
  end
15
15
 
16
16
  def on_data(data)
17
- use_alternate? ? @connection.server(:alternate, @alternate) : @connection.server(:default, @default)
18
17
  data
19
18
  end
20
19
 
21
20
  private
22
21
 
22
+ def choose_destination_server!
23
+ name, proxy_options = if use_alternate?
24
+ [:alternate, @alternate]
25
+ else
26
+ [:default, @default]
27
+ end
28
+ @connection.server(name, proxy_options.merge(:relay_client => true, :relay_server => true))
29
+ end
30
+
23
31
  def use_alternate?
24
32
  @file_checker.exists?(@lock_file)
25
33
  end
26
34
 
27
- private
28
-
29
35
  def validate_host(host_config)
30
36
  if host_config.nil? || String(host_config[:host]).empty? || host_config[:port].nil?
31
37
  raise ArgumentError, "Bad host config, both host and port must be present."
@@ -0,0 +1,4 @@
1
+ module TurnoutProxy
2
+ version_file = File.expand_path('../../../VERSION', __FILE__)
3
+ VERSION = File.read(version_file).freeze
4
+ end
@@ -1,12 +1,12 @@
1
1
  require 'test_helper'
2
2
  require 'fileutils'
3
3
  require 'net/http'
4
- require 'posix/spawn'
4
+ require 'support/travis_spawn'
5
5
  require 'support/hello_server'
6
6
  require 'turnout_proxy'
7
7
 
8
8
  class TestTurnoutProxy < TurnoutProxyTestCase
9
- include POSIX::Spawn
9
+ include TravisSpawn
10
10
  include TurnoutProxy
11
11
 
12
12
  TEST_LOCK_FILE = PROJECT_ROOT.join("lock")
@@ -51,12 +51,10 @@ class TestTurnoutProxy < TurnoutProxyTestCase
51
51
  end
52
52
 
53
53
  test "doesn't fail if destination server isn't responding" do
54
- @pid = nil
55
54
  with_running_proxy(8085) do |pid|
56
- @pid = pid
57
55
  Net::HTTP.get(URI("http://127.0.0.1:5678")) rescue nil
56
+ assert_equal 0, `kill -0 #{pid}`.chomp.to_i
58
57
  end
59
- Process.kill 0, @pid
60
58
  end
61
59
 
62
60
  end
@@ -31,14 +31,14 @@ class TestHostChooser < TurnoutProxyTestCase
31
31
  @file_checker = FakeFile.new
32
32
  end
33
33
 
34
- ALTERNATE_CONFIG = { :host => "127.0.0.1", :port => 19999 }
35
- DEFAULT_CONFIG = { :host => "127.0.0.1", :port => 9012 }
34
+ ALTERNATE_CONFIG = { :host => "127.0.0.1", :port => 19999, :relay_client => true, :relay_server => true }
35
+ DEFAULT_CONFIG = { :host => "127.0.0.1", :port => 9012, :relay_client => true, :relay_server => true }
36
36
 
37
37
  def host_chooser
38
38
  host_chooser = HostChooser.new(@connection,
39
39
  :default => DEFAULT_CONFIG,
40
- :alternate => ALTERNATE_CONFIG)
41
- host_chooser.file_checker = @file_checker
40
+ :alternate => ALTERNATE_CONFIG,
41
+ :file_checker => @file_checker)
42
42
  host_chooser
43
43
  end
44
44
 
@@ -1,13 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'posix/spawn'
3
+ require 'support/travis_spawn'
4
4
  require 'eventmachine'
5
5
 
6
6
  class HelloServer
7
- include POSIX::Spawn
7
+ include TravisSpawn
8
8
 
9
9
  def initialize(port, message)
10
- @pid = spawn("ruby #{__FILE__} #{port} #{message}")
10
+ @pid = spawn("ruby -Itest #{__FILE__} #{port} #{message}")
11
11
  at_exit { die }
12
12
  end
13
13
 
@@ -0,0 +1,12 @@
1
+ require 'posix/spawn'
2
+
3
+ module TravisSpawn
4
+ include POSIX::Spawn
5
+
6
+ def spawn(command, *args)
7
+ if ENV["TRAVIS"]
8
+ command = "rvmsudo " + command
9
+ end
10
+ super(command, *args)
11
+ end
12
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  $:.unshift File.expand_path('../lib/', __FILE__)
4
4
 
5
- require 'turnout_proxy'
5
+ require 'turnout_proxy/version'
6
6
  require 'date'
7
7
 
8
8
  Gem::Specification.new do |s|
metadata CHANGED
@@ -1,75 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: turnout_proxy
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
5
+ version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Vladimir Yarotsky
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-04-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: em-proxy
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 9
28
- segments:
29
- - 0
30
- - 1
31
- version: "0.1"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.1'
32
22
  type: :runtime
33
- requirement: *id001
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '0.1'
34
29
  prerelease: false
35
- - !ruby/object:Gem::Dependency
30
+ - !ruby/object:Gem::Dependency
36
31
  name: rake
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :development
47
- requirement: *id002
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
48
45
  prerelease: false
49
- - !ruby/object:Gem::Dependency
46
+ - !ruby/object:Gem::Dependency
50
47
  name: posix-spawn
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
52
49
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :development
61
- requirement: *id003
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
62
61
  prerelease: false
63
62
  description:
64
63
  email: vladimir.yarotksy@gmail.com
65
- executables:
64
+ executables:
66
65
  - turnout_proxy
67
66
  extensions: []
68
-
69
- extra_rdoc_files:
67
+ extra_rdoc_files:
70
68
  - LICENSE.txt
71
69
  - README.md
72
- files:
70
+ files:
73
71
  - .gitignore
74
72
  - .travis.yml
75
73
  - Gemfile
@@ -80,48 +78,44 @@ files:
80
78
  - bin/turnout_proxy
81
79
  - lib/turnout_proxy.rb
82
80
  - lib/turnout_proxy/host_chooser.rb
81
+ - lib/turnout_proxy/version.rb
83
82
  - test/acceptance/test_turnout_proxy.rb
84
83
  - test/lib/turnout_proxy/test_host_chooser.rb
85
84
  - test/support/hello_server.rb
85
+ - test/support/travis_spawn.rb
86
86
  - test/test_helper.rb
87
87
  - turnout_proxy.gemspec
88
88
  homepage: http://github.com/v-yarotsky/turnout_proxy
89
- licenses:
89
+ licenses:
90
90
  - MIT
91
91
  post_install_message:
92
92
  rdoc_options: []
93
-
94
- require_paths:
93
+ require_paths:
95
94
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
95
+ required_ruby_version: !ruby/object:Gem::Requirement
97
96
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ segments:
103
101
  - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ hash: 241058783050928805
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
105
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 23
111
- segments:
112
- - 1
113
- - 3
114
- - 6
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
115
109
  version: 1.3.6
116
110
  requirements: []
117
-
118
111
  rubyforge_project:
119
- rubygems_version: 1.8.24
112
+ rubygems_version: 1.8.25
120
113
  signing_key:
121
114
  specification_version: 3
122
115
  summary: Proxy server which allows to switch between two destinations using lock file
123
- test_files:
116
+ test_files:
124
117
  - test/acceptance/test_turnout_proxy.rb
125
118
  - test/lib/turnout_proxy/test_host_chooser.rb
126
119
  - test/support/hello_server.rb
120
+ - test/support/travis_spawn.rb
127
121
  - test/test_helper.rb