taps 0.2.8 → 0.2.9

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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 8
2
+ :patch: 9
3
3
  :major: 0
4
4
  :minor: 2
@@ -41,7 +41,7 @@ class ClientSession
41
41
  end
42
42
 
43
43
  def open_session
44
- uri = server['sessions'].post('', :taps_version => Taps.version)
44
+ uri = server['sessions'].post('', http_headers)
45
45
  server[uri]
46
46
  end
47
47
 
@@ -50,7 +50,7 @@ class ClientSession
50
50
  end
51
51
 
52
52
  def close_session
53
- @session_resource.delete(:taps_version => Taps.version) if @session_resource
53
+ @session_resource.delete(http_headers) if @session_resource
54
54
  end
55
55
 
56
56
  def safe_url(url)
@@ -65,6 +65,10 @@ class ClientSession
65
65
  safe_url(database_url)
66
66
  end
67
67
 
68
+ def http_headers(extra = {})
69
+ { :taps_version => Taps.compatible_version }.merge(extra)
70
+ end
71
+
68
72
  def cmd_send
69
73
  verify_server
70
74
  cmd_send_schema
@@ -77,20 +81,20 @@ class ClientSession
77
81
  puts "Sending indexes"
78
82
 
79
83
  index_data = `#{File.dirname(__FILE__)}/../../bin/schema indexes #{database_url}`
80
- session_resource['indexes'].post(index_data, :taps_version => Taps.version)
84
+ session_resource['indexes'].post(index_data, http_headers)
81
85
  end
82
86
 
83
87
  def cmd_send_schema
84
88
  puts "Sending schema"
85
89
 
86
90
  schema_data = `#{File.dirname(__FILE__)}/../../bin/schema dump #{database_url}`
87
- session_resource['schema'].post(schema_data, :taps_version => Taps.version)
91
+ session_resource['schema'].post(schema_data, http_headers)
88
92
  end
89
93
 
90
94
  def cmd_send_reset_sequences
91
95
  puts "Resetting sequences"
92
96
 
93
- session_resource["reset_sequences"].post('', :taps_version => Taps.version)
97
+ session_resource["reset_sequences"].post('', http_headers)
94
98
  end
95
99
 
96
100
  def cmd_send_data
@@ -119,10 +123,9 @@ class ClientSession
119
123
 
120
124
  chunksize = Taps::Utils.calculate_chunksize(chunksize) do
121
125
  begin
122
- session_resource["tables/#{table_name}"].post(gzip_data,
123
- :taps_version => Taps.version,
126
+ session_resource["tables/#{table_name}"].post(gzip_data, http_headers({
124
127
  :content_type => 'application/octet-stream',
125
- :taps_checksum => Taps::Utils.checksum(gzip_data).to_s)
128
+ :taps_checksum => Taps::Utils.checksum(gzip_data).to_s}))
126
129
  rescue RestClient::RequestFailed => e
127
130
  # retry the same data, it got corrupted somehow.
128
131
  if e.http_code == 412
@@ -146,6 +149,7 @@ class ClientSession
146
149
  tables_with_counts = tables.inject({}) do |accum, table|
147
150
  accum[table] = db[table].count
148
151
  record_count += accum[table]
152
+ accum
149
153
  end
150
154
 
151
155
  [ tables_with_counts, record_count ]
@@ -196,7 +200,7 @@ class ClientSession
196
200
  def fetch_table_rows(table_name, chunksize, offset)
197
201
  response = nil
198
202
  chunksize = Taps::Utils.calculate_chunksize(chunksize) do
199
- response = session_resource["tables/#{table_name}/#{chunksize}?offset=#{offset}"].get(:taps_version => Taps.version)
203
+ response = session_resource["tables/#{table_name}/#{chunksize}?offset=#{offset}"].get(http_headers)
200
204
  end
201
205
  raise CorruptedData unless Taps::Utils.valid_data?(response.to_s, response.headers[:taps_checksum])
202
206
 
@@ -214,7 +218,7 @@ class ClientSession
214
218
  retries = 0
215
219
  max_retries = 1
216
220
  begin
217
- tables_with_counts = Marshal.load(session_resource['tables'].get(:taps_version => Taps.version))
221
+ tables_with_counts = Marshal.load(session_resource['tables'].get(http_headers))
218
222
  record_count = tables_with_counts.values.inject(0) { |a,c| a += c }
219
223
  rescue RestClient::Exception
220
224
  retries += 1
@@ -229,7 +233,7 @@ class ClientSession
229
233
  def cmd_receive_schema
230
234
  puts "Receiving schema"
231
235
 
232
- schema_data = session_resource['schema'].get(:taps_version => Taps.version)
236
+ schema_data = session_resource['schema'].get(http_headers)
233
237
  output = Taps::Utils.load_schema(database_url, schema_data)
234
238
  puts output if output
235
239
  end
@@ -237,7 +241,7 @@ class ClientSession
237
241
  def cmd_receive_indexes
238
242
  puts "Receiving indexes"
239
243
 
240
- index_data = session_resource['indexes'].get(:taps_version => Taps.version)
244
+ index_data = session_resource['indexes'].get(http_headers)
241
245
 
242
246
  output = Taps::Utils.load_indexes(database_url, index_data)
243
247
  puts output if output
@@ -256,10 +260,10 @@ class ClientSession
256
260
 
257
261
  def verify_server
258
262
  begin
