tarantool 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +14 -0
- data/Gemfile.lock +55 -0
- data/LICENSE +24 -0
- data/README.md +116 -0
- data/Rakefile +131 -0
- data/examples/em_simple.rb +21 -0
- data/examples/record.rb +56 -0
- data/examples/synchrony_simple.rb +13 -0
- data/lib/em/protocols/fixed_header_and_body.rb +67 -0
- data/lib/tarantool.rb +44 -0
- data/lib/tarantool/connection.rb +54 -0
- data/lib/tarantool/exceptions.rb +11 -0
- data/lib/tarantool/record.rb +316 -0
- data/lib/tarantool/request.rb +94 -0
- data/lib/tarantool/requests.rb +19 -0
- data/lib/tarantool/requests/call.rb +20 -0
- data/lib/tarantool/requests/delete.rb +18 -0
- data/lib/tarantool/requests/insert.rb +19 -0
- data/lib/tarantool/requests/ping.rb +16 -0
- data/lib/tarantool/requests/select.rb +22 -0
- data/lib/tarantool/requests/update.rb +35 -0
- data/lib/tarantool/response.rb +58 -0
- data/lib/tarantool/serializers.rb +9 -0
- data/lib/tarantool/serializers/bson.rb +15 -0
- data/lib/tarantool/serializers/integer.rb +14 -0
- data/lib/tarantool/serializers/string.rb +14 -0
- data/lib/tarantool/space.rb +39 -0
- data/lib/tarantool/synchrony.rb +13 -0
- data/spec/helpers/let.rb +11 -0
- data/spec/helpers/truncate.rb +12 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/tarantool.cfg +32 -0
- data/spec/tarantool/record_spec.rb +247 -0
- data/spec/tarantool/request_spec.rb +114 -0
- data/tarantool.gemspec +70 -0
- metadata +126 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tarantool::Request do
|
5
|
+
before do
|
6
|
+
Tarantool.singleton_space.space_no = 1
|
7
|
+
end
|
8
|
+
describe "pack method" do
|
9
|
+
describe "for field" do
|
10
|
+
it "should pack integer as 32 bit integer" do
|
11
|
+
size, value = Tarantool::Request.pack_field(5).unpack('wL')
|
12
|
+
value.must_equal 5
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should pack string as arbitrary binary string" do
|
16
|
+
size, value = Tarantool::Request.pack_field("привет").unpack('wa*')
|
17
|
+
value.force_encoding('utf-8').must_equal 'привет'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise ArgumentError for other types" do
|
21
|
+
lambda { Tarantool::Request.pack_field(:foo) }.must_raise Tarantool::ArgumentError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "for tuple" do
|
26
|
+
it "should pack to fields with fields count" do
|
27
|
+
field1, field2 = 1, "привет"
|
28
|
+
expect = [2, 4, field1, field2.bytesize, field2].pack('LwLwa*')
|
29
|
+
Tarantool::Request.pack_tuple(field1, field2).must_equal expect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "instance" do
|
35
|
+
let(:request) { Tarantool::Requests::Insert.new Tarantool.space }
|
36
|
+
|
37
|
+
it "should make packet with right request type, body size and next request id + body" do
|
38
|
+
body = 'hi'
|
39
|
+
expect = [Tarantool::Requests::REQUEST_TYPES[:insert], body.bytesize, request.request_id].pack('LLL') + body
|
40
|
+
request.make_packet(body).must_equal expect
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "requests" do
|
46
|
+
include Helpers::Truncate
|
47
|
+
describe "insert and select" do
|
48
|
+
it "should insert tuple and return it" do
|
49
|
+
Tarantool.insert 100, 'привет', return_tuple: true
|
50
|
+
res = Tarantool.select 100
|
51
|
+
int, string = res.tuple
|
52
|
+
int.to_i.must_equal 100
|
53
|
+
string.to_s.must_equal 'привет'
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "with equal ids" do
|
57
|
+
it "should raise error" do
|
58
|
+
Tarantool.insert 100, 'lala'
|
59
|
+
lambda { Tarantool.insert 100, 'yo' }.must_raise(Tarantool::BadReturnCode)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "select" do
|
65
|
+
it "should select multiple tuples" do
|
66
|
+
Tarantool.insert 100, 'привет'
|
67
|
+
Tarantool.insert 101, 'hi'
|
68
|
+
res = Tarantool.select 100, 101
|
69
|
+
res.tuples.map { |v| v.last.to_s }.must_equal ['привет', 'hi']
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "call" do
|
74
|
+
it "should call lua proc" do
|
75
|
+
res = Tarantool.call proc_name: 'box.pack', args: ['i', '100'], return_tuple: true
|
76
|
+
res.tuple[0].to_i.must_equal 100
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return batches via select_range" do
|
80
|
+
Tarantool.insert 100, 'привет'
|
81
|
+
Tarantool.insert 101, 'hi'
|
82
|
+
res = Tarantool.call proc_name: 'box.select_range', args: ['1', '0', '100'], return_tuple: true
|
83
|
+
res.tuples.size.must_equal 2
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "update" do
|
88
|
+
it "should update tuple" do
|
89
|
+
Tarantool.insert 100, 'привет'
|
90
|
+
Tarantool.update 100, ops: [[1, :set, 'yo!']]
|
91
|
+
res = Tarantool.select 100
|
92
|
+
int, string = res.tuple
|
93
|
+
string.to_s.must_equal 'yo!'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "delete" do
|
98
|
+
it "should delete record" do
|
99
|
+
inserted = Tarantool.insert 100, 'привет', return_tuple: true
|
100
|
+
Tarantool.delete inserted.tuple[0], return_tuple: true
|
101
|
+
res = Tarantool.select 100
|
102
|
+
res.tuple.must_be_nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "ping" do
|
107
|
+
it "should ping without exceptions" do
|
108
|
+
res = Tarantool.ping
|
109
|
+
res.must_be_kind_of Numeric
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
data/tarantool.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
|
+
s.rubygems_version = '1.3.5'
|
5
|
+
|
6
|
+
s.name = 'tarantool'
|
7
|
+
s.version = '0.1'
|
8
|
+
s.date = '2011-12-05'
|
9
|
+
s.rubyforge_project = 'tarantool'
|
10
|
+
|
11
|
+
s.summary = "Tarantool KV-storage client."
|
12
|
+
s.description = "Tarantool KV-storage client."
|
13
|
+
|
14
|
+
s.authors = ["Andrew Rudenko"]
|
15
|
+
s.email = 'ceo@prepor.ru'
|
16
|
+
s.homepage = 'http://github.com/mailru/tarantool-ruby'
|
17
|
+
|
18
|
+
s.require_paths = %w[lib]
|
19
|
+
|
20
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
22
|
+
|
23
|
+
s.add_dependency('eventmachine', [">= 1.0.0.beta.4", "< 2.0.0"])
|
24
|
+
s.add_dependency('activemodel', [">= 3.1", "< 4.0"])
|
25
|
+
s.add_dependency('em-synchrony', [">= 1.0.0", "< 2.0"])
|
26
|
+
|
27
|
+
# = MANIFEST =
|
28
|
+
s.files = %w[
|
29
|
+
Gemfile
|
30
|
+
Gemfile.lock
|
31
|
+
LICENSE
|
32
|
+
README.md
|
33
|
+
Rakefile
|
34
|
+
examples/em_simple.rb
|
35
|
+
examples/record.rb
|
36
|
+
examples/synchrony_simple.rb
|
37
|
+
lib/em/protocols/fixed_header_and_body.rb
|
38
|
+
lib/tarantool.rb
|
39
|
+
lib/tarantool/connection.rb
|
40
|
+
lib/tarantool/exceptions.rb
|
41
|
+
lib/tarantool/record.rb
|
42
|
+
lib/tarantool/request.rb
|
43
|
+
lib/tarantool/requests.rb
|
44
|
+
lib/tarantool/requests/call.rb
|
45
|
+
lib/tarantool/requests/delete.rb
|
46
|
+
lib/tarantool/requests/insert.rb
|
47
|
+
lib/tarantool/requests/ping.rb
|
48
|
+
lib/tarantool/requests/select.rb
|
49
|
+
lib/tarantool/requests/update.rb
|
50
|
+
lib/tarantool/response.rb
|
51
|
+
lib/tarantool/serializers.rb
|
52
|
+
lib/tarantool/serializers/bson.rb
|
53
|
+
lib/tarantool/serializers/integer.rb
|
54
|
+
lib/tarantool/serializers/string.rb
|
55
|
+
lib/tarantool/space.rb
|
56
|
+
lib/tarantool/synchrony.rb
|
57
|
+
spec/helpers/let.rb
|
58
|
+
spec/helpers/truncate.rb
|
59
|
+
spec/spec_helper.rb
|
60
|
+
spec/tarantool.cfg
|
61
|
+
spec/tarantool/record_spec.rb
|
62
|
+
spec/tarantool/request_spec.rb
|
63
|
+
tarantool.gemspec
|
64
|
+
]
|
65
|
+
# = MANIFEST =
|
66
|
+
|
67
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
68
|
+
## matches what you actually use.
|
69
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarantool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Rudenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: eventmachine
|
16
|
+
requirement: &70160133311300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0.beta.4
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *70160133311300
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activemodel
|
30
|
+
requirement: &70160133310540 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '3.1'
|
36
|
+
- - <
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '4.0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: *70160133310540
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: em-synchrony
|
44
|
+
requirement: &70160133309780 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.0.0
|
50
|
+
- - <
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
53
|
+
type: :runtime
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: *70160133309780
|
56
|
+
description: Tarantool KV-storage client.
|
57
|
+
email: ceo@prepor.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
- LICENSE
|
63
|
+
files:
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- examples/em_simple.rb
|
70
|
+
- examples/record.rb
|
71
|
+
- examples/synchrony_simple.rb
|
72
|
+
- lib/em/protocols/fixed_header_and_body.rb
|
73
|
+
- lib/tarantool.rb
|
74
|
+
- lib/tarantool/connection.rb
|
75
|
+
- lib/tarantool/exceptions.rb
|
76
|
+
- lib/tarantool/record.rb
|
77
|
+
- lib/tarantool/request.rb
|
78
|
+
- lib/tarantool/requests.rb
|
79
|
+
- lib/tarantool/requests/call.rb
|
80
|
+
- lib/tarantool/requests/delete.rb
|
81
|
+
- lib/tarantool/requests/insert.rb
|
82
|
+
- lib/tarantool/requests/ping.rb
|
83
|
+
- lib/tarantool/requests/select.rb
|
84
|
+
- lib/tarantool/requests/update.rb
|
85
|
+
- lib/tarantool/response.rb
|
86
|
+
- lib/tarantool/serializers.rb
|
87
|
+
- lib/tarantool/serializers/bson.rb
|
88
|
+
- lib/tarantool/serializers/integer.rb
|
89
|
+
- lib/tarantool/serializers/string.rb
|
90
|
+
- lib/tarantool/space.rb
|
91
|
+
- lib/tarantool/synchrony.rb
|
92
|
+
- spec/helpers/let.rb
|
93
|
+
- spec/helpers/truncate.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- spec/tarantool.cfg
|
96
|
+
- spec/tarantool/record_spec.rb
|
97
|
+
- spec/tarantool/request_spec.rb
|
98
|
+
- tarantool.gemspec
|
99
|
+
homepage: http://github.com/mailru/tarantool-ruby
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project: tarantool
|
120
|
+
rubygems_version: 1.8.10
|
121
|
+
signing_key:
|
122
|
+
specification_version: 2
|
123
|
+
summary: Tarantool KV-storage client.
|
124
|
+
test_files:
|
125
|
+
- spec/tarantool/record_spec.rb
|
126
|
+
- spec/tarantool/request_spec.rb
|