riakpb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +30 -0
- data/README.rdoc +156 -0
- data/Rakefile +43 -0
- data/lib/riak/bucket.rb +177 -0
- data/lib/riak/client/rpc.rb +127 -0
- data/lib/riak/client.rb +227 -0
- data/lib/riak/client_pb.rb +372 -0
- data/lib/riak/failed_exchange.rb +21 -0
- data/lib/riak/failed_request.rb +22 -0
- data/lib/riak/i18n.rb +7 -0
- data/lib/riak/key.rb +284 -0
- data/lib/riak/locale/en.yml +37 -0
- data/lib/riak/riak_content.rb +219 -0
- data/lib/riak/sibling_error.rb +16 -0
- data/lib/riak/util/decode.rb +37 -0
- data/lib/riak/util/encode.rb +31 -0
- data/lib/riak/util/message_code.rb +73 -0
- data/lib/riak/util/translation.rb +16 -0
- data/lib/riak.rb +34 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/riak/bucket_spec.rb +118 -0
- data/spec/riak/client_spec.rb +212 -0
- data/spec/riak/key_spec.rb +54 -0
- data/spec/riak/map_reduce_spec.rb +4 -0
- data/spec/riak/riak_content_spec.rb +88 -0
- data/spec/riak/rpc_spec.rb +17 -0
- data/spec/spec_helper.rb +25 -0
- metadata +121 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
module Riak
|
2
|
+
module Util
|
3
|
+
module MessageCode
|
4
|
+
ERROR_RESPONSE = 0
|
5
|
+
|
6
|
+
PING_REQUEST = 1
|
7
|
+
PING_RESPONSE = 2
|
8
|
+
|
9
|
+
GET_CLIENT_ID_REQUEST = 3
|
10
|
+
GET_CLIENT_ID_RESPONSE = 4
|
11
|
+
|
12
|
+
SET_CLIENT_ID_REQUEST = 5
|
13
|
+
SET_CLIENT_ID_RESPONSE = 6
|
14
|
+
|
15
|
+
GET_SERVER_INFO_REQUEST = 7
|
16
|
+
GET_SERVER_INFO_RESPONSE = 8
|
17
|
+
|
18
|
+
GET_REQUEST = 9
|
19
|
+
GET_RESPONSE = 10
|
20
|
+
|
21
|
+
PUT_REQUEST = 11
|
22
|
+
PUT_RESPONSE = 12
|
23
|
+
|
24
|
+
DEL_REQUEST = 13
|
25
|
+
DEL_RESPONSE = 14
|
26
|
+
|
27
|
+
LIST_BUCKETS_REQUEST = 15
|
28
|
+
LIST_BUCKETS_RESPONSE = 16
|
29
|
+
|
30
|
+
LIST_KEYS_REQUEST = 17
|
31
|
+
LIST_KEYS_RESPONSE = 18
|
32
|
+
|
33
|
+
GET_BUCKET_REQUEST = 19
|
34
|
+
GET_BUCKET_RESPONSE = 20
|
35
|
+
|
36
|
+
SET_BUCKET_REQUEST = 21
|
37
|
+
SET_BUCKET_RESPONSE = 22
|
38
|
+
|
39
|
+
MAP_REDUCE_REQUEST = 23
|
40
|
+
MAP_REDUCE_RESPONSE = 24
|
41
|
+
|
42
|
+
MC_RESPONSE_FOR = {
|
43
|
+
PING_REQUEST => PING_RESPONSE,
|
44
|
+
GET_CLIENT_ID_REQUEST => GET_CLIENT_ID_RESPONSE,
|
45
|
+
SET_CLIENT_ID_REQUEST => SET_CLIENT_ID_RESPONSE,
|
46
|
+
GET_SERVER_INFO_REQUEST => GET_SERVER_INFO_RESPONSE,
|
47
|
+
GET_REQUEST => GET_RESPONSE,
|
48
|
+
PUT_REQUEST => PUT_RESPONSE,
|
49
|
+
DEL_REQUEST => DEL_RESPONSE,
|
50
|
+
LIST_BUCKETS_REQUEST => LIST_BUCKETS_RESPONSE,
|
51
|
+
LIST_KEYS_REQUEST => LIST_KEYS_RESPONSE,
|
52
|
+
GET_BUCKET_REQUEST => GET_BUCKET_RESPONSE,
|
53
|
+
SET_BUCKET_REQUEST => SET_BUCKET_RESPONSE,
|
54
|
+
MAP_REDUCE_REQUEST => MAP_REDUCE_RESPONSE
|
55
|
+
}
|
56
|
+
|
57
|
+
RESPONSE_CLASS_FOR = {
|
58
|
+
PING_REQUEST => nil,
|
59
|
+
GET_CLIENT_ID_REQUEST => Riak::RpbGetClientIdResp,
|
60
|
+
SET_CLIENT_ID_REQUEST => nil,
|
61
|
+
GET_SERVER_INFO_REQUEST => Riak::RpbGetServerInfoResp,
|
62
|
+
GET_REQUEST => Riak::RpbGetResp,
|
63
|
+
PUT_REQUEST => Riak::RpbPutResp,
|
64
|
+
DEL_REQUEST => nil,
|
65
|
+
LIST_BUCKETS_REQUEST => Riak::RpbListBucketsResp,
|
66
|
+
LIST_KEYS_REQUEST => Riak::RpbListKeysResp,
|
67
|
+
GET_BUCKET_REQUEST => Riak::RpbGetBucketResp,
|
68
|
+
SET_BUCKET_REQUEST => nil,
|
69
|
+
MAP_REDUCE_REQUEST => Riak::RpbMapRedResp
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/riak.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'active_support/json'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'active_support/core_ext/hash'
|
7
|
+
require 'yaml'
|
8
|
+
require 'base64'
|
9
|
+
require 'riak/client_pb'
|
10
|
+
|
11
|
+
module Riak
|
12
|
+
VERSION = '0.1.0'
|
13
|
+
|
14
|
+
# Domain objects
|
15
|
+
autoload :I18n, 'riak/i18n'
|
16
|
+
autoload :Client, 'riak/client'
|
17
|
+
autoload :Key, 'riak/key'
|
18
|
+
autoload :RiakContent, 'riak/riak_content'
|
19
|
+
autoload :Bucket, 'riak/bucket'
|
20
|
+
autoload :MapReduce, 'riak/map_reduce'
|
21
|
+
|
22
|
+
# Exceptions
|
23
|
+
autoload :FailedRequest, "riak/failed_request"
|
24
|
+
autoload :FailedExchange, "riak/failed_exchange"
|
25
|
+
autoload :SiblingError, "riak/sibling_error"
|
26
|
+
|
27
|
+
# Mixins
|
28
|
+
module Util
|
29
|
+
autoload :Translation, 'riak/util/translation'
|
30
|
+
autoload :MessageCode, 'riak/util/message_code'
|
31
|
+
autoload :Encode, 'riak/util/encode'
|
32
|
+
autoload :Decode, 'riak/util/decode'
|
33
|
+
end
|
34
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/riak.rb'}"
|
9
|
+
puts "Loading riak gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
15
|
+
|
16
|
+
describe Riak::Bucket do
|
17
|
+
describe "when directly initializing" do
|
18
|
+
before :each do
|
19
|
+
@client = Riak::Client.new
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should default with the client and name, and empty n_val or allow_mult" do
|
23
|
+
bucket = Riak::Bucket.new(@client, "test")
|
24
|
+
bucket.client.should == @client
|
25
|
+
bucket.name.should == "test"
|
26
|
+
bucket.n_val.should == nil
|
27
|
+
bucket.allow_mult.should == nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should correctly accept an n_val" do
|
31
|
+
bucket = Riak::Bucket.new(@client, "test")
|
32
|
+
bucket.n_val = 5
|
33
|
+
bucket.n_val.should be_kind_of(Fixnum)
|
34
|
+
lambda { bucket.n_val="5" }.should raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should correctly accept an allow_mult" do
|
38
|
+
bucket = Riak::Bucket.new(@client, "test")
|
39
|
+
bucket.allow_mult = true
|
40
|
+
bucket.allow_mult.should be_kind_of(TrueClass)
|
41
|
+
bucket.allow_mult = false
|
42
|
+
bucket.allow_mult.should be_kind_of(FalseClass)
|
43
|
+
lambda { bucket.allow_mult="no" }.should raise_error(ArgumentError)
|
44
|
+
end
|
45
|
+
end # describe "when directly initializing"
|
46
|
+
|
47
|
+
describe "when initialized from the Client" do
|
48
|
+
before :each do
|
49
|
+
@client = Riak::Client.new
|
50
|
+
@client.rpc.stub!(:request).and_return(nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have set the properties" do
|
54
|
+
@client.rpc.stub!(:request).with(
|
55
|
+
Riak::Util::MessageCode::GET_BUCKET_REQUEST,
|
56
|
+
Riak::RpbGetBucketReq.new(:bucket => "goog")
|
57
|
+
).and_return(
|
58
|
+
Riak::RpbGetBucketResp.new(
|
59
|
+
{ :props => {
|
60
|
+
:allow_mult => false,
|
61
|
+
:n_val => 3
|
62
|
+
}
|
63
|
+
}
|
64
|
+
))
|
65
|
+
bucket = @client["goog"]
|
66
|
+
bucket.should be_kind_of(Riak::Bucket)
|
67
|
+
bucket.client.should == @client
|
68
|
+
bucket.name.should == "goog"
|
69
|
+
bucket.n_val.should == 3
|
70
|
+
bucket.allow_mult.should == false
|
71
|
+
end
|
72
|
+
end # describe "when initialized from the Client"
|
73
|
+
|
74
|
+
describe "key retrieval" do
|
75
|
+
before :each do
|
76
|
+
@client = Riak::Client.new
|
77
|
+
@client.rpc.stub!(:request).with(
|
78
|
+
Riak::Util::MessageCode::GET_BUCKET_REQUEST,
|
79
|
+
Riak::RpbGetBucketReq.new(:bucket => "goog")
|
80
|
+
).and_return(
|
81
|
+
Riak::RpbGetBucketResp.new(
|
82
|
+
{ :props => {
|
83
|
+
:allow_mult => false,
|
84
|
+
:n_val => 3
|
85
|
+
}
|
86
|
+
}
|
87
|
+
))
|
88
|
+
@bucket = @client["goog"]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should list the keys within the bucket" do
|
92
|
+
@client.rpc.stub!(:request).with(
|
93
|
+
Riak::Util::MessageCode::LIST_KEYS_REQUEST,
|
94
|
+
Riak::RpbListKeysReq.new(:bucket => "goog")
|
95
|
+
).and_return(
|
96
|
+
Riak::RpbListKeysResp.new(
|
97
|
+
{ :keys => ["2010-04-12", "2008-01-10", "2006-06-06"],
|
98
|
+
:done => true
|
99
|
+
}
|
100
|
+
))
|
101
|
+
@bucket.keys.should be_kind_of(Protobuf::Field::FieldArray)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return a key, when requested" do
|
105
|
+
@client.rpc.stub!(:request).with(
|
106
|
+
Riak::Util::MessageCode::GET_REQUEST,
|
107
|
+
Riak::RpbGetReq.new(:bucket => "goog", :key => "2010-04-12", :r => nil)
|
108
|
+
).and_return(
|
109
|
+
Riak::RpbGetResp.new(
|
110
|
+
{ :content => [],
|
111
|
+
:vclock => ""
|
112
|
+
}
|
113
|
+
))
|
114
|
+
@bucket["2010-04-12"].should be_kind_of(Riak::Key)
|
115
|
+
end
|
116
|
+
end # describe "key retrieval"
|
117
|
+
|
118
|
+
end # Riak::Client
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
15
|
+
|
16
|
+
describe Riak::Client do
|
17
|
+
describe "when initializing" do
|
18
|
+
it "should default to the local interface on port 8087" do
|
19
|
+
client = Riak::Client.new
|
20
|
+
client.host.should == "127.0.0.1"
|
21
|
+
client.port.should == 8087
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept a host" do
|
25
|
+
client = Riak::Client.new :host => "riak.basho.com"
|
26
|
+
client.host.should == "riak.basho.com"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should accept a port" do
|
30
|
+
client = Riak::Client.new :port => 9000
|
31
|
+
client.port.should == 9000
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "reconfiguring" do
|
36
|
+
before :each do
|
37
|
+
@client = Riak::Client.new
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "setting the host" do
|
41
|
+
it "should allow setting the host" do
|
42
|
+
@client.should respond_to(:host=)
|
43
|
+
@client.host = "riak.basho.com"
|
44
|
+
@client.host.should == "riak.basho.com"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should require the host to be an IP or hostname" do
|
48
|
+
[238472384972, "", "riak.basho-.com"].each do |invalid|
|
49
|
+
lambda { @client.host = invalid }.should raise_error(ArgumentError)
|
50
|
+
end
|
51
|
+
["127.0.0.1", "10.0.100.5", "localhost", "otherhost.local", "riak.basho.com"].each do |valid|
|
52
|
+
lambda { @client.host = valid }.should_not raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end # describe "setting the host"
|
56
|
+
|
57
|
+
describe "setting the port" do
|
58
|
+
it "should allow setting the port" do
|
59
|
+
@client.should respond_to(:port=)
|
60
|
+
@client.port = 9000
|
61
|
+
@client.port.should == 9000
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should require the port to be a valid number" do
|
65
|
+
[-1,65536,"foo"].each do |invalid|
|
66
|
+
lambda { @client.port = invalid }.should raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
[0,1,65535,8098].each do |valid|
|
69
|
+
lambda { @client.port = valid }.should_not raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end # describe "setting the port"
|
73
|
+
|
74
|
+
describe "setting the client id" do
|
75
|
+
it "should accept a string unmodified" do
|
76
|
+
@client.client_id = "foo"
|
77
|
+
@client.client_id.should == "foo"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should base64-encode an integer" do
|
81
|
+
@client.client_id = 1
|
82
|
+
@client.client_id.should == "AAAAAQ=="
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should reject an integer equal to the maximum client id" do
|
86
|
+
lambda { @client.client_id = Riak::Client::MAX_CLIENT_ID }.should raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should reject an integer larger than the maximum client id" do
|
90
|
+
lambda { @client.client_id = Riak::Client::MAX_CLIENT_ID + 1 }.should raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
end # describe "setting the client id"
|
93
|
+
end # describe "reconfiguring"
|
94
|
+
|
95
|
+
describe "sending and receiving protocol buffers" do
|
96
|
+
before :each do
|
97
|
+
@client = Riak::Client.new
|
98
|
+
@client.rpc.stub!(:status).and_return(true)
|
99
|
+
@client.rpc.stub!(:request).and_return(nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "basic communication with riak node" do
|
103
|
+
it "should send a ping request and return true" do
|
104
|
+
@client.rpc.stub!(:request).with(
|
105
|
+
Riak::Util::MessageCode::PING_REQUEST
|
106
|
+
).and_return('')
|
107
|
+
|
108
|
+
@client.ping?.should == true
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should request the connected riak node's server info and return a Hash" do
|
112
|
+
# test length or content? Need to look at what are considered acceptable values
|
113
|
+
@client.rpc.stub!(:request).with(
|
114
|
+
Riak::Util::MessageCode::GET_SERVER_INFO_REQUEST
|
115
|
+
).and_return(Riak::RpbGetServerInfoResp.new(
|
116
|
+
{ :node => "riak@127.0.0.1",
|
117
|
+
:server_version => "0.10.1"
|
118
|
+
}
|
119
|
+
))
|
120
|
+
|
121
|
+
@client.info[:node].should be_kind_of(String)
|
122
|
+
@client.info[:server_version].should be_kind_of(String)
|
123
|
+
end
|
124
|
+
end # describe "basic communication with riak node"
|
125
|
+
|
126
|
+
describe "bucket operations: retrieval (get) and send (set)" do
|
127
|
+
|
128
|
+
describe "bucket retrieval (get)" do
|
129
|
+
it "should send a request to list available bucket names and return a Protobuf::Field::FieldArray" do
|
130
|
+
@client.rpc.stub!(:request).with(
|
131
|
+
Riak::Util::MessageCode::LIST_BUCKETS_REQUEST
|
132
|
+
).and_return(
|
133
|
+
Riak::RpbListBucketsResp.new(
|
134
|
+
{ :buckets => ["goog"] }
|
135
|
+
))
|
136
|
+
|
137
|
+
@client.buckets.should be_kind_of(Protobuf::Field::FieldArray)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should send a request with the bucket name and return a Riak::Bucket" do
|
141
|
+
@client.rpc.stub!(:request).with(
|
142
|
+
Riak::Util::MessageCode::GET_BUCKET_REQUEST,
|
143
|
+
Riak::RpbGetBucketReq.new(:bucket => "goog")
|
144
|
+
).and_return(
|
145
|
+
Riak::RpbGetBucketResp.new(
|
146
|
+
{ :props => {
|
147
|
+
:allow_mult => false,
|
148
|
+
:n_val => 3
|
149
|
+
}
|
150
|
+
}
|
151
|
+
))
|
152
|
+
|
153
|
+
@client.bucket("goog").should be_kind_of(Riak::Bucket)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should send a request to list keys within a bucket and return a Protobuf::Field::FieldArray" do
|
157
|
+
@client.rpc.stub!(:request).with(
|
158
|
+
Riak::Util::MessageCode::LIST_KEYS_REQUEST,
|
159
|
+
Riak::RpbListKeysReq.new(:bucket => "goog")
|
160
|
+
).and_return(
|
161
|
+
Riak::RpbListKeysResp.new(
|
162
|
+
{ :keys => ["2010-04-12", "2008-01-10", "2006-06-06"],
|
163
|
+
:done => true
|
164
|
+
}
|
165
|
+
))
|
166
|
+
@client.keys_in("goog").should be_kind_of(Protobuf::Field::FieldArray)
|
167
|
+
end
|
168
|
+
end # describe "bucket retrieval (get)"
|
169
|
+
|
170
|
+
describe "bucket sending (set)" do
|
171
|
+
end # describe "bucket sending (set)"
|
172
|
+
end # describe "bucket operations and retrieval"
|
173
|
+
|
174
|
+
describe "key operations: retrieval (get), send (put) and delete (del)" do
|
175
|
+
before :each do
|
176
|
+
@client.rpc.stub!(:request).with(
|
177
|
+
Riak::Util::MessageCode::GET_REQUEST,
|
178
|
+
Riak::RpbGetReq.new(:bucket => "goog", :key => "2010-04-12", :r => nil)
|
179
|
+
).and_return(
|
180
|
+
Riak::RpbGetResp.new(
|
181
|
+
{ :content => [],
|
182
|
+
:vclock => ""
|
183
|
+
}
|
184
|
+
))
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should send a request for a bucket/key pair and return a Riak::RpbGetResp" do
|
188
|
+
@client.get_request("goog", "2010-04-12").should be_kind_of(Riak::RpbGetResp)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should have a vclock attribute within Riak::RpbGetResp of that is a String" do
|
192
|
+
@client.get_request("goog", "2010-04-12").vclock.should be_kind_of(String)
|
193
|
+
end
|
194
|
+
end # describe "key operations and retrieval"
|
195
|
+
|
196
|
+
describe "key operations and retrieval" do
|
197
|
+
before :each do
|
198
|
+
@client.rpc.stub!(:request).with(
|
199
|
+
Riak::Util::MessageCode::GET_REQUEST,
|
200
|
+
Riak::RpbGetReq.new(:bucket => "goog", :key => "2010-04-12", :r => nil)
|
201
|
+
).and_return(
|
202
|
+
Riak::RpbGetResp.new(
|
203
|
+
{ :content => [],
|
204
|
+
:vclock => ""
|
205
|
+
}
|
206
|
+
))
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
end # describe "key operations and retrieval"
|
211
|
+
end # describe "basic communication with riak node"
|
212
|
+
end # Riak::Client
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Riak::Key do
|
4
|
+
describe "when directly initializing" do
|
5
|
+
before :each do
|
6
|
+
@client = Riak::Client.new
|
7
|
+
@client.rpc.stub!(:request).with(
|
8
|
+
Riak::Util::MessageCode::GET_BUCKET_REQUEST,
|
9
|
+
Riak::RpbGetBucketReq.new(:bucket => "goog")
|
10
|
+
).and_return(
|
11
|
+
Riak::RpbGetBucketResp.new(
|
12
|
+
{ :props => {
|
13
|
+
:allow_mult => false,
|
14
|
+
:n_val => 3
|
15
|
+
}
|
16
|
+
}
|
17
|
+
))
|
18
|
+
@bucket = @client["goog"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should default with the bucket and name, and an empty vclock" do
|
22
|
+
key = Riak::Key.new(@bucket, "test")
|
23
|
+
key.bucket.should == @bucket
|
24
|
+
key.name.should == "test"
|
25
|
+
key.vclock.should == nil
|
26
|
+
key.content.should be_kind_of(Riak::RiakContent)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should serialize into a Key Protocol Buffer (RpbPutReq)" do
|
30
|
+
@client.rpc.stub!(:request).with(
|
31
|
+
Riak::Util::MessageCode::GET_REQUEST,
|
32
|
+
Riak::RpbGetReq.new(:bucket => "goog", :key => "2010-04-12", :r => nil)
|
33
|
+
).and_return(
|
34
|
+
Riak::RpbGetResp.new(
|
35
|
+
{ :content => [Riak::RpbContent.new(:value => "Test")],
|
36
|
+
:vclock => "k\xCEa```\xCC`\xCA\x05R,\xACL\xF7^e0%2\xE6\xB12\xC4s\xE6\x1D\xE5\xCB\x02\x00"
|
37
|
+
}
|
38
|
+
))
|
39
|
+
key = @bucket["2010-04-12"] # Riak::Key.new(@bucket, "test")
|
40
|
+
pb_put = key.to_pb_put
|
41
|
+
pb_put.should be_kind_of(Riak::RpbPutReq)
|
42
|
+
pb_put.vclock.should == "k\xCEa```\xCC`\xCA\x05R,\xACL\xF7^e0%2\xE6\xB12\xC4s\xE6\x1D\xE5\xCB\x02\x00"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should serialize into a Link Protocol Buffer (RpbLink)" do
|
46
|
+
key = Riak::Key.new(@bucket, "test")
|
47
|
+
pb_link = key.to_pb_link
|
48
|
+
pb_link.should be_kind_of(Riak::RpbLink)
|
49
|
+
pb_link.bucket.should == "goog"
|
50
|
+
pb_link.key.should == "test"
|
51
|
+
end
|
52
|
+
end # describe "when directly initializing"
|
53
|
+
end # Riak::Key
|
54
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
15
|
+
|
16
|
+
describe Riak::RiakContent do
|
17
|
+
describe "when directly initializing" do
|
18
|
+
before :each do
|
19
|
+
@client = Riak::Client.new
|
20
|
+
@client.rpc.stub!(:request).with(
|
21
|
+
Riak::Util::MessageCode::GET_BUCKET_REQUEST,
|
22
|
+
Riak::RpbGetBucketReq.new(:bucket => "goog")
|
23
|
+
).and_return(
|
24
|
+
Riak::RpbGetBucketResp.new(
|
25
|
+
{ :props => {
|
26
|
+
:allow_mult => false,
|
27
|
+
:n_val => 3
|
28
|
+
}
|
29
|
+
}
|
30
|
+
))
|
31
|
+
@bucket = @client["goog"]
|
32
|
+
@key = Riak::Key.new(@bucket, "test")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should default with nil attributes and links/usermeta as instances of Set/Hash" do
|
36
|
+
rcontent = Riak::RiakContent.new(@key)
|
37
|
+
rcontent.key.should == @key
|
38
|
+
rcontent.value.should == nil
|
39
|
+
rcontent.content_type.should == nil
|
40
|
+
rcontent.charset.should == nil
|
41
|
+
rcontent.content_encoding.should == nil
|
42
|
+
rcontent.vtag.should == nil
|
43
|
+
rcontent.links.should be_kind_of(Hash)
|
44
|
+
rcontent.last_mod.should == nil
|
45
|
+
rcontent.last_mod_usecs.should == nil
|
46
|
+
rcontent.usermeta.should be_kind_of(Hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should allow you to set the Key, after initialization" do
|
50
|
+
rcontent = Riak::RiakContent.new(@key)
|
51
|
+
rcontent.key = @key
|
52
|
+
rcontent.key.should == @key
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should accept a Key as an argument to new, tying it back to an owner" do
|
56
|
+
rcontent = Riak::RiakContent.new(@key)
|
57
|
+
rcontent.key.should == @key
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should serialize into a corresponding Protocol Buffer (RpbContent)" do
|
61
|
+
rcontent = Riak::RiakContent.new(@key, :value => "Test")
|
62
|
+
rcontent.to_pb.should be_kind_of(Riak::RpbContent)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should load a Riak::RpbContent instance, returning a matching self, RiakContent" do
|
66
|
+
rcontent = Riak::RiakContent.new(@key)
|
67
|
+
rpb_content = Riak::RpbContent.new
|
68
|
+
rpb_content.value = "{\"Date\":\"2010-04-12\",\"Open\":567.35,\"High\":574.00,\"Low\":566.22,\"Close\":572.73,\"Volume\":2352400,\"Adj. Close\":572.73}"
|
69
|
+
rpb_content.content_type = "application/json"
|
70
|
+
rpb_content.vtag = "4DNB6Vt0zLl5VJ6P2xx9dc"
|
71
|
+
rpb_content.last_mod = 1274645855
|
72
|
+
rpb_content.last_mod_usecs = 968694
|
73
|
+
|
74
|
+
rcontent.load(rpb_content)
|
75
|
+
rcontent.key.should == @key
|
76
|
+
rcontent.value.should == {"Date" => "2010-04-12".to_date,"Open" => 567.35,"High" => 574.00,"Low" => 566.22,"Close" => 572.73,"Volume" => 2352400,"Adj. Close" => 572.73}
|
77
|
+
rcontent.content_type.should == "application/json"
|
78
|
+
rcontent.charset.should == nil
|
79
|
+
rcontent.content_encoding.should == nil
|
80
|
+
rcontent.vtag.should == "4DNB6Vt0zLl5VJ6P2xx9dc"
|
81
|
+
rcontent.links.should be_kind_of(Hash)
|
82
|
+
rcontent.last_mod.should == 1274645855
|
83
|
+
rcontent.last_mod_usecs.should == 968694
|
84
|
+
rcontent.usermeta.should be_kind_of(Hash)
|
85
|
+
end
|
86
|
+
|
87
|
+
end # describe "when directly initializing"
|
88
|
+
end # Riak::RiakContent
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require File.expand_path("../spec_helper", File.dirname(__FILE__))
|
15
|
+
|
16
|
+
describe Riak::Client::Rpc do
|
17
|
+
end # Riak::Client::Rpc
|