dpla-analysand 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG +67 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE +22 -0
  8. data/README +48 -0
  9. data/Rakefile +22 -0
  10. data/analysand.gemspec +33 -0
  11. data/bin/analysand +27 -0
  12. data/lib/analysand.rb +3 -0
  13. data/lib/analysand/bulk_response.rb +14 -0
  14. data/lib/analysand/change_watcher.rb +280 -0
  15. data/lib/analysand/config_response.rb +25 -0
  16. data/lib/analysand/connection_testing.rb +52 -0
  17. data/lib/analysand/database.rb +322 -0
  18. data/lib/analysand/errors.rb +60 -0
  19. data/lib/analysand/http.rb +90 -0
  20. data/lib/analysand/instance.rb +255 -0
  21. data/lib/analysand/reading.rb +26 -0
  22. data/lib/analysand/response.rb +35 -0
  23. data/lib/analysand/response_headers.rb +18 -0
  24. data/lib/analysand/session_response.rb +16 -0
  25. data/lib/analysand/status_code_predicates.rb +25 -0
  26. data/lib/analysand/streaming_view_response.rb +90 -0
  27. data/lib/analysand/version.rb +3 -0
  28. data/lib/analysand/view_response.rb +24 -0
  29. data/lib/analysand/view_streaming/builder.rb +142 -0
  30. data/lib/analysand/viewing.rb +95 -0
  31. data/lib/analysand/writing.rb +71 -0
  32. data/script/setup_database.rb +45 -0
  33. data/spec/analysand/a_response.rb +70 -0
  34. data/spec/analysand/change_watcher_spec.rb +102 -0
  35. data/spec/analysand/database_spec.rb +243 -0
  36. data/spec/analysand/database_writing_spec.rb +488 -0
  37. data/spec/analysand/instance_spec.rb +205 -0
  38. data/spec/analysand/response_spec.rb +26 -0
  39. data/spec/analysand/view_response_spec.rb +44 -0
  40. data/spec/analysand/view_streaming/builder_spec.rb +73 -0
  41. data/spec/analysand/view_streaming_spec.rb +122 -0
  42. data/spec/fixtures/vcr_cassettes/get_config.yml +40 -0
  43. data/spec/fixtures/vcr_cassettes/get_many_config.yml +40 -0
  44. data/spec/fixtures/vcr_cassettes/head_request_with_etag.yml +40 -0
  45. data/spec/fixtures/vcr_cassettes/reload_config.yml +114 -0
  46. data/spec/fixtures/vcr_cassettes/unauthorized_put_config.yml +43 -0
  47. data/spec/fixtures/vcr_cassettes/view.yml +40 -0
  48. data/spec/smoke/database_thread_spec.rb +59 -0
  49. data/spec/spec_helper.rb +30 -0
  50. data/spec/support/database_access.rb +40 -0
  51. data/spec/support/example_isolation.rb +86 -0
  52. data/spec/support/test_parameters.rb +39 -0
  53. metadata +283 -0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:admin@localhost:5984/_config/stats/rate
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Connection:
15
+ - keep-alive
16
+ Keep-Alive:
17
+ - 30
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
25
+ Date:
26
+ - Tue, 13 Nov 2012 17:03:28 GMT
27
+ Content-Type:
28
+ - text/plain; charset=utf-8
29
+ Content-Length:
30
+ - '7'
31
+ Cache-Control:
32
+ - must-revalidate
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '"1000"
36
+
37
+ '
38
+ http_version:
39
+ recorded_at: Tue, 13 Nov 2012 17:03:28 GMT
40
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:admin@localhost:5984/_config/stats
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Connection:
15
+ - keep-alive
16
+ Keep-Alive:
17
+ - 30
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
25
+ Date:
26
+ - Tue, 13 Nov 2012 17:11:24 GMT
27
+ Content-Type:
28
+ - text/plain; charset=utf-8
29
+ Content-Length:
30
+ - '46'
31
+ Cache-Control:
32
+ - must-revalidate
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '{"rate":"1000","samples":"[0, 60, 300, 900]"}
36
+
37
+ '
38
+ http_version:
39
+ recorded_at: Tue, 13 Nov 2012 17:11:24 GMT
40
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://admin:admin@localhost:5984/analysand_test/abc123
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Connection:
15
+ - keep-alive
16
+ Keep-Alive:
17
+ - 30
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - CouchDB/1.3.0a-d6ab08d-git (Erlang OTP/R15B)
25
+ Etag:
26
+ - ! '"1-967a00dff5e02add41819138abb3284d"'
27
+ Date:
28
+ - Tue, 22 May 2012 14:21:26 GMT
29
+ Content-Type:
30
+ - text/plain; charset=utf-8
31
+ Content-Length:
32
+ - '61'
33
+ Cache-Control:
34
+ - must-revalidate
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ http_version:
39
+ recorded_at: Tue, 22 May 2012 14:21:26 GMT
40
+ recorded_with: VCR 2.0.1
@@ -0,0 +1,114 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:admin@localhost:5984/_config/stats/samples
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Connection:
15
+ - keep-alive
16
+ Keep-Alive:
17
+ - 30
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
25
+ Date:
26
+ - Wed, 14 Nov 2012 00:27:29 GMT
27
+ Content-Type:
28
+ - text/plain; charset=utf-8
29
+ Content-Length:
30
+ - '20'
31
+ Cache-Control:
32
+ - must-revalidate
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '"[0, 60, 300, 900]"
36
+
37
+ '
38
+ http_version:
39
+ recorded_at: Wed, 14 Nov 2012 00:27:29 GMT
40
+ - request:
41
+ method: put
42
+ uri: http://admin:admin@localhost:5984/_config/stats/samples
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ! '"[0, 60, 300, 900]"'
46
+ headers:
47
+ Accept:
48
+ - ! '*/*'
49
+ User-Agent:
50
+ - Ruby
51
+ Connection:
52
+ - keep-alive
53
+ Keep-Alive:
54
+ - 30
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Server:
61
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
62
+ Date:
63
+ - Wed, 14 Nov 2012 00:27:29 GMT
64
+ Content-Type:
65
+ - text/plain; charset=utf-8
66
+ Content-Length:
67
+ - '20'
68
+ Cache-Control:
69
+ - must-revalidate
70
+ body:
71
+ encoding: US-ASCII
72
+ string: ! '"[0, 60, 300, 900]"
73
+
74
+ '
75
+ http_version:
76
+ recorded_at: Wed, 14 Nov 2012 00:27:29 GMT
77
+ - request:
78
+ method: get
79
+ uri: http://admin:admin@localhost:5984/_config/stats/samples
80
+ body:
81
+ encoding: US-ASCII
82
+ string: ''
83
+ headers:
84
+ Accept:
85
+ - ! '*/*'
86
+ User-Agent:
87
+ - Ruby
88
+ Connection:
89
+ - keep-alive
90
+ Keep-Alive:
91
+ - 30
92
+ response:
93
+ status:
94
+ code: 200
95
+ message: OK
96
+ headers:
97
+ Server:
98
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
99
+ Date:
100
+ - Wed, 14 Nov 2012 00:27:29 GMT
101
+ Content-Type:
102
+ - text/plain; charset=utf-8
103
+ Content-Length:
104
+ - '20'
105
+ Cache-Control:
106
+ - must-revalidate
107
+ body:
108
+ encoding: US-ASCII
109
+ string: ! '"[0, 60, 300, 900]"
110
+
111
+ '
112
+ http_version:
113
+ recorded_at: Wed, 14 Nov 2012 00:27:29 GMT
114
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: !binary |-
5
+ cHV0
6
+ uri: http://localhost:5984/_config/stats/rate
7
+ body:
8
+ encoding: !binary |-
9
+ VVRGLTg=
10
+ string: ! '"1000"'
11
+ headers:
12
+ Accept:
13
+ - ! '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Connection:
17
+ - keep-alive
18
+ Keep-Alive:
19
+ - 30
20
+ response:
21
+ status:
22
+ code: 401
23
+ message: Unauthorized
24
+ headers:
25
+ Server:
26
+ - CouchDB/1.2.0 (Erlang OTP/R15B02)
27
+ Date:
28
+ - Wed, 14 Nov 2012 05:43:26 GMT
29
+ Content-Type:
30
+ - text/plain; charset=utf-8
31
+ Content-Length:
32
+ - '64'
33
+ Cache-Control:
34
+ - must-revalidate
35
+ body:
36
+ encoding: !binary |-
37
+ VVMtQVNDSUk=
38
+ string: ! '{"error":"unauthorized","reason":"You are not a server admin."}
39
+
40
+ '
41
+ http_version:
42
+ recorded_at: Wed, 14 Nov 2012 05:43:26 GMT
43
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:5984/analysand_test/_design/doc/_view/a_view
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Connection:
15
+ - keep-alive
16
+ Keep-Alive:
17
+ - 30
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Transfer-Encoding:
24
+ - chunked
25
+ Server:
26
+ - CouchDB/1.2.0 (Erlang OTP/R15B)
27
+ Etag:
28
+ - ! '"D4N5T8QITOHPR5PN1FFNNQ9JA"'
29
+ Date:
30
+ - Fri, 02 Nov 2012 14:33:24 GMT
31
+ Content-Type:
32
+ - text/plain; charset=utf-8
33
+ Cache-Control:
34
+ - must-revalidate
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! "{\"total_rows\":1,\"offset\":0,\"rows\":[\r\n{\"id\":\"abc123\",\"key\":\"abc123\",\"value\":1}\r\n]}\n"
38
+ http_version:
39
+ recorded_at: Fri, 02 Nov 2012 14:33:24 GMT
40
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,59 @@
1
+ require 'analysand'
2
+ require 'celluloid'
3
+ require 'spec_helper'
4
+
5
+ describe 'Analysand::Database from multiple threads' do
6
+ let!(:db) { Analysand::Database.new(database_uri) }
7
+ let!(:thread_count) { 32 }
8
+
9
+ before(:all) do
10
+ WebMock.disable!
11
+ end
12
+
13
+ after(:all) do
14
+ WebMock.enable!
15
+ end
16
+
17
+ before do
18
+ clean_databases!
19
+ end
20
+
21
+ it 'processes all PUTs' do
22
+ threads = (0...thread_count).map do |i|
23
+ Thread.new do
24
+ sleep 1
25
+
26
+ (0...10).each do |j|
27
+ tag = 10 * i + j
28
+ db.put(tag.to_s, { :num => tag }, member1_credentials)
29
+ end
30
+ end
31
+ end
32
+
33
+ threads.each(&:join)
34
+
35
+ db.all_docs(:stream => true).count.should == thread_count * 10
36
+ end
37
+
38
+ it 'processes all GETs' do
39
+ docs = []
40
+
41
+ (thread_count * 10).times do |i|
42
+ docs << { :_id => i.to_s, :num => i }
43
+ end
44
+
45
+ db.bulk_docs!(docs, member1_credentials)
46
+
47
+ result = (0...thread_count).map do |i|
48
+ Celluloid::Future.new do
49
+ sleep 1
50
+ (0...10).map do |j|
51
+ tag = 10 * i + j
52
+ db.get(tag.to_s, member1_credentials).body['num']
53
+ end.inject(&:+)
54
+ end
55
+ end.map(&:value).inject(&:+)
56
+
57
+ result.should == (0...thread_count * 10).inject(&:+)
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require File.expand_path('../support/database_access', __FILE__)
4
+ require File.expand_path('../support/example_isolation', __FILE__)
5
+ require File.expand_path('../support/test_parameters', __FILE__)
6
+
7
+ require 'celluloid/autostart' # for ChangeWatcher specs
8
+ require 'vcr'
9
+
10
+ RSpec.configure do |config|
11
+ config.include DatabaseAccess
12
+ config.include ExampleIsolation
13
+ config.include TestParameters
14
+
15
+ config.around do |example|
16
+ begin
17
+ Celluloid.logger = nil
18
+ Celluloid.boot
19
+ example.call
20
+ ensure
21
+ Celluloid.shutdown
22
+ end
23
+ end
24
+ end
25
+
26
+ VCR.configure do |c|
27
+ c.allow_http_connections_when_no_cassette = true
28
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
29
+ c.hook_into :webmock
30
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+
3
+ module DatabaseAccess
4
+ ##
5
+ # Sets members and admins for the database.
6
+ #
7
+ # Assumes #admin_credentials returns a Hash containing the keys :username and
8
+ # :password, where those keys' values are the username and password of a
9
+ # CouchDB admin user.
10
+ def set_security(members, admins = {})
11
+ doc = {
12
+ 'members' => members,
13
+ 'admins' => admins
14
+ }
15
+
16
+ credentials = admin_credentials
17
+ uri = instance_uri
18
+
19
+ Net::HTTP.start(uri.host, uri.port) do |h|
20
+ req = Net::HTTP::Put.new("/#{database_name}/_security")
21
+ req.basic_auth(credentials[:username], credentials[:password])
22
+ req.body = doc.to_json
23
+
24
+ resp = h.request(req)
25
+
26
+ unless Net::HTTPSuccess === resp
27
+ raise "Unable to set security parameters on #{database_name}: response code = #{resp.code}, body = #{resp.body}"
28
+ end
29
+ end
30
+ end
31
+
32
+ ##
33
+ # Resets member and admin lists for the test database to [].
34
+ def clear_security
35
+ set_security({ 'names' => [], 'roles' => [] },
36
+ { 'names' => [], 'roles' => [] })
37
+ end
38
+ end
39
+
40
+ # vim:ts=2:sw=2:et:tw=78