tarantool16 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Rakefile +3 -0
- data/lib/tarantool16.rb +1 -1
- data/lib/tarantool16/schema.rb +2 -2
- data/lib/tarantool16/version.rb +1 -1
- data/test/config.lua +33 -0
- data/test/helper.rb +134 -0
- data/test/test_dumb.rb +60 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4708dae76a87bea3c57671ad97120d4a60ecf5a6
|
4
|
+
data.tar.gz: 16d47be30532317b0e29380952baaf90e8c2817f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6577b96200a9cca5e14e5acba0203e14423e505a02219164716f49ec1160d1b1073c59170ac0227753dce09a040e1960524c2edee88efcc892ad68fd7ae731c3
|
7
|
+
data.tar.gz: d51b72462995c71820cc174c459b1fc2848b0a03cd2b74067bbf7d9d17e5b7a89b8e4cab4f02317cf98396e003fa9072975b93c85daebc754cac4e6449e83aad
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/lib/tarantool16.rb
CHANGED
data/lib/tarantool16/schema.rb
CHANGED
@@ -124,7 +124,7 @@ module Tarantool16
|
|
124
124
|
elsif index = @index_names[ino]
|
125
125
|
yield index.pos, index.map_key(key)
|
126
126
|
else
|
127
|
-
cb.call(Option.error(SchemaError, "Could not find index #{ino} for
|
127
|
+
cb.call(Option.error(SchemaError, "Could not find index #{ino} for fields #{Hash===key ? key.keys : key.inspect} in #{name_sid}"))
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -215,7 +215,7 @@ module Tarantool16
|
|
215
215
|
attr :name, :pos, :parts, :type, :part_names, :part_positions
|
216
216
|
ITERS = {
|
217
217
|
tree: (ITERATOR_EQ..ITERATOR_GT).freeze,
|
218
|
-
hash: [ITERATOR_ALL, ITERATOR_EQ
|
218
|
+
hash: [ITERATOR_ALL, ITERATOR_EQ].freeze,
|
219
219
|
bitset: [ITERATOR_ALL, ITERATOR_EQ, ITERATOR_BITS_ALL_SET,
|
220
220
|
ITERATOR_BITS_ANY_SET, ITERATOR_BITS_ALL_NOT_SET].freeze,
|
221
221
|
rtree: [ITERATOR_ALL, ITERATOR_EQ, ITERATOR_GT, ITERATOR_GE, ITERATOR_LT, ITERATOR_LE,
|
data/lib/tarantool16/version.rb
CHANGED
data/test/config.lua
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
local log = require 'log'
|
2
|
+
box.cfg{
|
3
|
+
listen = 33013,
|
4
|
+
wal_dir='.',
|
5
|
+
snap_dir='.',
|
6
|
+
}
|
7
|
+
if not box.space.test then
|
8
|
+
local s1 = box.schema.space.create('test', {id = 513, if_not_exists = true})
|
9
|
+
local ip = s1:create_index('primary', {type = 'hash', parts = {1, 'NUM'}, if_not_exists = true})
|
10
|
+
local iname = s1:create_index('name', {type = 'tree', parts = {2, 'STR'}, if_not_exists = true})
|
11
|
+
local irtree = s1:create_index('point', {type = 'rtree', unique=false, parts = {3, 'ARRAY'}, if_not_exists = true})
|
12
|
+
local ipname = s1:create_index('id_name', {type = 'tree', parts = {1, 'NUM', 2, 'STR'}})
|
13
|
+
end
|
14
|
+
|
15
|
+
function reseed()
|
16
|
+
local s1 = box.space.test
|
17
|
+
s1:truncate()
|
18
|
+
s1:insert{1, "hello", {1, 2}}
|
19
|
+
s1:insert{2, "world", {3, 4}}
|
20
|
+
end
|
21
|
+
|
22
|
+
pcall(function()
|
23
|
+
box.schema.user.grant('guest', 'read,write,execute', 'universe')
|
24
|
+
end)
|
25
|
+
|
26
|
+
if not box.schema.user.exists('tester') then
|
27
|
+
box.schema.user.create('tester', {password='testpass'})
|
28
|
+
box.schema.user.grant('tester', 'read,write,execute', 'universe')
|
29
|
+
end
|
30
|
+
|
31
|
+
local console = require 'console'
|
32
|
+
console.listen '0.0.0.0:33015'
|
33
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
$: << File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tarantool16'
|
5
|
+
require 'socket'
|
6
|
+
|
7
|
+
|
8
|
+
class Spawn
|
9
|
+
DIR = File.expand_path('..', __FILE__)
|
10
|
+
include FileUtils
|
11
|
+
Dir[File.join(DIR, "tarantool*.log")].each{|f| File.unlink(f)}
|
12
|
+
|
13
|
+
attr :port
|
14
|
+
def initialize(opts={})
|
15
|
+
@name = opts[:name] or raise "no name"
|
16
|
+
@port = opts[:port] || 16788
|
17
|
+
@admin_port = opts[:admin_port] || 16789
|
18
|
+
@binary = opts[:binary] || 'tarantool'
|
19
|
+
@instance = opts[:instance] || 'main'
|
20
|
+
@config = opts[:config] || 'config.lua'
|
21
|
+
end
|
22
|
+
|
23
|
+
def fjoin(*args)
|
24
|
+
File.join(*args.map(&:to_s))
|
25
|
+
end
|
26
|
+
|
27
|
+
def dir
|
28
|
+
fjoin(DIR, "run", ["tarantool", @instance].compact.join('_'))
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear
|
32
|
+
return unless @dir
|
33
|
+
stop
|
34
|
+
rm_rf(dir)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
return unless @pid
|
39
|
+
Process.kill('INT', @pid)
|
40
|
+
Process.wait2(@pid)
|
41
|
+
@pid = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare
|
45
|
+
return if @dir
|
46
|
+
clear
|
47
|
+
@dir = dir
|
48
|
+
mkdir_p(@dir)
|
49
|
+
conf = File.read(fjoin(DIR, @config))
|
50
|
+
conf.sub!(/listen = \d+/, "listen = #{@port}")
|
51
|
+
conf.sub!(/listen '0\.0\.0\.0:\d+'/, "listen '0.0.0.0:#{@admin_port}'")
|
52
|
+
if block_given?
|
53
|
+
yield conf
|
54
|
+
end
|
55
|
+
File.open(fjoin(@dir, 'config.lua'), 'w'){|f| f.write(conf)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def run
|
59
|
+
return if @pid
|
60
|
+
prepare
|
61
|
+
log = File.open(fjoin(DIR, "tarantool_#{@name}.log"), 'ab')
|
62
|
+
Dir.chdir(@dir) do
|
63
|
+
@pid = spawn(@binary, 'config.lua', {out: log, err: log})
|
64
|
+
end
|
65
|
+
sleep(0.25)
|
66
|
+
end
|
67
|
+
|
68
|
+
def reseed
|
69
|
+
run
|
70
|
+
s = TCPSocket.new '127.0.0.1', @admin_port
|
71
|
+
s.send("reseed()\n", 0)
|
72
|
+
sleep(0.004)
|
73
|
+
s.read_nonblock(1000)
|
74
|
+
s.close
|
75
|
+
end
|
76
|
+
|
77
|
+
CONF = {
|
78
|
+
main: {conf:{}}
|
79
|
+
}
|
80
|
+
|
81
|
+
AT_EXIT_CALLED = [false]
|
82
|
+
def self.inst(what=:main)
|
83
|
+
CONF[what][:inst] ||= new(CONF[what][:conf].merge(name: what.to_s))
|
84
|
+
CONF[what][:inst]
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.run(what=:main)
|
88
|
+
inst(what).run
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.reseed(what=:main)
|
92
|
+
inst(what).reseed
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.stop(what=:main)
|
96
|
+
if inst = CONF[what][:inst]
|
97
|
+
inst.stop
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.clear(what=:main)
|
102
|
+
if inst = CONF[what][:inst]
|
103
|
+
inst.clear
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
at_exit do
|
108
|
+
CONF.each_key{|name| clear(name)}
|
109
|
+
FileUtils.rm_rf(File.join(DIR, "run"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Object
|
114
|
+
def deep_freeze
|
115
|
+
case self
|
116
|
+
when String
|
117
|
+
freeze
|
118
|
+
when Array
|
119
|
+
each{|v| v.deep_freeze}
|
120
|
+
freeze
|
121
|
+
when Hash
|
122
|
+
each_value{|v| v.deep_freeze}
|
123
|
+
freeze
|
124
|
+
else
|
125
|
+
if respond_to?(:freeze)
|
126
|
+
freeze
|
127
|
+
else
|
128
|
+
self
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
require 'minitest/autorun'
|
data/test/test_dumb.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
describe 'DumbConnection' do
|
4
|
+
before { Spawn.reseed }
|
5
|
+
let(:db) { Tarantool16.new host: 'localhost:16788' }
|
6
|
+
let(:r1) { [1, 'hello', [1,2]].deep_freeze }
|
7
|
+
let(:r2) { [2, 'world', [3,4]].deep_freeze }
|
8
|
+
|
9
|
+
it "should select by pk" do
|
10
|
+
db.select(:test, 1).must_equal [r1]
|
11
|
+
db.select(513, 2).must_equal [r2]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should select by secondary index" do
|
15
|
+
db.select(:test, "hello", index: 1).must_equal [r1]
|
16
|
+
db.select(:test, "world", index: 'name').must_equal [r2]
|
17
|
+
db.select(:test, ["hello"], index: 1).must_equal [r1]
|
18
|
+
|
19
|
+
db.select(:test, [[1,2]], index: 2).must_equal [r1]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should iterate" do
|
23
|
+
db.select(:test, 1, iterator: :>=, index: 3).must_equal [r1, r2]
|
24
|
+
db.select(:test, 1, iterator: :>, index: 3).must_equal [r2]
|
25
|
+
db.select(:test, 1, iterator: :<, index: 3).must_equal []
|
26
|
+
db.select(:test, 1, iterator: :<=, index: 3).must_equal [r1]
|
27
|
+
db.select(:test, 2, iterator: :>=, index: 3).must_equal [r2]
|
28
|
+
db.select(:test, 2, iterator: :>, index: 3).must_equal []
|
29
|
+
db.select(:test, 2, iterator: :<, index: 3).must_equal [r1]
|
30
|
+
db.select(:test, 2, iterator: :<=, index: 3).must_equal [r2, r1]
|
31
|
+
|
32
|
+
db.select(:test, 'hello', index: 1, iterator: :>).must_equal [r2]
|
33
|
+
|
34
|
+
db.select(:test, [[0,0]], index: 2, iterator: "<->").must_equal [r1, r2]
|
35
|
+
db.select(:test, [[4,4]], index: 2, iterator: "<->").must_equal [r2, r1]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should insert" do
|
39
|
+
db.insert(:test, [4, "johny", [5,6]])
|
40
|
+
db.select(513, 4).must_equal [[4, "johny", [5,6]]]
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "with field names" do
|
44
|
+
before {
|
45
|
+
db.define_fields(:test, [[:id, :int], [:name, :str], [:point, :array]])
|
46
|
+
}
|
47
|
+
let(:h1){ {id:1, name:'hello', point:[1,2]}.deep_freeze }
|
48
|
+
let(:h2){ {id:2, name:'world', point:[3,4]}.deep_freeze }
|
49
|
+
|
50
|
+
it "should select by hash" do
|
51
|
+
db.select(:test, {id: 1}).must_equal [h1]
|
52
|
+
db.select(:test, {name: "world"}).must_equal [h2]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should iterate" do
|
56
|
+
db.select(:test, {id: 0}, iterator: :>).must_equal [h1, h2]
|
57
|
+
db.select(:test, {id: 4}, iterator: :<).must_equal [h2, h1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tarantool16
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sokolov Yura aka funny_falcon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,9 @@ files:
|
|
77
77
|
- lib/tarantool16/schema.rb
|
78
78
|
- lib/tarantool16/version.rb
|
79
79
|
- tarantool16.gemspec
|
80
|
+
- test/config.lua
|
81
|
+
- test/helper.rb
|
82
|
+
- test/test_dumb.rb
|
80
83
|
homepage: https://github.com/funny-falcon/tarantool16-ruby
|
81
84
|
licenses:
|
82
85
|
- MIT
|
@@ -97,8 +100,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
100
|
version: '0'
|
98
101
|
requirements: []
|
99
102
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.4.
|
103
|
+
rubygems_version: 2.4.8
|
101
104
|
signing_key:
|
102
105
|
specification_version: 4
|
103
106
|
summary: adapter for Tarantool 1.6
|
104
|
-
test_files:
|
107
|
+
test_files:
|
108
|
+
- test/config.lua
|
109
|
+
- test/helper.rb
|
110
|
+
- test/test_dumb.rb
|