riak-client 1.4.5 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.markdown +211 -66
  6. data/RELEASE_NOTES.md +22 -47
  7. data/Rakefile +45 -0
  8. data/lib/riak.rb +1 -1
  9. data/lib/riak/bucket.rb +2 -2
  10. data/lib/riak/client.rb +22 -195
  11. data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
  12. data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
  13. data/lib/riak/client/beefcake/footer +4 -0
  14. data/lib/riak/client/beefcake/header +6 -0
  15. data/lib/riak/client/beefcake/message_codes.rb +29 -0
  16. data/lib/riak/client/beefcake/message_overlay.rb +61 -0
  17. data/lib/riak/client/beefcake/messages.rb +733 -371
  18. data/lib/riak/client/beefcake/object_methods.rb +1 -1
  19. data/lib/riak/client/beefcake/protocol.rb +105 -0
  20. data/lib/riak/client/beefcake/socket.rb +243 -0
  21. data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
  22. data/lib/riak/client/node.rb +4 -75
  23. data/lib/riak/client/protobuffs_backend.rb +6 -14
  24. data/lib/riak/client/search.rb +0 -64
  25. data/lib/riak/client/yokozuna.rb +52 -0
  26. data/lib/riak/counter.rb +1 -1
  27. data/lib/riak/crdt.rb +21 -0
  28. data/lib/riak/crdt/base.rb +97 -0
  29. data/lib/riak/crdt/batch_counter.rb +19 -0
  30. data/lib/riak/crdt/batch_map.rb +41 -0
  31. data/lib/riak/crdt/counter.rb +71 -0
  32. data/lib/riak/crdt/inner_counter.rb +74 -0
  33. data/lib/riak/crdt/inner_flag.rb +42 -0
  34. data/lib/riak/crdt/inner_map.rb +53 -0
  35. data/lib/riak/crdt/inner_register.rb +26 -0
  36. data/lib/riak/crdt/inner_set.rb +95 -0
  37. data/lib/riak/crdt/map.rb +88 -0
  38. data/lib/riak/crdt/operation.rb +19 -0
  39. data/lib/riak/crdt/set.rb +156 -0
  40. data/lib/riak/crdt/typed_collection.rb +131 -0
  41. data/lib/riak/errors/base.rb +9 -0
  42. data/lib/riak/errors/connection_error.rb +44 -0
  43. data/lib/riak/errors/crdt_error.rb +18 -0
  44. data/lib/riak/errors/failed_request.rb +56 -0
  45. data/lib/riak/errors/protobuffs_error.rb +11 -0
  46. data/lib/riak/i18n.rb +2 -0
  47. data/lib/riak/json.rb +1 -1
  48. data/lib/riak/locale/en.yml +26 -1
  49. data/lib/riak/locale/fr.yml +0 -1
  50. data/lib/riak/map_reduce.rb +1 -1
  51. data/lib/riak/map_reduce/results.rb +1 -1
  52. data/lib/riak/multiget.rb +1 -2
  53. data/lib/riak/rcontent.rb +8 -3
  54. data/lib/riak/robject.rb +2 -8
  55. data/lib/riak/secondary_index.rb +4 -4
  56. data/lib/riak/serializers.rb +1 -1
  57. data/lib/riak/util/escape.rb +3 -5
  58. data/lib/riak/version.rb +1 -1
  59. data/lib/riak/walk_spec.rb +7 -3
  60. data/riak-client.gemspec +10 -8
  61. data/spec/fixtures/bitcask.txt +25 -0
  62. data/spec/integration/riak/bucket_types_spec.rb +61 -0
  63. data/spec/integration/riak/counters_spec.rb +17 -32
  64. data/spec/integration/riak/crdt_spec.rb +181 -0
  65. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  66. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  67. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
  68. data/spec/integration/riak/security_spec.rb +94 -0
  69. data/spec/integration/riak/threading_spec.rb +24 -67
  70. data/spec/integration/yokozuna/index_spec.rb +61 -0
  71. data/spec/integration/yokozuna/queries_spec.rb +116 -0
  72. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  73. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  74. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
  75. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  76. data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
  77. data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
  78. data/spec/riak/bucket_spec.rb +81 -77
  79. data/spec/riak/client_spec.rb +43 -340
  80. data/spec/riak/core_ext/to_param_spec.rb +2 -2
  81. data/spec/riak/counter_spec.rb +20 -20
  82. data/spec/riak/crdt/counter_spec.rb +52 -0
  83. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  84. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  85. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  86. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  87. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  88. data/spec/riak/crdt/map_spec.rb +77 -0
  89. data/spec/riak/crdt/set_spec.rb +58 -0
  90. data/spec/riak/crdt/shared_examples.rb +74 -0
  91. data/spec/riak/crdt/typed_collection_spec.rb +231 -0
  92. data/spec/riak/escape_spec.rb +33 -37
  93. data/spec/riak/feature_detection_spec.rb +45 -45
  94. data/spec/riak/index_collection_spec.rb +12 -12
  95. data/spec/riak/link_spec.rb +34 -34
  96. data/spec/riak/list_buckets_spec.rb +7 -7
  97. data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
  98. data/spec/riak/map_reduce/phase_spec.rb +35 -35
  99. data/spec/riak/map_reduce_spec.rb +89 -87
  100. data/spec/riak/multiget_spec.rb +20 -15
  101. data/spec/riak/node_spec.rb +5 -152
  102. data/spec/riak/robject_spec.rb +95 -108
  103. data/spec/riak/search_spec.rb +17 -139
  104. data/spec/riak/secondary_index_spec.rb +49 -49
  105. data/spec/riak/serializers_spec.rb +9 -9
  106. data/spec/riak/stamp_spec.rb +9 -9
  107. data/spec/riak/walk_spec_spec.rb +46 -46
  108. data/spec/spec_helper.rb +14 -22
  109. data/spec/support/certs/README.md +13 -0
  110. data/spec/support/certs/ca.crt +22 -0
  111. data/spec/support/certs/client.crt +95 -0
  112. data/spec/support/certs/client.key +27 -0
  113. data/spec/support/certs/empty_ca.crt +21 -0
  114. data/spec/support/certs/server.crl +13 -0
  115. data/spec/support/certs/server.crt +95 -0
  116. data/spec/support/certs/server.key +27 -0
  117. data/spec/support/integration_setup.rb +1 -1
  118. data/spec/support/search_corpus_setup.rb +29 -8
  119. data/spec/support/test_client.rb +46 -0
  120. data/spec/support/test_client.yml.example +10 -0
  121. data/spec/support/unified_backend_examples.rb +104 -83
  122. data/spec/support/version_filter.rb +2 -2
  123. data/spec/support/wait_until.rb +14 -0
  124. metadata +134 -132
  125. data/erl_src/riak_kv_test014_backend.beam +0 -0
  126. data/erl_src/riak_kv_test014_backend.erl +0 -189
  127. data/erl_src/riak_kv_test_backend.beam +0 -0
  128. data/erl_src/riak_kv_test_backend.erl +0 -731
  129. data/erl_src/riak_search_test_backend.beam +0 -0
  130. data/erl_src/riak_search_test_backend.erl +0 -175
  131. data/lib/riak/client/excon_backend.rb +0 -172
  132. data/lib/riak/client/http_backend.rb +0 -413
  133. data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
  134. data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
  135. data/lib/riak/client/http_backend/configuration.rb +0 -227
  136. data/lib/riak/client/http_backend/key_streamer.rb +0 -15
  137. data/lib/riak/client/http_backend/object_methods.rb +0 -114
  138. data/lib/riak/client/http_backend/request_headers.rb +0 -34
  139. data/lib/riak/client/http_backend/transport_methods.rb +0 -201
  140. data/lib/riak/client/instrumentation.rb +0 -25
  141. data/lib/riak/client/net_http_backend.rb +0 -82
  142. data/lib/riak/cluster.rb +0 -151
  143. data/lib/riak/failed_request.rb +0 -81
  144. data/lib/riak/instrumentation.rb +0 -6
  145. data/lib/riak/node.rb +0 -40
  146. data/lib/riak/node/configuration.rb +0 -304
  147. data/lib/riak/node/console.rb +0 -133
  148. data/lib/riak/node/control.rb +0 -207
  149. data/lib/riak/node/defaults.rb +0 -85
  150. data/lib/riak/node/generation.rb +0 -127
  151. data/lib/riak/node/log.rb +0 -34
  152. data/lib/riak/node/version.rb +0 -29
  153. data/lib/riak/search.rb +0 -3
  154. data/lib/riak/test_server.rb +0 -89
  155. data/lib/riak/util/headers.rb +0 -32
  156. data/lib/riak/util/multipart.rb +0 -52
  157. data/lib/riak/util/multipart/stream_parser.rb +0 -62
  158. data/spec/fixtures/munchausen.txt +0 -1033
  159. data/spec/integration/riak/cluster_spec.rb +0 -88
  160. data/spec/integration/riak/http_backends_spec.rb +0 -180
  161. data/spec/integration/riak/node_spec.rb +0 -170
  162. data/spec/integration/riak/test_server_spec.rb +0 -57
  163. data/spec/riak/excon_backend_spec.rb +0 -102
  164. data/spec/riak/headers_spec.rb +0 -21
  165. data/spec/riak/http_backend/configuration_spec.rb +0 -273
  166. data/spec/riak/http_backend/object_methods_spec.rb +0 -243
  167. data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
  168. data/spec/riak/http_backend_spec.rb +0 -367
  169. data/spec/riak/instrumentation_spec.rb +0 -167
  170. data/spec/riak/multipart_spec.rb +0 -23
  171. data/spec/riak/net_http_backend_spec.rb +0 -15
  172. data/spec/riak/stream_parser_spec.rb +0 -53
  173. data/spec/support/drb_mock_server.rb +0 -39
  174. data/spec/support/http_backend_implementation_examples.rb +0 -253
  175. data/spec/support/mock_server.rb +0 -81
  176. data/spec/support/mocks.rb +0 -4
  177. data/spec/support/riak_test.rb +0 -77
  178. data/spec/support/sometimes.rb +0 -46
  179. data/spec/support/test_server.rb +0 -61
  180. data/spec/support/test_server.yml.example +0 -14
