riak-client 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/RELNOTES.md +3 -0
  4. data/lib/riak/bucket.rb +1 -1
  5. data/lib/riak/client.rb +14 -7
  6. data/lib/riak/client/beefcake/messages.rb +13 -0
  7. data/lib/riak/multi.rb +101 -0
  8. data/lib/riak/multiexist.rb +14 -0
  9. data/lib/riak/multiget.rb +7 -107
  10. data/lib/riak/version.rb +1 -1
  11. metadata +12 -234
  12. data/.document +0 -5
  13. data/.gitignore +0 -44
  14. data/.rspec +0 -2
  15. data/Gemfile +0 -17
  16. data/Guardfile +0 -20
  17. data/Rakefile +0 -124
  18. data/riak-client.gemspec +0 -71
  19. data/spec/failover/failover.rb +0 -59
  20. data/spec/fixtures/bitcask.txt +0 -25
  21. data/spec/fixtures/cat.jpg +0 -0
  22. data/spec/fixtures/multipart-basic-conflict.txt +0 -15
  23. data/spec/fixtures/multipart-blank.txt +0 -7
  24. data/spec/fixtures/multipart-mapreduce.txt +0 -10
  25. data/spec/fixtures/multipart-with-body.txt +0 -16
  26. data/spec/fixtures/multipart-with-marked-tombstones.txt +0 -17
  27. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +0 -16
  28. data/spec/fixtures/server.cert.crt +0 -15
  29. data/spec/fixtures/server.cert.key +0 -15
  30. data/spec/fixtures/test.pem +0 -1
  31. data/spec/fixtures/yz_schema_template.xml +0 -18
  32. data/spec/integration/riak/bucket_types_spec.rb +0 -308
  33. data/spec/integration/riak/conflict_resolution_spec.rb +0 -96
  34. data/spec/integration/riak/counters_spec.rb +0 -36
  35. data/spec/integration/riak/crdt/configuration_spec.rb +0 -38
  36. data/spec/integration/riak/crdt_search_spec.rb +0 -176
  37. data/spec/integration/riak/crdt_spec.rb +0 -332
  38. data/spec/integration/riak/crdt_validation/map_spec.rb +0 -63
  39. data/spec/integration/riak/crdt_validation/set_spec.rb +0 -122
  40. data/spec/integration/riak/encodings/crdt_spec.rb +0 -122
  41. data/spec/integration/riak/encodings/kv_spec.rb +0 -87
  42. data/spec/integration/riak/encodings/yz_spec.rb +0 -142
  43. data/spec/integration/riak/preflist_spec.rb +0 -43
  44. data/spec/integration/riak/properties_spec.rb +0 -69
  45. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +0 -33
  46. data/spec/integration/riak/protobuffs/timeouts_spec.rb +0 -178
  47. data/spec/integration/riak/protobuffs_backends_spec.rb +0 -40
  48. data/spec/integration/riak/search_spec.rb +0 -104
  49. data/spec/integration/riak/secondary_index_spec.rb +0 -72
  50. data/spec/integration/riak/security_spec.rb +0 -105
  51. data/spec/integration/riak/threading_spec.rb +0 -154
  52. data/spec/integration/riak/time_series_spec.rb +0 -212
  53. data/spec/integration/yokozuna/index_spec.rb +0 -61
  54. data/spec/integration/yokozuna/queries_spec.rb +0 -115
  55. data/spec/integration/yokozuna/schema_spec.rb +0 -49
  56. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +0 -247
  57. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +0 -244
  58. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +0 -53
  59. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +0 -189
  60. data/spec/riak/beefcake_protobuffs_backend/ts_cell_codec_spec.rb +0 -124
  61. data/spec/riak/beefcake_protobuffs_backend_spec.rb +0 -162
  62. data/spec/riak/bucket_properties_spec.rb +0 -135
  63. data/spec/riak/bucket_spec.rb +0 -275
  64. data/spec/riak/bucket_type_spec.rb +0 -50
  65. data/spec/riak/bucket_typed/bucket_spec.rb +0 -78
  66. data/spec/riak/client_spec.rb +0 -304
  67. data/spec/riak/core_ext/to_param_spec.rb +0 -15
  68. data/spec/riak/counter_spec.rb +0 -122
  69. data/spec/riak/crdt/counter_spec.rb +0 -55
  70. data/spec/riak/crdt/hyper_log_log_spec.rb +0 -56
  71. data/spec/riak/crdt/inner_counter_spec.rb +0 -21
  72. data/spec/riak/crdt/inner_flag_spec.rb +0 -39
  73. data/spec/riak/crdt/inner_map_spec.rb +0 -47
  74. data/spec/riak/crdt/inner_register_spec.rb +0 -40
  75. data/spec/riak/crdt/inner_set_spec.rb +0 -33
  76. data/spec/riak/crdt/map_spec.rb +0 -78
  77. data/spec/riak/crdt/set_spec.rb +0 -61
  78. data/spec/riak/crdt/shared_examples.rb +0 -88
  79. data/spec/riak/crdt/typed_collection_spec.rb +0 -225
  80. data/spec/riak/escape_spec.rb +0 -72
  81. data/spec/riak/feature_detection_spec.rb +0 -77
  82. data/spec/riak/index_collection_spec.rb +0 -53
  83. data/spec/riak/instrumentation_spec.rb +0 -124
  84. data/spec/riak/link_spec.rb +0 -85
  85. data/spec/riak/list_buckets_spec.rb +0 -41
  86. data/spec/riak/map_reduce/filter_builder_spec.rb +0 -32
  87. data/spec/riak/map_reduce/phase_spec.rb +0 -142
  88. data/spec/riak/map_reduce_spec.rb +0 -434
  89. data/spec/riak/multiget_spec.rb +0 -81
  90. data/spec/riak/node_spec.rb +0 -26
  91. data/spec/riak/robject_spec.rb +0 -542
  92. data/spec/riak/search/index_spec.rb +0 -72
  93. data/spec/riak/search/query_spec.rb +0 -88
  94. data/spec/riak/search/result_collection_spec.rb +0 -89
  95. data/spec/riak/search/result_document_spec.rb +0 -106
  96. data/spec/riak/search/schema_spec.rb +0 -63
  97. data/spec/riak/search_spec.rb +0 -107
  98. data/spec/riak/secondary_index_spec.rb +0 -225
  99. data/spec/riak/serializers_spec.rb +0 -121
  100. data/spec/riak/stamp_spec.rb +0 -54
  101. data/spec/riak/time_series/deletion_spec.rb +0 -33
  102. data/spec/riak/time_series/listing_spec.rb +0 -51
  103. data/spec/riak/time_series/submission_spec.rb +0 -35
  104. data/spec/riak/util/gzip_spec.rb +0 -49
  105. data/spec/riak/walk_spec_spec.rb +0 -203
  106. data/spec/spec_helper.rb +0 -67
  107. data/spec/support/certs/README.md +0 -13
  108. data/spec/support/certs/ca.crt +0 -21
  109. data/spec/support/certs/client.crl +0 -13
  110. data/spec/support/certs/client.crt +0 -94
  111. data/spec/support/certs/client.csr +0 -18
  112. data/spec/support/certs/client.key +0 -27
  113. data/spec/support/certs/empty_ca.crt +0 -21
  114. data/spec/support/certs/server.crl +0 -13
  115. data/spec/support/certs/server.crt +0 -94
  116. data/spec/support/certs/server.key +0 -27
  117. data/spec/support/crdt_search_config.rb +0 -112
  118. data/spec/support/crdt_search_fixtures.rb +0 -42
  119. data/spec/support/integration_setup.rb +0 -10
  120. data/spec/support/search_config.rb +0 -83
  121. data/spec/support/search_corpus_setup.rb +0 -39
  122. data/spec/support/test_client.rb +0 -52
  123. data/spec/support/test_client.yml.example +0 -10
  124. data/spec/support/unified_backend_examples.rb +0 -402
  125. data/spec/support/version_filter.rb +0 -12
  126. data/spec/support/wait_until.rb +0 -20
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::IndexCollection do
4
- describe "json initialization" do
5
- it "accepts a list of keys" do
6
- @input = {
7
- 'keys' => %w{first second third}
8
- }.to_json
9
- expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
10
- expect(%w{first second third}).to eq(@coll)
11
- end
12
-
13
- it "accepts a list of keys and a continuation" do
14
- @input = {
15
- 'keys' => %w{first second third},
16
- 'continuation' => 'examplecontinuation'
17
- }.to_json
18
- expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
19
- expect(%w{first second third}).to eq(@coll)
20
- expect(@coll.continuation).to eq('examplecontinuation')
21
- end
22
-
23
- it "accepts a list of results hashes" do
24
- @input = {
25
- 'results' => [
26
- {'first' => 'first'},
27
- {'second' => 'second'},
28
- {'second' => 'other'}
29
- ]
30
- }.to_json
31
-
32
- expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
33
- expect(%w{first second other}).to eq(@coll)
34
- expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
35
- end
36
-
37
- it "accepts a list of results hashes and a continuation" do
38
- @input = {
39
- 'results' => [
40
- {'first' => 'first'},
41
- {'second' => 'second'},
42
- {'second' => 'other'}
43
- ],
44
- 'continuation' => 'examplecontinuation'
45
- }.to_json
46
-
47
- expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
48
- expect(%w{first second other}).to eq(@coll)
49
- expect(@coll.continuation).to eq('examplecontinuation')
50
- expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
51
- end
52
- end
53
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client do
4
-
5
- before do
6
- @client = Riak::Client.new
7
- @backend = double("Backend")
8
- allow(@client).to receive(:backend).and_yield(@backend)
9
- allow(@client).to receive(: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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to receive(:reset_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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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
- expect(@backend).to 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 'mapred' operation" do
97
- @mapred = Riak::MapReduce.new(@client).add('test').map("function(){}").map("function(){}")
98
- expect(@backend).to receive(:mapred).and_return(nil)
99
- test_client_event(@client, 'riak.map_reduce') do
100
- @client.mapred(@mapred)
101
- end
102
- end
103
-
104
- it "should notify on the 'ping' operation" do
105
- expect(@backend).to receive(:ping).and_return(nil)
106
- test_client_event(@client, 'riak.ping') do
107
- @client.ping
108
- end
109
- end
110
- end
111
- end
112
-
113
- def test_client_event(client, event_name, &block)
114
- block.call
115
- expect(@events.size).to eql(1)
116
- event = @events.first
117
- expect(event.name).to eql(event_name)
118
- expect(event.payload[:client_id]).to eql(client.client_id)
119
- end
120
-
121
- # name, start, finish, id, payload
122
- def event(*args)
123
- ActiveSupport::Notifications::Event.new(*args)
124
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Link do
4
- describe "parsing a link header" do
5
- it "creates Link objects from the data" do
6
- result = Riak::Link.parse('</riak/foo/bar>; rel="tag", </riak/foo>; rel="up"')
7
- expect(result).to be_kind_of(Array)
8
- expect(result).to be_all {|i| Riak::Link === i }
9
- end
10
-
11
- it "sets the bucket, key, url and rel parameters properly" do
12
- result = Riak::Link.parse('</riak/foo/bar>; riaktag="tag", </riak/foo>; rel="up"')
13
- expect(result[0].url).to eq("/riak/foo/bar")
14
- expect(result[0].bucket).to eq("foo")
15
- expect(result[0].key).to eq("bar")
16
- expect(result[0].rel).to eq("tag")
17
- expect(result[1].url).to eq("/riak/foo")
18
- expect(result[1].bucket).to eq("foo")
19
- expect(result[1].key).to eq(nil)
20
- expect(result[1].rel).to eq("up")
21
- end
22
-
23
- it "keeps the url intact if it does not point to a bucket or bucket/key" do
24
- result = Riak::Link.parse('</mapred>; rel="riak_kv_wm_mapred"')
25
- expect(result[0].url).to eq("/mapred")
26
- expect(result[0].bucket).to be_nil
27
- expect(result[0].key).to be_nil
28
- end
29
-
30
- it "parses the Riak 1.0 URL scheme" do
31
- result = Riak::Link.parse('</buckets/b/keys/k>; riaktag="tag"').first
32
- expect(result.bucket).to eq('b')
33
- expect(result.key).to eq('k')
34
- expect(result.tag).to eq('tag')
35
- end
36
- end
37
-
38
- context "converting to a string" do
39
- it "to a string appropriate for use in the Link header" do
40
- expect(Riak::Link.new("/riak/foo", "up").to_s).to eq('</riak/foo>; riaktag="up"')
41
- expect(Riak::Link.new("/riak/foo/bar", "next").to_s).to eq('</riak/foo/bar>; riaktag="next"')
42
- expect(Riak::Link.new("/riak", "riak_kv_wm_raw").to_s).to eq('</riak>; riaktag="riak_kv_wm_raw"')
43
- end
44
-
45
- it "converts to a string using the new URL scheme" do
46
- expect(Riak::Link.new("bucket", "key", "tag").to_s(true)).to eq('</buckets/bucket/keys/key>; riaktag="tag"')
47
- expect(Riak::Link.parse('</riak/bucket/key>; riaktag="tag"').first.to_s(true)).to eq('</buckets/bucket/keys/key>; riaktag="tag"')
48
- end
49
- end
50
-
51
- it "converts to a walk spec when pointing to an object" do
52
- expect(Riak::Link.new("/riak/foo/bar", "next").to_walk_spec.to_s).to eq("foo,next,_")
53
- expect { Riak::Link.new("/riak/foo", "up").to_walk_spec }.to raise_error
54
- end
55
-
56
- it "is equivalent to a link with the same url and rel" do
57
- one = Riak::Link.new("/riak/foo/bar", "next")
58
- two = Riak::Link.new("/riak/foo/bar", "next")
59
- expect(one).to eq(two)
60
- expect([one]).to include(two)
61
- expect([two]).to include(one)
62
- end
63
-
64
- it "unescapes the bucket name" do
65
- expect(Riak::Link.new("/riak/bucket%20spaces/key", "foo").bucket).to eq("bucket spaces")
66
- end
67
-
68
- it "unescapes the key name" do
69
- expect(Riak::Link.new("/riak/bucket/key%2Fname", "foo").key).to eq("key/name")
70
- end
71
-
72
- it "doesn't rely on the prefix to equal /riak/ when extracting the bucket and key" do
73
- link = Riak::Link.new("/raw/bucket/key", "foo")
74
- expect(link.bucket).to eq("bucket")
75
- expect(link.key).to eq("key")
76
- end
77
-
78
- it "constructs from bucket, key and tag" do
79
- link = Riak::Link.new("bucket", "key", "tag")
80
- expect(link.bucket).to eq("bucket")
81
- expect(link.key).to eq("key")
82
- expect(link.tag).to eq("tag")
83
- expect(link.url).to eq("/riak/bucket/key")
84
- end
85
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::ListBuckets do
4
- before :each do
5
- @client = Riak::Client.new
6
- @backend = double 'backend'
7
- @fake_pool = double 'connection pool'
8
- allow(@fake_pool).to receive(:take).and_yield(@backend)
9
-
10
- @expect_list = expect(@backend).to receive(:list_buckets)
11
-
12
- @client.instance_variable_set :@protobuffs_pool, @fake_pool
13
- end
14
-
15
- describe "non-streaming" do
16
- it 'calls the backend without a block' do
17
- @expect_list.with({}).and_return(%w{a b c d})
18
-
19
- @client.list_buckets
20
- end
21
- end
22
-
23
- describe "streaming" do
24
- it 'calls the backend with a block' do
25
- @expect_list.
26
- and_yield(%w{abc abd abe}).
27
- and_yield(%w{bbb ccc ddd})
28
-
29
- @yielded = []
30
-
31
- @client.list_buckets do |bucket|
32
- @yielded << bucket
33
- end
34
-
35
- @yielded.each do |b|
36
- expect(b).to be_a Riak::Bucket
37
- end
38
- expect(@yielded.map(&:name)).to eq(%w{abc abd abe bbb ccc ddd})
39
- end
40
- end
41
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::MapReduce::FilterBuilder do
4
- subject { Riak::MapReduce::FilterBuilder.new }
5
- it "evaluates the passed block on initialization" do
6
- expect(subject.class.new do
7
- matches "foo"
8
- end.to_a).to eq([[:matches, "foo"]])
9
- end
10
-
11
- it "adds filters to the list" do
12
- subject.to_lower
13
- subject.similar_to("ripple", 3)
14
- expect(subject.to_a).to eq([[:to_lower], [:similar_to, "ripple", 3]])
15
- end
16
-
17
- it "adds a logical operation with a block" do
18
- subject.OR do
19
- starts_with "foo"
20
- ends_with "bar"
21
- end
22
- expect(subject.to_a).to eq([[:or, [[:starts_with, "foo"], [:ends_with, "bar"]]]])
23
- end
24
-
25
- it "raises an error on a filter arity mismatch" do
26
- expect { subject.less_than }.to raise_error(ArgumentError)
27
- end
28
-
29
- it "raises an error when a block is not given to a logical operation" do
30
- expect { subject._or }.to raise_error(ArgumentError)
31
- end
32
- end
@@ -1,142 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::MapReduce::Phase do
4
- before :each do
5
- @js_fun = "function(v,_,_){ return v['values'][0]['data']; }"
6
- @erl_fun = "fun(Obj, _KeyData, _Arg) -> [{riak_object:key(Obj), riak_object:get_value(Obj)}] end."
7
- end
8
-
9
- it "initializes with a type and a function" do
10
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun, :language => "javascript")
11
- expect(phase.type).to eq(:map)
12
- expect(phase.function).to eq(@js_fun)
13
- expect(phase.language).to eq("javascript")
14
- end
15
-
16
- it "initializes with a type and an MF" do
17
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => %w(module function), :language => "erlang")
18
- expect(phase.type).to eq(:map)
19
- expect(phase.function).to eq(%w(module function))
20
- expect(phase.language).to eq("erlang")
21
- end
22
-
23
- it "initializes with a type and a bucket/key" do
24
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "funs", :key => "awesome_map"}, :language => "javascript")
25
- expect(phase.type).to eq(:map)
26
- expect(phase.function).to eq({:bucket => "funs", :key => "awesome_map"})
27
- expect(phase.language).to eq("javascript")
28
- end
29
-
30
- it "assumes the language is erlang when the function is an array" do
31
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => %w(module function))
32
- expect(phase.language).to eq("erlang")
33
- end
34
-
35
- it "assumes the language is javascript when the function is a string and starts with function" do
36
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun)
37
- expect(phase.language).to eq("javascript")
38
- end
39
-
40
- it "assumes the language is erlang when the function is a string and starts with anon fun" do
41
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => @erl_fun)
42
- expect(phase.language).to eq("erlang")
43
- end
44
-
45
- it "assumes the language is javascript when the function is a hash" do
46
- phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "jobs", :key => "awesome_map"})
47
- expect(phase.language).to eq("javascript")
48
- end
49
-
50
- it "accepts a WalkSpec for the function when a link phase" do
51
- phase = Riak::MapReduce::Phase.new(:type => :link, :function => Riak::WalkSpec.new({}))
52
- expect(phase.function).to be_kind_of(Riak::WalkSpec)
53
- end
54
-
55
- it "raises an error if a WalkSpec is given for a phase type other than :link" do
56
- expect { Riak::MapReduce::Phase.new(:type => :map, :function => Riak::WalkSpec.new({})) }.to raise_error(ArgumentError)
57
- end
58
-
59
- describe "converting to JSON for the job" do
60
- before :each do
61
- @phase = Riak::MapReduce::Phase.new(:type => :map, :function => "")
62
- end
63
-
64
- [:map, :reduce].each do |type|
65
- describe "when a #{type} phase" do
66
- before :each do
67
- @phase.type = type
68
- end
69
-
70
- it "is an object with a single key of '#{type}'" do
71
- expect(@phase.to_json).to match(/^\{"#{type}":/)
72
- end
73
-
74
- it "includes the language" do
75
- expect(@phase.to_json).to match(/"language":/)
76
- end
77
-
78
- it "includes the keep value" do
79
- expect(@phase.to_json).to match(/"keep":false/)
80
- @phase.keep = true
81
- expect(@phase.to_json).to match(/"keep":true/)
82
- end
83
-
84
- it "includes the function source when the function is a source string" do
85
- @phase.function = "function(v,_,_){ return v; }"
86
- expect(@phase.to_json).to include(@phase.function)
87
- expect(@phase.to_json).to match(/"source":/)
88
- end
89
-
90
- it "includes the function name when the function is not a lambda" do
91
- @phase.function = "Riak.mapValues"
92
- expect(@phase.to_json).to include('"name":"Riak.mapValues"')
93
- expect(@phase.to_json).not_to include('"source"')
94
- end
95
-
96
- it "includes the bucket and key when referring to a stored function" do
97
- @phase.function = {:bucket => "design", :key => "wordcount_map"}
98
- expect(@phase.to_json).to include('"bucket":"design"')
99
- expect(@phase.to_json).to include('"key":"wordcount_map"')
100
- end
101
-
102
- it "includes the module and function when invoking an Erlang function" do
103
- @phase.function = %w(riak_mapreduce mapreduce_fun)
104
- expect(@phase.to_json).to include('"module":"riak_mapreduce"')
105
- expect(@phase.to_json).to include('"function":"mapreduce_fun"')
106
- end
107
- end
108
- end
109
-
110
- describe "when a link phase" do
111
- before :each do
112
- @phase.type = :link
113
- @phase.function = {}
114
- end
115
-
116
- it "is an object of a single key 'link'" do
117
- expect(@phase.to_json).to match(/^\{"link":/)
118
- end
119
-
120
- it "includes the bucket" do
121
- expect(@phase.to_json).to match(/"bucket":"_"/)
122
- @phase.function[:bucket] = "foo"
123
- expect(@phase.to_json).to match(/"bucket":"foo"/)
124
- end
125
-
126
- it "includes the tag" do
127
- expect(@phase.to_json).to match(/"tag":"_"/)
128
- @phase.function[:tag] = "parent"
129
- expect(@phase.to_json).to match(/"tag":"parent"/)
130
- end
131
-
132
- it "includes the keep value" do
133
- expect(@phase.to_json).to match(/"keep":false/)
134
- @phase.keep = true
135
- expect(@phase.to_json).to match(/"keep":true/)
136
- @phase.keep = false
137
- @phase.function[:keep] = true
138
- expect(@phase.to_json).to match(/"keep":true/)
139
- end
140
- end
141
- end
142
- end