259
- server['/'].get(:taps_version => Taps.version)
263
+ server['/'].get(http_headers)
260
264
  rescue RestClient::RequestFailed => e
261
265
  if e.http_code == 417
262
- puts "#{remote_url} is running a different version of taps."
266
+ puts "#{safe_remote_url} is running a different minor version of taps."
263
267
  puts "#{e.response.body}"
264
268
  exit(1)
265
269
  else
data/lib/taps/config.rb CHANGED
@@ -10,6 +10,10 @@ module Taps
10
10
  "#{version_yml[:major]}.#{version_yml[:minor]}.#{version_yml[:patch]}"
11
11
  end
12
12
 
13
+ def self.compatible_version
14
+ "#{version_yml[:major]}.#{version_yml[:minor]}"
15
+ end
16
+
13
17
  class Config
14
18
  class << self
15
19
  attr_accessor :taps_database_url
data/lib/taps/server.rb CHANGED
@@ -14,8 +14,9 @@ class Server < Sinatra::Default
14
14
  end
15
15
 
16
16
  before do
17
- unless request.env['HTTP_TAPS_VERSION'] == Taps.version
18
- halt 417, "Taps version #{Taps.version} is required for this server"
17
+ major, minor, patch = request.env['HTTP_TAPS_VERSION'].split('.') rescue []
18
+ unless "#{major}.#{minor}" == Taps.compatible_version
19
+ halt 417, "Taps v#{Taps.compatible_version}.x is required for this server"
19
20
  end
20
21
  end
21
22
 
@@ -37,7 +37,7 @@ describe Taps::ClientSession do
37
37
  @client.stubs(:server).returns(mock('server'))
38
38
  @request = mock('request')
39
39
  @client.server.expects(:[]).with('/').returns(@request)
40
- @request.expects(:get).with({:taps_version => Taps.version})
40
+ @request.expects(:get).with({:taps_version => Taps.compatible_version})
41
41
 
42
42
  lambda { @client.verify_server }.should.not.raise
43
43
  end
@@ -62,7 +62,7 @@ describe Taps::ClientSession do
62
62
  it "fetches remote tables info from taps server" do
63
63
  @marshal_data = Marshal.dump({ :mytable => 2 })
64
64
  @client.session_resource.stubs(:[]).with('tables').returns(mock('tables'))
65
- @client.session_resource['tables'].stubs(:get).with(:taps_version => Taps.version).returns(@marshal_data)
65
+ @client.session_resource['tables'].stubs(:get).with(:taps_version => Taps.compatible_version).returns(@marshal_data)
66
66
  @client.fetch_remote_tables_info.should == [ { :mytable => 2 }, 2 ]
67
67
  end
68
68
 
@@ -73,7 +73,7 @@ describe Taps::ClientSession do
73
73
 
74
74
  @response = mock('response')
75
75
  @client.session_resource.stubs(:[]).with('tables/mytable/1000?offset=0').returns(mock('table resource'))
76
- @client.session_resource['tables/mytable/1000?offset=0'].expects(:get).with(:taps_version => Taps.version).returns(@response)
76
+ @client.session_resource['tables/mytable/1000?offset=0'].expects(:get).with(:taps_version => Taps.compatible_version).returns(@response)
77
77
  @response.stubs(:to_s).returns(@gzip_data)
78
78
  @response.stubs(:headers).returns({ :taps_checksum => Taps::Utils.checksum(@gzip_data) })
79
79
  @client.fetch_table_rows('mytable', 1000, 0).should == [ 1000, { :header => [:x, :y], :data => [[1, 2], [3, 4]] } ]
data/spec/server_spec.rb CHANGED
@@ -21,7 +21,7 @@ describe Taps::Server do
21
21
  end
22
22
 
23
23
  it "verifies the client taps version" do
24
- get('/', { }, { 'HTTP_AUTHORIZATION' => @auth_header, 'HTTP_TAPS_VERSION' => Taps.version })
24
+ get('/', { }, { 'HTTP_AUTHORIZATION' => @auth_header, 'HTTP_TAPS_VERSION' => Taps.compatible_version })
25
25
  status.should == 200
26
26
  end
27
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Chimal, Jr.
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-03-16 00:00:00 -07:00
13
+ date: 2009-03-18 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -84,21 +84,21 @@ extra_rdoc_files: []
84
84
 
85
85
  files:
86
86
  - spec/base.rb
87
+ - spec/schema_spec.rb
87
88
  - spec/utils_spec.rb
88
- - spec/server_spec.rb
89
89
  - spec/client_session_spec.rb
90
- - spec/schema_spec.rb
90
+ - spec/server_spec.rb
91
91
  - lib/taps/db_session.rb
92
92
  - lib/taps/progress_bar.rb
93
- - lib/taps/server.rb
94
93
  - lib/taps/cli.rb
95
94
  - lib/taps/adapter_hacks.rb
96
95
  - lib/taps/adapter_hacks/invalid_text_limit.rb
97
96
  - lib/taps/adapter_hacks/non_rails_schema_dump.rb
98
97
  - lib/taps/schema.rb
98
+ - lib/taps/config.rb
99
99
  - lib/taps/client_session.rb
100
+ - lib/taps/server.rb
100
101
  - lib/taps/utils.rb
101
- - lib/taps/config.rb
102
102
  - README.rdoc
103
103
  - LICENSE
104
104
  - VERSION.yml