@@ -1,167 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client do
4
-
5
- before do
6
- @client = Riak::Client.new
7
- @backend = mock("Backend")
8
- @client.stub!(:backend).and_yield(@backend)
9
- @client.stub!(:http).and_yield(@backend)
10
- @bucket = Riak::Bucket.new(@client, "foo")
11
-
12
- @events = []
13
- @notifier = ActiveSupport::Notifications.notifier
14
- @notifier.subscribe { |*args| (@events ||= []) << event(*args) }
15
- end
16
-
17
- describe "instrumentation", instrumentation: true do
18
-
19
- it "should notify on the 'buckets' operation" do
20
- @backend.should_receive(:list_buckets).and_return(%w{test test2})
21
- test_client_event(@client, 'riak.list_buckets') do
22
- @client.buckets
23
- end
24
- end
25
-
26
- it "should notify on the 'list_buckets' operation" do
27
- @backend.should_receive(:list_buckets).and_return(%w{test test2})
28
- test_client_event(@client, 'riak.list_buckets') do
29
- @client.list_buckets
30
- end
31
- end
32
-
33
- it "should notify on the 'list_keys' operation" do
34
- @backend.should_receive(:list_keys).and_return(%w{test test2})
35
- test_client_event(@client, 'riak.list_keys') do
36
- @client.list_keys(@bucket)
37
- end
38
- end
39
-
40
- it "should notify on the 'get_bucket_props' operation" do
41
- @backend.should_receive(:get_bucket_props).and_return({})
42
- test_client_event(@client, 'riak.get_bucket_props') do
43
- @client.get_bucket_props(@bucket)
44
- end
45
- end
46
-
47
- it "should notify on the 'set_bucket_props' operation" do
48
- @backend.should_receive(:set_bucket_props).and_return({})
49
- test_client_event(@client, 'riak.set_bucket_props') do
50
- @client.set_bucket_props(@bucket, {})
51
- end
52
- end
53
-
54
- it "should notify on the 'clear_bucket_props' operation" do
55
- @backend.should_receive(:clear_bucket_props).and_return({})
56
- test_client_event(@client, 'riak.clear_bucket_props') do
57
- @client.clear_bucket_props(@bucket)
58
- end
59
- end
60
-
61
- it "should notify on the 'get_index' operation" do
62
- @backend.should_receive(:get_index).and_return({})
63
- test_client_event(@client, 'riak.get_index') do
64
- @client.get_index(@bucket, 'index', 'query', {})
65
- end
66
- end
67
-
68
- it "should notify on the 'get_object' operation" do
69
- @backend.should_receive(:fetch_object).and_return(nil)
70
- test_client_event(@client, 'riak.get_object') do
71
- @client.get_object(@bucket, 'bar')
72
- end
73
- end
74
-
75
- it "should notify on the 'store_object' operation" do
76
- @backend.should_receive(:store_object).and_return(nil)
77
- test_client_event(@client, 'riak.store_object') do
78
- @client.store_object(Object.new)
79
- end
80
- end
81
-
82
- it "should notify on the 'reload_object' operation" do
83
- @backend.should_receive(:reload_object).and_return(nil)
84
- test_client_event(@client, 'riak.reload_object') do
85
- @client.reload_object(Object.new)
86
- end
87
- end
88
-
89
- it "should notify on the 'delete_object' operation" do
90
- @backend.should_receive(:delete_object).and_return(nil)
91
- test_client_event(@client, 'riak.delete_object') do
92
- @client.delete_object(@bucket, 'bar')
93
- end
94
- end
95
-
96
- it "should notify on the 'store_file' operation" do
97
- @backend.should_receive(:store_file).and_return(nil)
98
- test_client_event(@client, 'riak.store_file') do
99
- @client.store_file('filename')
100
- end
101
- end
102
-
103
- it "should notify on the 'get_file' operation" do
104
- @backend.should_receive(:get_file).and_return(nil)
105
- test_client_event(@client, 'riak.get_file') do
106
- @client.get_file('filename')
107
- end
108
- end
109
-
110
- it "should notify on the 'delete_file' operation" do
111
- @backend.should_receive(:delete_file).and_return(nil)
112
- test_client_event(@client, 'riak.delete_file') do
113
- @client.delete_file('filename')
114
- end
115
- end
116
-
117
- it "should notify on the 'file_exists' operation" do
118
- @backend.should_receive(:file_exists?).and_return(nil)
119
- test_client_event(@client, 'riak.file_exists') do
120
- @client.file_exists?('filename')
121
- end
122
- end
123
-
124
- it "should notify on the 'file_exist' operation" do
125
- @backend.should_receive(:file_exists?).and_return(nil)
126
- test_client_event(@client, 'riak.file_exists') do
127
- @client.file_exist?('filename')
128
- end
129
- end
130
-
131
- it "should notify on the 'link_walk' operation" do
132
- @backend.should_receive(:link_walk).and_return(nil)
133
- test_client_event(@client, 'riak.link_walk') do
134
- @client.link_walk(Object.new, [Riak::WalkSpec.new(:bucket => 'foo')])
135
- end
136
- end
137
-
138
- it "should notify on the 'mapred' operation" do
139
- @mapred = Riak::MapReduce.new(@client).add('test').map("function(){}").map("function(){}")
140
- @backend.should_receive(:mapred).and_return(nil)
141
- test_client_event(@client, 'riak.map_reduce') do
142
- @client.mapred(@mapred)
143
- end
144
- end
145
-
146
- it "should notify on the 'ping' operation" do
147
- @backend.should_receive(:ping).and_return(nil)
148
- test_client_event(@client, 'riak.ping') do
149
- @client.ping
150
- end
151
- end
152
- end
153
- end
154
-
155
- def test_client_event(client, event_name, &block)
156
- block.call
157
- @events.size.should == 1
158
- event = @events.first
159
- event.name.should == event_name
160
- event.payload[:protocol].should == client.protocol
161
- event.payload[:client_id].should == client.client_id
162
- end
163
-
164
- # name, start, finish, id, payload
165
- def event(*args)
166
- ActiveSupport::Notifications::Event.new(*args)
167
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Util::Multipart do
4
- it "should extract the boundary string from a header value" do
5
- Riak::Util::Multipart.extract_boundary("multipart/mixed; boundary=123446677890").should == "123446677890"
6
- end
7
-
8
- it "should parse an empty multipart body into empty arrays" do
9
- data = File.read(File.expand_path("#{File.dirname(__FILE__)}/../fixtures/multipart-blank.txt"))
10
- Riak::Util::Multipart.parse(data, "73NmmA8dJxSB5nL2dVerpFIi8ze").should == [[]]
11
- end
12
-
13
- it "should parse multipart body into nested arrays with response-like results" do
14
- data = File.read(File.expand_path("#{File.dirname(__FILE__)}/../fixtures/multipart-with-body.txt"))
15
- results = Riak::Util::Multipart.parse(data, "5EiMOjuGavQ2IbXAqsJPLLfJNlA")
16
- results.should be_kind_of(Array)
17
- results.first.should be_kind_of(Array)
18
- obj = results.first.first
19
- obj.should be_kind_of(Hash)
20
- obj.should have_key(:headers)
21
- obj.should have_key(:body)
22
- end
23
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client::NetHTTPBackend do
4
- before :each do
5
- @client = Riak::Client.new(:http_backend => :NetHTTP)
6
- @backend = @client.new_http_backend
7
- FakeWeb.allow_net_connect = false
8
- end
9
-
10
- def setup_http_mock(method, uri, options={})
11
- FakeWeb.register_uri(method, uri, options)
12
- end
13
-
14
- it_should_behave_like "HTTP backend"
15
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Util::Multipart::StreamParser do
4
- let(:klass) { Riak::Util::Multipart::StreamParser }
5
- let(:block) { mock }
6
- it "should detect the initial boundary" do
7
- text = "--boundary1\r\nContent-Type: text/plain\r\n\r\nfoo\r\n--boundary1--\r\n"
8
- parser = klass.new do |result|
9
- result[:headers]['content-type'].should include("text/plain")
10
- result[:body].should == "foo"
11
- end
12
- parser.accept text
13
- end
14
-
15
- it "should detect inner multipart bodies" do
16
- block.should_receive(:ping).once.and_return(true)
17
- parser = klass.new do |result|
18
- block.ping
19
- result.should have(1).item
20
- result.first[:headers]['content-type'].should include("text/plain")
21
- result.first[:body].should == "SCP sloooow...."
22
- end
23
- File.open("spec/fixtures/multipart-with-body.txt", "r") do |f|
24
- while chunk = f.read(16)
25
- parser.accept chunk
26
- end
27
- end
28
- end
29
-
30
- it "should yield successive complete chunks to the block" do
31
- block.should_receive(:ping).twice.and_return(true)
32
- parser = klass.new do |result|
33
- block.ping
34
- result[:headers]['content-type'].should include("application/json")
35
- lambda { Riak::JSON.parse(result[:body]) }.should_not raise_error
36
- end
37
- File.open("spec/fixtures/multipart-mapreduce.txt", "r") do |f|
38
- while chunk = f.read(16)
39
- parser.accept chunk
40
- end
41
- end
42
- end
43
-
44
- it "should yield successive complete bodies to the block, even when multiple bodies are accepted in a single chunk" do
45
- block.should_receive(:ping).twice.and_return(true)
46
- parser = klass.new do |result|
47
- block.ping
48
- result[:headers]['content-type'].should include("application/json")
49
- lambda { Riak::JSON.parse(result[:body]) }.should_not raise_error
50
- end
51
- parser.accept File.read("spec/fixtures/multipart-mapreduce.txt")
52
- end
53
- end
@@ -1,39 +0,0 @@
1
- require 'drb/drb'
2
- DRBURI="druby://localhost:8787"
3
-
4
- module DrbMockServer
5
- extend self
6
-
7
- def start_client
8
- # JRuby doesn't support fork
9
- if defined? JRUBY_VERSION
10
- @server = MockServer.new(2)
11
- at_exit { @server.stop }
12
- else
13
- child_pid = Process.fork do
14
- start_server
15
- end
16
- sleep 1
17
- at_exit { Process.kill("HUP", child_pid); Process.wait2 }
18
- DRb.start_service
19
- @server = DRbObject.new_with_uri(DRBURI)
20
- sleep 1
21
- end
22
- true
23
- end
24
-
25
- def maybe_start
26
- start_client unless @server
27
- end
28
-
29
- def method_missing(meth, *args, &block)
30
- @server.send(meth, *args, &block)
31
- end
32
-
33
- def start_server
34
- server = MockServer.new
35
- DRb.start_service(DRBURI, server)
36
- Signal.trap("HUP") { server.stop; exit }
37
- DRb.thread.join
38
- end
39
- end
@@ -1,253 +0,0 @@
1
- shared_examples_for "HTTP backend" do
2
- let(:resource){ @backend.path("/riak/","foo") }
3
-
4
- describe "HEAD requests" do
5
- before :each do
6
- setup_http_mock(:head, resource.to_s, :body => "")
7
- end
8
-
9
- it "should return only the headers when the request succeeds" do
10
- response = @backend.head(200, resource)
11
- response.should_not have_key(:body)
12
- response[:headers].should be_kind_of(Hash)
13
- response[:code].should == 200
14
- end
15
-
16
- it "should raise a FailedRequest exception when the request fails" do
17
- lambda { @backend.head(301, resource) }.should raise_error(Riak::FailedRequest)
18
- end
19
-
20
- it "should not raise a FailedRequest if one of the expected response codes matches" do
21
- lambda { @backend.head([200, 301], resource) }.should_not raise_error(Riak::FailedRequest)
22
- end
23
- end
24
-
25
- describe "GET requests" do
26
- before :each do
27
- setup_http_mock(:get, resource.to_s, :body => "Success!")
28
- end
29
-
30
- it "should return the response body and headers when the request succeeds" do
31
- response = @backend.get(200, resource)
32
- response[:body].should == "Success!"
33
- response[:headers].should be_kind_of(Hash)
34
- response[:code].should == 200
35
- end
36
-
37
- it "should raise a FailedRequest exception when the request fails" do
38
- lambda { @backend.get(304, resource) }.should raise_error(Riak::FailedRequest)
39
- end
40
-
41
- it "should not raise a FailedRequest if one of the expected response codes matches" do
42
- lambda { @backend.get([200, 301], resource) }.should_not raise_error(Riak::FailedRequest)
43
- end
44
-
45
- it "should yield successive chunks of the response to the given block but not return the entire body" do
46
- chunks = ""
47
- response = @backend.get(200, resource) do |chunk|
48
- chunks << chunk
49
- end
50
- chunks.should == "Success!"
51
- response.should_not have_key(:body)
52
- response[:headers].should be_kind_of(Hash)
53
- response[:code].should == 200
54
- end
55
- end
56
-
57
- describe "DELETE requests" do
58
- before :each do
59
- setup_http_mock(:delete, resource.to_s, :body => "Success!")
60
- end
61
-
62
- it "should return the response body and headers when the request succeeds" do
63
- response = @backend.delete(200, resource)
64
- response[:body].should == "Success!"
65
- response[:headers].should be_kind_of(Hash)
66
- end
67
-
68
- it "should raise a FailedRequest exception when the request fails" do
69
- lambda { @backend.delete(304, resource) }.should raise_error(Riak::FailedRequest)
70
- end
71
-
72
- it "should not raise a FailedRequest if one of the expected response codes matches" do
73
- lambda { @backend.delete([200, 301], resource) }.should_not raise_error(Riak::FailedRequest)
74
- end
75
-
76
- it "should yield successive chunks of the response to the given block but not return the entire body" do
77
- chunks = ""
78
- response = @backend.delete(200, resource) do |chunk|
79
- chunks << chunk
80
- end
81
- chunks.should == "Success!"
82
- response.should_not have_key(:body)
83
- response[:headers].should be_kind_of(Hash)
84
- response[:code].should == 200
85
- end
86
- end
87
-
88
- describe "PUT requests" do
89
- before :each do
90
- setup_http_mock(:put, resource.to_s, :body => "Success!")
91
- end
92
-
93
- it "should return the response body, headers, and code when the request succeeds" do
94
- response = @backend.put(200, resource, "This is the body.")
95
- response[:body].should == "Success!"
96
- response[:headers].should be_kind_of(Hash)
97
- response[:code].should == 200
98
- end
99
-
100
- it "should raise a FailedRequest exception when the request fails" do
101
- lambda { @backend.put(204, resource, "This is the body.") }.should raise_error(Riak::FailedRequest)
102
- end
103
-
104
- it "should not raise a FailedRequest if one of the expected response codes matches" do
105
- lambda { @backend.put([200, 204], resource, "This is the body.") }.should_not raise_error(Riak::FailedRequest)
106
- end
107
-
108
-
109
- it "should yield successive chunks of the response to the given block but not return the entire body" do
110
- chunks = ""
111
- response = @backend.put(200, resource, "This is the body.") do |chunk|
112
- chunks << chunk
113
- end
114
- chunks.should == "Success!"
115
- response.should_not have_key(:body)
116
- response[:headers].should be_kind_of(Hash)
117
- response[:code].should == 200
118
- end
119
-
120
-
121
- it "should raise an error if no body data is given" do
122
- lambda { @backend.put(200, resource) }.should raise_error(ArgumentError)
123
- end
124
-
125
- it "should raise an error if the body is not a string or IO" do
126
- lambda { @backend.put(200, resource, 123) }.should raise_error(ArgumentError)
127
- end
128
- end
129
-
130
- describe "POST requests" do
131
- before :each do
132
- setup_http_mock(:post, resource.to_s, :body => "Success!")
133
- end
134
-
135
- it "should return the response body, headers, and code when the request succeeds" do
136
- response = @backend.post(200, resource, "This is the body.")
137
- response[:body].should == "Success!"
138
- response[:headers].should be_kind_of(Hash)
139
- response[:code].should == 200
140
- end
141
-
142
- it "should raise a FailedRequest exception when the request fails" do
143
- lambda { @backend.post(204, resource, "This is the body.") }.should raise_error(Riak::FailedRequest)
144
- end
145
-
146
- it "should not raise a FailedRequest if one of the expected response codes matches" do
147
- lambda { @backend.post([200, 204], resource, "This is the body.") }.should_not raise_error(Riak::FailedRequest)
148
- end
149
-
150
- it "should yield successive chunks of the response to the given block but not return the entire body" do
151
- chunks = ""
152
- response = @backend.post(200, resource, "This is the body.") do |chunk|
153
- chunks << chunk
154
- end
155
- chunks.should == "Success!"
156
- response.should_not have_key(:body)
157
- response[:headers].should be_kind_of(Hash)
158
- response[:code].should == 200
159
- end
160
-
161
- it "should raise an error if no body data is given" do
162
- lambda { @backend.post(200, resource) }.should raise_error(ArgumentError)
163
- end
164
-
165
- it "should raise an error if the body is not a string or IO" do
166
- lambda { @backend.post(200, resource, 123) }.should raise_error(ArgumentError)
167
- end
168
- end
169
-
170
- describe "Responses with no body" do
171
- [204, 205, 304].each do |code|
172
- [:get, :post, :put, :delete].each do |method|
173
- it "should not return a body on #{method.to_s.upcase} for #{code}" do
174
- setup_http_mock(method, resource.to_s, :status => code)
175
- response = if method == :post || method == :put
176
- @backend.send(method, code, resource, "This is the body")
177
- else
178
- @backend.send(method, code, resource)
179
- end
180
- response.should_not have_key(:body)
181
- end
182
- end
183
- end
184
- end
185
-
186
- describe "SSL" do
187
- it "should be supported" do
188
- unless @client.http_backend == :NetHTTP
189
- @client.nodes.each do |node|
190
- node.http_port = $mock_server.port + 1
191
- end
192
- end
193
- @client.ssl = true
194
- setup_http_mock(:get, @backend.path("/riak/","ssl").to_s, :body => "Success!")
195
- response = @backend.get(200, @backend.path("/riak/","ssl"))
196
- response[:code].should == 200
197
- end
198
- end
199
-
200
- describe "HTTP Basic Authentication", :basic_auth => true do
201
- sometimes "should add the http basic auth header" do
202
- @client.basic_auth = "ripple:rocks"
203
- if @client.http_backend == :NetHTTP
204
- setup_http_mock(:get, "http://ripple:rocks@127.0.0.1:8098/riak/auth", :body => 'Success!')
205
- else
206
- @_mock_set = "Basic #{Base64::encode64("ripple:rocks").strip}"
207
- $mock_server.attach do |env|
208
- $mock_server.satisfied = env['HTTP_AUTHORIZATION'] == @_mock_set
209
- [200, {}, Array('Success!')]
210
- end
211
- end
212
- response = @backend.get(200, @backend.path("/riak/", "auth"))
213
- response[:code].should == 200
214
- end
215
- end
216
-
217
- describe "Invalid responses" do
218
-
219
- def bad_request(method)
220
- if method == :post || method == :put
221
- @backend.send(method, 200, resource, "body")
222
- else
223
- @backend.send(method, 200, resource)
224
- end
225
- end
226
-
227
- [:get, :post, :put, :delete].each do |method|
228
- context method.to_s do
229
-
230
- before(:each) do
231
- setup_http_mock(method, resource.to_s, :body => "Failure!", :status => 400, 'Content-Type' => 'text/plain' )
232
- end
233
-
234
- it "raises an HTTPFailedRequest exeption" do
235
- lambda { bad_request(method) }.should raise_error(Riak::HTTPFailedRequest)
236
- end
237
-
238
- it "should normalize the response header keys to lower case" do
239
- begin
240
- bad_request(method)
241
- rescue Riak::HTTPFailedRequest => fr
242
- fr.headers.keys.should =~ fr.headers.keys.collect(&:downcase)
243
- else
244
- fail "No exception raised!"
245
- end
246
- end
247
-
248
- end
249
- end
250
-
251
- end
252
-
253
- end