tarantool16 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62a5d736d466e1c713051fc111c67e3e938bf745
4
- data.tar.gz: 29bbca98c7773046dff52f466fad62ff02126137
3
+ metadata.gz: 4708dae76a87bea3c57671ad97120d4a60ecf5a6
4
+ data.tar.gz: 16d47be30532317b0e29380952baaf90e8c2817f
5
5
  SHA512:
6
- metadata.gz: a56d98dd3030cf79931a9820f8109eb0eaa89b1fceca8b73915642429409e3a597bb80c819aaf7a2eb74f366d0ed8e1dc1098d1c4037f6cbbe4ed8bb463e2630
7
- data.tar.gz: cc7c4d07c41ad772b38a4a3cd4fb8c0ed7b533116a444cdddc5c21e2b3f2d5f6e54178ea9fa50d866126c49e963ab0f304e13958790e32ad6f2b74c1a2399b9a
6
+ metadata.gz: 6577b96200a9cca5e14e5acba0203e14423e505a02219164716f49ec1160d1b1073c59170ac0227753dce09a040e1960524c2edee88efcc892ad68fd7ae731c3
7
+ data.tar.gz: d51b72462995c71820cc174c459b1fc2848b0a03cd2b74067bbf7d9d17e5b7a89b8e4cab4f02317cf98396e003fa9072975b93c85daebc754cac4e6449e83aad
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ /test/*.log
10
+ /test/run/
9
11
  /tmp/
10
12
  *.bundle
11
13
  *.so
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new
2
5
 
data/lib/tarantool16.rb CHANGED
@@ -5,7 +5,7 @@ module Tarantool16
5
5
  autoload :DumbDB, 'tarantool16/dumb_db'
6
6
  def self.new(opts = {})
7
7
  opts = opts.dup
8
- hosts = opts[:host]
8
+ hosts = [opts[:host], opts[:port]].compact.join(':')
9
9
  type = opts[:type] && opts[:type].to_s || 'dumb'
10
10
  case type
11
11
  when 'dumb'
@@ -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 spacefor fields #{key.keys}"))
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, ITERATOR_GT].freeze,
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,
@@ -1,3 +1,3 @@
1
1
  module Tarantool16
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-06-10 00:00:00.000000000 Z
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.5
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