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,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- begin
4
- require 'excon'
5
- rescue LoadError
6
- warn "Skipping ExconBackend specs, excon library not found."
7
- else
8
- $mock_server = DrbMockServer
9
- $mock_server.maybe_start
10
-
11
- describe Riak::Client::ExconBackend do
12
- def setup_http_mock(method, uri, options={})
13
- method = method.to_s.upcase
14
- uri = URI.parse(uri)
15
- path = uri.path || "/"
16
- query = uri.query || ""
17
- body = options[:body] || []
18
- headers = options[:headers] || {}
19
- headers['Content-Type'] ||= "text/plain"
20
- status = options[:status] ? Array(options[:status]).first.to_i : 200
21
- @_mock_set = [status, headers, method, path, query, body]
22
- $mock_server.expect(*@_mock_set)
23
- end
24
-
25
- before :each do
26
- @client = Riak::Client.new(:http_port => $mock_server.port, :http_backend => :Excon) # Point to our mock
27
- @node = @client.node
28
- @backend = @client.new_http_backend if described_class.configured?
29
- @_mock_set = false
30
- end
31
-
32
- after :each do
33
- if @_mock_set
34
- $mock_server.satisfied.should be_true #("Expected #{@_mock_set.inspect}, failed")
35
- end
36
- end
37
-
38
- it_should_behave_like "HTTP backend"
39
-
40
- it "should split long headers into 8KB chunks" do
41
- # TODO: This doesn't actually inspect the emitted headers. How
42
- # can it?
43
- setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
44
- lambda do
45
- @backend.put(200, @backend.path("/riak", "foo"), "body", {"Long-Header" => (["12345678"*10]*100).join(", ") })
46
- end.should_not raise_error
47
- end
48
-
49
- it "should support IO objects as the request body on PUT" do
50
- File.open(File.expand_path("../../fixtures/cat.jpg", __FILE__), 'rb') do |file|
51
- lambda do
52
- setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
53
- @backend.put(200, @backend.path("/riak/","foo"), file)
54
- $mock_server.satisfied.should be_true
55
- end.should_not raise_error
56
- end
57
- end
58
-
59
- it "should support IO objects as the request body on POST" do
60
- File.open(File.expand_path("../../fixtures/cat.jpg", __FILE__), 'rb') do |file|
61
- lambda do
62
- setup_http_mock(:post, @backend.path("/riak/","foo").to_s, :body => "ok")
63
- @backend.post(200, @backend.path("/riak/", "foo"), file)
64
- $mock_server.satisfied.should be_true
65
- end.should_not raise_error
66
- end
67
- end
68
-
69
- context "checking the Excon Gem version" do
70
- subject { described_class }
71
-
72
- def suppress_warnings
73
- original_verbosity = $VERBOSE
74
- $VERBOSE = nil
75
- result = yield
76
- $VERBOSE = original_verbosity
77
- return result
78
- end
79
-
80
- def set_excon_version(v)
81
- original_version = Excon::VERSION
82
- suppress_warnings { Excon.const_set(:VERSION, v) }
83
- yield
84
- suppress_warnings {Excon.const_set(:VERSION, original_version)}
85
- end
86
-
87
- context "when it meets the minimum requirement" do
88
- it { should be_configured }
89
-
90
- context "and has a version number that is not *lexically* greater than the minimum version" do
91
- around {|ex| set_excon_version("0.13.2", &ex) }
92
- it { should be_configured }
93
- end
94
- end
95
-
96
- context "when it does not meet the minimum requirement" do
97
- around {|ex| set_excon_version("0.5.6", &ex) }
98
- it { should_not be_configured }
99
- end
100
- end
101
- end
102
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Util::Headers do
4
- it "should include the Net::HTTPHeader module" do
5
- Riak::Util::Headers.included_modules.should include(Net::HTTPHeader)
6
- end
7
-
8
- it "should be initially empty" do
9
- Riak::Util::Headers.new.to_hash.should == {}
10
- end
11
-
12
- it "should parse a header line into the key and value" do
13
- Riak::Util::Headers.parse("Content-Type: text/plain\r\n").should == ["Content-Type", "text/plain"]
14
- end
15
-
16
- it "should parse a header line and add it to the collection" do
17
- h = Riak::Util::Headers.new
18
- h.parse("Content-Type: text/plain\r\n")
19
- h.to_hash.should == {"content-type" => ["text/plain"]}
20
- end
21
- end
@@ -1,273 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client::HTTPBackend::Configuration do
4
- let(:client){ Riak::Client.new }
5
- let(:node){ client.node }
6
- subject { Riak::Client::HTTPBackend.new(client, node) }
7
- let(:uri){ URI.parse("http://127.0.0.1:8098/") }
8
-
9
- context "generating resource URIs" do
10
- context "when using the old scheme" do
11
- before { subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_raw", </ping>; rel="riak_kv_wm_ping", </stats>; rel="riak_kv_wm_stats", </mapred>; rel="riak_kv_wm_mapred"']}) }
12
-
13
- it "should generate a ping path" do
14
- url = subject.ping_path
15
- url.should be_kind_of(URI)
16
- url.path.should == '/ping'
17
- end
18
-
19
- it "should generate a stats path" do
20
- url = subject.stats_path
21
- url.should be_kind_of(URI)
22
- url.path.should == '/stats'
23
- end
24
-
25
- it "should generate a mapred path" do
26
- url = subject.mapred_path :chunked => true
27
- url.should be_kind_of(URI)
28
- url.path.should == '/mapred'
29
- url.query.should == "chunked=true"
30
- end
31
-
32
- it "should generate a bucket list path" do
33
- url = subject.bucket_list_path
34
- url.should be_kind_of(URI)
35
- url.path.should == '/riak'
36
- url.query.should == 'buckets=true'
37
- end
38
-
39
- it "should generate a bucket properties path" do
40
- url = subject.bucket_properties_path('test ')
41
- url.should be_kind_of(URI)
42
- url.path.should == '/riak/test%20'
43
- url.query.should == "keys=false&props=true"
44
- end
45
-
46
- it "should generate a key list path" do
47
- url = subject.key_list_path('test ')
48
- url.should be_kind_of(URI)
49
- url.path.should == '/riak/test%20'
50
- url.query.should == 'keys=true&props=false'
51
- url = subject.key_list_path('test ', :keys => :stream)
52
- url.path.should == '/riak/test%20'
53
- url.query.should == 'keys=stream&props=false'
54
- end
55
-
56
- it "should generate an object path" do
57
- url = subject.object_path('test ', 'object/', :r => 3)
58
- url.should be_kind_of(URI)
59
- url.path.should == '/riak/test%20/object%2F'
60
- url.query.should == 'r=3'
61
- end
62
-
63
- it "should generate a link-walking path" do
64
- url = subject.link_walk_path('test ', 'object/', [Riak::WalkSpec.new(:bucket => 'foo')])
65
- url.should be_kind_of(URI)
66
- url.path.should == '/riak/test%20/object%2F/foo,_,_'
67
- end
68
-
69
- it "should raise an error when generating an index range path" do
70
- expect { subject.index_range_path('test', 'index_bin', 'a', 'b') }.to raise_error
71
- end
72
-
73
- it "should raise an error when generating an index equal path" do
74
- expect { subject.index_eq_path('test', 'index_bin', 'a') }.to raise_error
75
- end
76
- end
77
-
78
- context "when using the new scheme" do
79
- before { subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</buckets>; rel="riak_kv_wm_buckets", </ping>; rel="riak_kv_wm_ping", </stats>; rel="riak_kv_wm_stats", </mapred>; rel="riak_kv_wm_mapred"']}) }
80
-
81
- it "should generate a ping path" do
82
- url = subject.ping_path
83
- url.should be_kind_of(URI)
84
- url.path.should == '/ping'
85
- end
86
-
87
- it "should generate a stats path" do
88
- url = subject.stats_path
89
- url.should be_kind_of(URI)
90
- url.path.should == '/stats'
91
- end
92
-
93
- it "should generate a mapred path" do
94
- url = subject.mapred_path :chunked => true
95
- url.should be_kind_of(URI)
96
- url.path.should == '/mapred'
97
- url.query.should == "chunked=true"
98
- end
99
-
100
- it "should generate a bucket list path" do
101
- url = subject.bucket_list_path
102
- url.should be_kind_of(URI)
103
- url.path.should == '/buckets'
104
- url.query.should == 'buckets=true'
105
- end
106
-
107
- it "should generate a bucket properties path" do
108
- url = subject.bucket_properties_path('test ')
109
- url.should be_kind_of(URI)
110
- url.path.should == '/buckets/test%20/props'
111
- url.query.should be_nil
112
- end
113
-
114
- it "should generate a key list path" do
115
- url = subject.key_list_path('test ')
116
- url.should be_kind_of(URI)
117
- url.path.should == '/buckets/test%20/keys'
118
- url.query.should == 'keys=true'
119
- url = subject.key_list_path('test ', :keys => :stream)
120
- url.path.should == '/buckets/test%20/keys'
121
- url.query.should == 'keys=stream'
122
- end
123
-
124
- it "should generate an object path" do
125
- url = subject.object_path('test ', 'object/', :r => 3)
126
- url.should be_kind_of(URI)
127
- url.path.should == '/buckets/test%20/keys/object%2F'
128
- url.query.should == 'r=3'
129
- end
130
-
131
- it "should generate a link-walking path" do
132
- url = subject.link_walk_path('test ', 'object/', [Riak::WalkSpec.new(:bucket => 'foo')])
133
- url.should be_kind_of(URI)
134
- url.path.should == '/buckets/test%20/keys/object%2F/foo,_,_'
135
- end
136
-
137
- it "should generate an index range path" do
138
- url = subject.index_range_path('test ', 'test_bin', 'a', 'b')
139
- url.should be_kind_of(URI)
140
- url.path.should == '/buckets/test%20/index/test_bin/a/b'
141
- end
142
-
143
- it "should generate an index equal path" do
144
- url = subject.index_eq_path('test ', 'test_bin', 'a')
145
- url.should be_kind_of(URI)
146
- url.path.should == '/buckets/test%20/index/test_bin/a'
147
- end
148
- end
149
- end
150
-
151
- it "should memoize the server config" do
152
- subject.should_receive(:get).with(200, uri).once.and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_link_walker",</mapred>; rel="riak_kv_wm_mapred",</ping>; rel="riak_kv_wm_ping",</riak>; rel="riak_kv_wm_raw",</stats>; rel="riak_kv_wm_stats"']})
153
- subject.send(:riak_kv_wm_link_walker).should == "/riak"
154
- subject.send(:riak_kv_wm_raw).should == "/riak"
155
- end
156
-
157
- context "generating Solr paths" do
158
- context "when Riak Search is disabled" do
159
- before {
160
- subject.should_receive(:get).with(200, uri).once.and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_link_walker",</mapred>; rel="riak_kv_wm_mapred",</ping>; rel="riak_kv_wm_ping",</riak>; rel="riak_kv_wm_raw",</stats>; rel="riak_kv_wm_stats"']})
161
- }
162
-
163
- it "should raise an error" do
164
- expect { subject.solr_select_path('foo', 'a:b') }.to raise_error
165
- expect { subject.solr_update_path('foo') }.to raise_error
166
- end
167
- end
168
-
169
- context "when Riak Search is enabled" do
170
- before {
171
- subject.should_receive(:get).with(200, uri).once.and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_link_walker",</mapred>; rel="riak_kv_wm_mapred",</ping>; rel="riak_kv_wm_ping",</riak>; rel="riak_kv_wm_raw",</stats>; rel="riak_kv_wm_stats", </solr>; rel="riak_solr_indexer_wm", </solr>; rel="riak_solr_searcher_wm"']})
172
- }
173
-
174
- it "should generate a search path for the default index" do
175
- url = subject.solr_select_path(nil, 'a:b')
176
- url.should be_kind_of(URI)
177
- url.path.should == '/solr/select'
178
- url.query.should include("q=a%3Ab")
179
- url.query.should include('wt=json')
180
- end
181
-
182
- it "should generate a search path for a specified index" do
183
- url = subject.solr_select_path('foo', 'a:b', 'wt' => 'xml')
184
- url.should be_kind_of(URI)
185
- url.path.should == '/solr/foo/select'
186
- url.query.should include("q=a%3Ab")
187
- url.query.should include('wt=xml')
188
- end
189
-
190
- it "should generate an indexing path for the default index" do
191
- url = subject.solr_update_path(nil)
192
- url.should be_kind_of(URI)
193
- url.path.should == '/solr/update'
194
- end
195
-
196
- it "should generate an indexing path for a specified index" do
197
- url = subject.solr_update_path('foo')
198
- url.should be_kind_of(URI)
199
- url.path.should == '/solr/foo/update'
200
- end
201
- end
202
- end
203
-
204
- context "when Luwak is enabled" do
205
- before { subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_raw", </ping>; rel="riak_kv_wm_ping", </stats>; rel="riak_kv_wm_stats", </mapred>; rel="riak_kv_wm_mapred", </luwak>; rel="luwak_wm_file"']}) }
206
-
207
- it "should generate a path for a file" do
208
- url = subject.luwak_path('foo')
209
- url.should be_kind_of(URI)
210
- url.path.should == '/luwak/foo'
211
- end
212
-
213
- it "should generate a path for the root" do
214
- url = subject.luwak_path(nil)
215
- url.should be_kind_of(URI)
216
- url.path.should == '/luwak'
217
- end
218
-
219
- it "should escape a nested path" do
220
- url = subject.luwak_path("foo/bar/baz")
221
- url.should be_kind_of(URI)
222
- url.path.should == '/luwak/foo%2Fbar%2Fbaz'
223
- end
224
- end
225
-
226
- context "when Luwak is disabled" do
227
- before { subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_raw", </ping>; rel="riak_kv_wm_ping", </stats>; rel="riak_kv_wm_stats", </mapred>; rel="riak_kv_wm_mapred"']}) }
228
-
229
- it "should raise an error when generating the path" do
230
- expect { subject.luwak_path(nil) }.to raise_error
231
- expect { subject.luwak_path('foo') }.to raise_error
232
- end
233
- end
234
-
235
- {
236
- :riak_kv_wm_raw => :prefix,
237
- :riak_kv_wm_link_walker => :prefix,
238
- :riak_kv_wm_mapred => :mapred
239
- }.each do |resource, alternate|
240
- it "should detect the #{resource} resource from the configuration URL" do
241
- subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => [%Q{</path>; rel="#{resource}"}]})
242
- subject.send(resource).should == "/path"
243
- end
244
-
245
- it "should fallback to node.http_paths[:#{alternate}] if the #{resource} resource is not found" do
246
- subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</>; rel="top"']})
247
- subject.send(resource).should == node.http_paths[alternate]
248
- end
249
-
250
- it "should fallback to node.http_paths[:#{alternate}] if request fails" do
251
- subject.should_receive(:get).with(200, uri).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
252
- subject.send(resource).should == node.http_paths[alternate]
253
- end
254
- end
255
-
256
- {
257
- :riak_kv_wm_ping => "/ping",
258
- :riak_kv_wm_stats => "/stats"
259
- }.each do |resource, default|
260
- it "should detect the #{resource} resource from the configuration URL" do
261
- subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => [%Q{</path>; rel="#{resource}"}]})
262
- subject.send(resource).should == "/path"
263
- end
264
- it "should fallback to #{default.inspect} if the #{resource} resource is not found" do
265
- subject.should_receive(:get).with(200, uri).and_return(:headers => {'link' => ['</>; rel="top"']})
266
- subject.send(resource).should == default
267
- end
268
- it "should fallback to #{default.inspect} if request fails" do
269
- subject.should_receive(:get).with(200, uri).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
270
- subject.send(resource).should == default
271
- end
272
- end
273
- end
@@ -1,243 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client::HTTPBackend::ObjectMethods do
4
- before :each do
5
- @client = Riak::Client.new
6
- @backend = Riak::Client::HTTPBackend.new(@client, @client.node)
7
- @bucket = Riak::Bucket.new(@client, "bucket")
8
- @object = Riak::RObject.new(@bucket, "bar")
9
- @backend.stub!(:new_scheme?).and_return(false)
10
- end
11
-
12
- describe "loading object data from the response" do
13
- it "should load the content type" do
14
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}})
15
- @object.content_type.should == "application/json"
16
- end
17
-
18
- it "should load the body data" do
19
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => '{"foo":"bar"}'})
20
- @object.raw_data.should be_present
21
- @object.data.should be_present
22
- end
23
-
24
- it "should handle raw data properly" do
25
- @object.should_not_receive(:deserialize) # optimize for the raw_data case, don't penalize people for using raw_data
26
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => body = '{"foo":"bar"}'})
27
- @object.raw_data.should == body
28
- end
29
-
30
- it "should deserialize the body data" do
31
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => "{}"})
32
- @object.data.should == {}
33
- end
34
-
35
- it "should leave the object data unchanged if the response body is blank" do
36
- @object.data = "Original data"
37
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => "", :code => 304})
38
- @object.data.should == "Original data"
39
- end
40
-
41
- it "should load the vclock from the headers" do
42
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], 'x-riak-vclock' => ["somereallylongbase64string=="]}, :body => "{}"})
43
- @object.vclock.should == "somereallylongbase64string=="
44
- end
45
-
46
- it "should load links from the headers" do
47
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "link" => ['</riak/bar>; rel="up"']}, :body => "{}"})
48
- @object.links.should have(1).item
49
- @object.links.first.url.should == "/riak/bar"
50
- @object.links.first.rel.should == "up"
51
- end
52
-
53
- it "should load the ETag from the headers" do
54
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "etag" => ["32748nvas83572934"]}, :body => "{}"})
55
- @object.etag.should == "32748nvas83572934"
56
- end
57
-
58
- it "should load the modified date from the headers" do
59
- time = Time.now
60
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "last-modified" => [time.httpdate]}, :body => "{}"})
61
- @object.last_modified.to_s.should == time.to_s # bah, times are not equivalent unless equal
62
- end
63
-
64
- it "should load meta information from the headers" do
65
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "x-riak-meta-some-kind-of-robot" => ["for AWESOME"]}, :body => "{}"})
66
- @object.meta["some-kind-of-robot"].should == ["for AWESOME"]
67
- end
68
-
69
- it "should load indexes from the headers" do
70
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "x-riak-index-email_bin" => ["sean@basho.com"], "x-riak-index-rank_int" => ["50"]}, :body => "{}"})
71
- @object.indexes['email_bin'].should include('sean@basho.com')
72
- @object.indexes['rank_int'].should include(50)
73
- end
74
-
75
- it "should parse the location header into the key when present" do
76
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/baz"]}})
77
- @object.key.should == "baz"
78
- end
79
-
80
- it "should parse and escape the location header into the key when present" do
81
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/%5Bbaz%5D?vtag=1234"]}})
82
- @object.key.should == "[baz]"
83
- end
84
-
85
- context "when the response code is 300 and the content-type is multipart/mixed" do
86
- let(:http_response) { {:headers => {"content-type" => ["multipart/mixed; boundary=8XZD3w6ttFTHIz6LCmhVxn9Ex0K"]}, :code => 300, :body => File.read("spec/fixtures/multipart-basic-conflict.txt")} }
87
- let(:other_object) { Riak::RObject.new(@bucket, "bar2") }
88
-
89
- it 'marks the object as in conflict' do
90
- @backend.load_object(@object, http_response)
91
- @object.should be_conflict
92
- end
93
-
94
- it 'attempts to resolve the conflict' do
95
- @object.should respond_to(:attempt_conflict_resolution)
96
- @object.should_receive(:attempt_conflict_resolution).and_return(other_object)
97
- @backend.load_object(@object, http_response).should be(other_object)
98
- end
99
- end
100
-
101
- it "should unescape the key given in the location header" do
102
- @backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/baz%20"]}})
103
- @object.key.should == "baz "
104
- end
105
-
106
- describe "extracting siblings" do
107
- before :each do
108
- @backend.load_object(@object, {:headers => {"x-riak-vclock" => ["merged"], "content-type" => ["multipart/mixed; boundary=8XZD3w6ttFTHIz6LCmhVxn9Ex0K"]}, :code => 300, :body => File.read("spec/fixtures/multipart-basic-conflict.txt")})
109
- end
110
-
111
- it "should extract the siblings" do
112
- @object.should have(2).siblings
113
- siblings = @object.siblings
114
- siblings[0].data.should == "bar"
115
- siblings[1].data.should == "foo"
116
- end
117
- end
118
- end
119
-
120
- describe "headers used for storing the object" do
121
- it "should include the content type" do
122
- @object.content_type = "application/json"
123
- @backend.store_headers(@object)["Content-Type"].should == "application/json"
124
- end
125
-
126
- it "should include the vclock when present" do
127
- @object.vclock = "123445678990"
128
- @backend.store_headers(@object)["X-Riak-Vclock"].should == "123445678990"
129
- end
130
-
131
- it "should exclude the vclock when nil" do
132
- @object.vclock = nil
133
- @backend.store_headers(@object).should_not have_key("X-Riak-Vclock")
134
- end
135
-
136
- describe "when conditional PUTs are requested" do
137
- before :each do
138
- @object.prevent_stale_writes = true
139
- end
140
-
141
- it "should include an If-None-Match: * header" do
142
- @backend.store_headers(@object).should have_key("If-None-Match")
143
- @backend.store_headers(@object)["If-None-Match"].should == "*"
144
- end
145
-
146
- it "should include an If-Match header with the etag when an etag is present" do
147
- @object.etag = "foobar"
148
- @backend.store_headers(@object).should have_key("If-Match")
149
- @backend.store_headers(@object)["If-Match"].should == @object.etag
150
- end
151
- end
152
-
153
- describe "when links are defined" do
154
- before :each do
155
- @object.links << Riak::Link.new("/riak/foo/baz", "next")
156
- end
157
-
158
- it "should include a Link header with references to other objects" do
159
- @backend.store_headers(@object).should have_key("Link")
160
- @backend.store_headers(@object)["Link"].should include('</riak/foo/baz>; riaktag="next"')
161
- end
162
-
163
- it "should exclude the 'up' link to the bucket from the header" do
164
- @object.links << Riak::Link.new("/riak/foo", "up")
165
- @backend.store_headers(@object).should have_key("Link")
166
- @backend.store_headers(@object)["Link"].should_not include('riaktag="up"')
167
- end
168
-
169
- context "when using the new URL scheme" do
170
- before { @backend.stub!(:new_scheme?).and_return(true) }
171
-
172
- it "should encode Links using the new format" do
173
- @backend.store_headers(@object).should have_key("Link")
174
- @backend.store_headers(@object)['Link'].should include('</buckets/foo/keys/baz>; riaktag="next"')
175
- end
176
- end
177
- end
178
-
179
- it "should exclude the Link header when no links are present" do
180
- @object.links = Set.new
181
- @backend.store_headers(@object).should_not have_key("Link")
182
- end
183
-
184
- describe "when meta fields are present" do
185
- before :each do
186
- @object.meta = {"some-kind-of-robot" => true, "powers" => "for awesome", "cold-ones" => 10}
187
- end
188
-
189
- it "should include X-Riak-Meta-* headers for each meta key" do
190
- @backend.store_headers(@object).should have_key("X-Riak-Meta-some-kind-of-robot")
191
- @backend.store_headers(@object).should have_key("X-Riak-Meta-cold-ones")
192
- @backend.store_headers(@object).should have_key("X-Riak-Meta-powers")
193
- end
194
-
195
- it "should turn non-string meta values into strings" do
196
- @backend.store_headers(@object)["X-Riak-Meta-some-kind-of-robot"].should == "true"
197
- @backend.store_headers(@object)["X-Riak-Meta-cold-ones"].should == "10"
198
- end
199
-
200
- it "should leave string meta values unchanged in the header" do
201
- @backend.store_headers(@object)["X-Riak-Meta-powers"].should == "for awesome"
202
- end
203
- end
204
-
205
- describe "when indexes are present" do
206
- before :each do
207
- @object.indexes = {"email_bin" => Set.new(['sean@basho.com', 'seancribbs@gmail.com']), "rank_int" => Set.new([50])}
208
- end
209
-
210
- it "should include X-Riak-Index-* headers for each index key" do
211
- @backend.store_headers(@object).should have_key('X-Riak-Index-email_bin')
212
- @backend.store_headers(@object).should have_key('X-Riak-Index-rank_int')
213
- end
214
-
215
- it "should join multi-valued indexes into a single header" do
216
- @backend.store_headers(@object)['X-Riak-Index-email_bin'].should == 'sean@basho.com, seancribbs@gmail.com'
217
- end
218
-
219
- it "should turn integer indexes into strings in the header" do
220
- @backend.store_headers(@object)['X-Riak-Index-rank_int'].should == '50'
221
- end
222
- end
223
- end
224
-
225
- describe "headers used for reloading the object" do
226
- it "should be blank when the etag and last_modified properties are blank" do
227
- @object.etag.should be_blank
228
- @object.last_modified.should be_blank
229
- @backend.reload_headers(@object).should be_blank
230
- end
231
-
232
- it "should include the If-None-Match key when the etag is present" do
233
- @object.etag = "etag!"
234
- @backend.reload_headers(@object)['If-None-Match'].should == "etag!"
235
- end
236
-
237
- it "should include the If-Modified-Since header when the last_modified time is present" do
238
- time = Time.now
239
- @object.last_modified = time
240
- @backend.reload_headers(@object)['If-Modified-Since'].should == time.httpdate
241
- end
242
- end
243
- end