rufus-tokyo 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/LICENSE.txt +21 -0
- data/TODO.txt +5 -0
- data/lib/rufus/tokyo/base.rb +1 -1
- data/lib/rufus/tokyo/cabinet/abstract.rb +0 -1
- data/lib/rufus/tokyo/cabinet/lib.rb +3 -0
- data/lib/rufus/tokyo/cabinet/table.rb +15 -1
- data/lib/rufus/tokyo/cabinet/util.rb +0 -1
- data/lib/rufus/tokyo/hmethods.rb +1 -0
- data/rel.txt +9 -0
- metadata +6 -24
- data/test/cabinet/abstract_0_test.rb +0 -75
- data/test/cabinet/abstract_1_test.rb +0 -69
- data/test/cabinet/api_0_test.rb +0 -26
- data/test/cabinet/hmethods_test.rb +0 -52
- data/test/cabinet/table_0_test.rb +0 -63
- data/test/cabinet/table_1_test.rb +0 -153
- data/test/cabinet/test.rb +0 -9
- data/test/cabinet/util_list_test.rb +0 -86
- data/test/cabinet/util_map_test.rb +0 -69
- data/test/dystopia/test.rb +0 -9
- data/test/dystopia/words_0_test.rb +0 -22
- data/test/mem.rb +0 -49
- data/test/mem1.rb +0 -44
- data/test/test_base.rb +0 -8
data/CHANGELOG.txt
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
21
|
+
|
data/TODO.txt
ADDED
data/lib/rufus/tokyo/base.rb
CHANGED
@@ -104,6 +104,9 @@ module Rufus::Tokyo
|
|
104
104
|
|
105
105
|
attach_function :tctdbget, [ :pointer, :string, :int ], :pointer
|
106
106
|
|
107
|
+
attach_function :tctdbiterinit, [ :pointer ], :int
|
108
|
+
attach_function :tctdbiternext2, [ :pointer ], :string
|
109
|
+
|
107
110
|
attach_function :tctdbput, [ :pointer, :string, :int, :pointer ], :int
|
108
111
|
attach_function :tctdbput3, [ :pointer, :string, :string ], :int
|
109
112
|
attach_function :tctdbout2, [ :pointer, :string ], :int
|
@@ -67,6 +67,7 @@ module Rufus::Tokyo
|
|
67
67
|
class Table
|
68
68
|
include CabinetLibMixin
|
69
69
|
include TokyoContainerMixin
|
70
|
+
include HashMethods
|
70
71
|
|
71
72
|
#
|
72
73
|
# Creates a Table instance (creates or opens it depending on the args)
|
@@ -182,11 +183,24 @@ module Rufus::Tokyo
|
|
182
183
|
#
|
183
184
|
# Returns the value (as a Ruby Hash) else nil
|
184
185
|
#
|
185
|
-
|
186
|
+
# (the actual #[] method is provided by HashMethods)
|
187
|
+
#
|
188
|
+
def get (k)
|
186
189
|
m = lib.tctdbget(@db, k, lib.strlen(k))
|
187
190
|
return nil if m.address == 0 # :( too bad, but it works
|
188
191
|
Rufus::Tokyo::Map.to_h(m) # which frees the map
|
189
192
|
end
|
193
|
+
protected :get
|
194
|
+
|
195
|
+
#
|
196
|
+
# Returns an array of all the primary keys in the table
|
197
|
+
#
|
198
|
+
def keys
|
199
|
+
a = []
|
200
|
+
lib.tctdbiterinit(@db)
|
201
|
+
while (k = (lib.tctdbiternext2(@db) rescue nil)); a << k; end
|
202
|
+
a
|
203
|
+
end
|
190
204
|
|
191
205
|
#
|
192
206
|
# Returns the number of records in this table db
|
data/lib/rufus/tokyo/hmethods.rb
CHANGED
data/rel.txt
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-tokyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-02 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,41 +33,23 @@ extra_rdoc_files:
|
|
33
33
|
- CHANGELOG.txt
|
34
34
|
- CREDITS.txt
|
35
35
|
files:
|
36
|
-
- lib/rufus
|
37
|
-
- lib/rufus/tokyo
|
38
36
|
- lib/rufus/tokyo/base.rb
|
39
|
-
- lib/rufus/tokyo/cabinet
|
40
37
|
- lib/rufus/tokyo/cabinet/abstract.rb
|
41
38
|
- lib/rufus/tokyo/cabinet/lib.rb
|
42
39
|
- lib/rufus/tokyo/cabinet/table.rb
|
43
40
|
- lib/rufus/tokyo/cabinet/util.rb
|
44
41
|
- lib/rufus/tokyo/cabinet.rb
|
45
|
-
- lib/rufus/tokyo/dystopia
|
46
42
|
- lib/rufus/tokyo/dystopia/lib.rb
|
47
43
|
- lib/rufus/tokyo/dystopia/words.rb
|
48
44
|
- lib/rufus/tokyo/hmethods.rb
|
49
45
|
- lib/rufus/tokyo.rb
|
50
46
|
- lib/rufus-tokyo.rb
|
51
|
-
- test/cabinet
|
52
|
-
- test/cabinet/abstract_0_test.rb
|
53
|
-
- test/cabinet/abstract_1_test.rb
|
54
|
-
- test/cabinet/api_0_test.rb
|
55
|
-
- test/cabinet/hmethods_test.rb
|
56
|
-
- test/cabinet/table_0_test.rb
|
57
|
-
- test/cabinet/table_1_test.rb
|
58
|
-
- test/cabinet/test.rb
|
59
|
-
- test/cabinet/util_list_test.rb
|
60
|
-
- test/cabinet/util_map_test.rb
|
61
|
-
- test/dystopia
|
62
|
-
- test/dystopia/test.rb
|
63
|
-
- test/dystopia/words_0_test.rb
|
64
|
-
- test/mem.rb
|
65
|
-
- test/mem1.rb
|
66
|
-
- test/test.rb
|
67
|
-
- test/test_base.rb
|
68
|
-
- README.txt
|
69
47
|
- CHANGELOG.txt
|
70
48
|
- CREDITS.txt
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.txt
|
51
|
+
- rel.txt
|
52
|
+
- TODO.txt
|
71
53
|
has_rdoc: true
|
72
54
|
homepage: http://rufus.rubyforge.org/
|
73
55
|
post_install_message:
|
@@ -1,75 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Fri Jan 23 08:31:01 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/cabinet'
|
11
|
-
|
12
|
-
|
13
|
-
class CabinetZero < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@db = Rufus::Tokyo::Cabinet.new('test_data.tch')
|
17
|
-
@db.clear
|
18
|
-
end
|
19
|
-
def teardown
|
20
|
-
@db.close
|
21
|
-
end
|
22
|
-
def db
|
23
|
-
@db
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_basic_workflow
|
27
|
-
|
28
|
-
db['pillow'] = 'Shonagon'
|
29
|
-
|
30
|
-
assert_equal 1, db.size
|
31
|
-
assert_equal 'Shonagon', db['pillow']
|
32
|
-
|
33
|
-
assert_equal 'Shonagon', db.delete('pillow')
|
34
|
-
assert_equal 0, db.size
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_clear
|
38
|
-
|
39
|
-
40.times { |i| db[i.to_s] = i.to_s }
|
40
|
-
assert_equal 40, db.size
|
41
|
-
|
42
|
-
db.clear
|
43
|
-
|
44
|
-
assert_equal 0, db.size
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_keys_and_values
|
48
|
-
|
49
|
-
keys = %w{ alpha bravo charly delta echo foxtrott }
|
50
|
-
|
51
|
-
keys.each_with_index { |k, i| db[k] = i.to_s }
|
52
|
-
|
53
|
-
assert_equal keys, db.keys
|
54
|
-
assert_equal %w{ 0 1 2 3 4 5 }, db.values
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_merge
|
58
|
-
|
59
|
-
db['a'] = 'A'
|
60
|
-
|
61
|
-
assert_equal(
|
62
|
-
{ 'a' => 'A', 'b' => 'B', 'c' => 'C' },
|
63
|
-
db.merge({ 'b' => 'B', 'c' => 'C' }))
|
64
|
-
|
65
|
-
assert_equal 1, db.size
|
66
|
-
|
67
|
-
db.merge!({ 'b' => 'B', 'c' => 'C' })
|
68
|
-
|
69
|
-
assert_equal(3, db.size)
|
70
|
-
|
71
|
-
assert_equal({ 'a' => 'A', 'b' => 'B', 'c' => 'C' }, db.to_h)
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
@@ -1,69 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Sun Jan 25 12:26:48 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'fileutils'
|
11
|
-
require 'rufus/tokyo/cabinet'
|
12
|
-
|
13
|
-
|
14
|
-
class CabinetOne < Test::Unit::TestCase
|
15
|
-
|
16
|
-
def test_copy
|
17
|
-
|
18
|
-
cab = Rufus::Tokyo::Cabinet.new('test_source.tch')
|
19
|
-
5000.times { |i| cab["key #{i}"] = "val #{i}" }
|
20
|
-
2500.times { |i| cab.delete("key #{i}") }
|
21
|
-
assert_equal 2500, cab.size
|
22
|
-
cab.copy('test_target.tch')
|
23
|
-
cab.close
|
24
|
-
|
25
|
-
cab = Rufus::Tokyo::Cabinet.new('test_target.tch')
|
26
|
-
assert_equal 2500, cab.size
|
27
|
-
cab.close
|
28
|
-
|
29
|
-
FileUtils.rm('test_source.tch')
|
30
|
-
FileUtils.rm('test_target.tch')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_compact_copy
|
34
|
-
|
35
|
-
cab = Rufus::Tokyo::Cabinet.new('test_source.tch')
|
36
|
-
100.times { |i| cab["key #{i}"] = "val #{i}" }
|
37
|
-
50.times { |i| cab.delete("key #{i}") }
|
38
|
-
assert_equal 50, cab.size
|
39
|
-
cab.compact_copy('test_target.tch')
|
40
|
-
cab.close
|
41
|
-
|
42
|
-
cab = Rufus::Tokyo::Cabinet.new('test_target.tch')
|
43
|
-
assert_equal 50, cab.size
|
44
|
-
cab.close
|
45
|
-
|
46
|
-
fs0 = File.size('test_source.tch')
|
47
|
-
fs1 = File.size('test_target.tch')
|
48
|
-
assert (fs0 > fs1)
|
49
|
-
|
50
|
-
FileUtils.rm('test_source.tch')
|
51
|
-
FileUtils.rm('test_target.tch')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_default
|
55
|
-
|
56
|
-
db = Rufus::Tokyo::Cabinet.new('test_data.tch', :default => 'wrong')
|
57
|
-
db.clear
|
58
|
-
|
59
|
-
db['a'] = 'A'
|
60
|
-
|
61
|
-
assert_equal 'A', db['a']
|
62
|
-
assert_equal 'wrong', db['b']
|
63
|
-
|
64
|
-
assert_equal 1, db.size
|
65
|
-
|
66
|
-
db.close
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
data/test/cabinet/api_0_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Mon Jan 26 15:10:03 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/base'
|
11
|
-
|
12
|
-
|
13
|
-
class ApiZero < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def test_compute_open_mode
|
16
|
-
|
17
|
-
o = Object.new
|
18
|
-
o.extend(Rufus::Tokyo::TokyoContainerMixin)
|
19
|
-
|
20
|
-
assert_equal 0, o.compute_open_mode({})
|
21
|
-
assert_equal 16, o.compute_open_mode(:no_lock => true)
|
22
|
-
assert_equal 17, o.compute_open_mode([:no_lock, :reader])
|
23
|
-
assert_equal 20, o.compute_open_mode([:no_lock, :create])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
@@ -1,52 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Thu Jan 29 11:19:25 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/hmethods'
|
11
|
-
|
12
|
-
|
13
|
-
class HmethodsTest < Test::Unit::TestCase
|
14
|
-
|
15
|
-
class MyHash
|
16
|
-
attr_accessor :default_proc
|
17
|
-
def get (k)
|
18
|
-
k.to_i % 2 == 0 ? k : nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@h = MyHash.new
|
24
|
-
@h.extend(Rufus::Tokyo::HashMethods)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_myhash
|
28
|
-
|
29
|
-
assert_equal nil, @h[1]
|
30
|
-
assert_equal 2, @h[2]
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_default
|
34
|
-
|
35
|
-
@h.default = :default
|
36
|
-
|
37
|
-
assert_equal :default, @h.default
|
38
|
-
|
39
|
-
assert_equal :default, @h[1]
|
40
|
-
assert_equal 2, @h[2]
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_default_proc
|
44
|
-
|
45
|
-
@h.default_proc = lambda { |h, k| k * 2 }
|
46
|
-
|
47
|
-
assert_equal 2, @h[1]
|
48
|
-
assert_equal 2, @h[2]
|
49
|
-
assert_equal 6, @h[3]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Mon Jan 26 15:10:03 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/cabinet/table'
|
11
|
-
|
12
|
-
|
13
|
-
class TableZero < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def test_open_missing
|
16
|
-
|
17
|
-
e = assert_raises Rufus::Tokyo::TokyoError do
|
18
|
-
Rufus::Tokyo::Table.new('missing.tdb')
|
19
|
-
end
|
20
|
-
|
21
|
-
assert_equal '(err 3) file not found', e.message
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_tabbed_put
|
25
|
-
|
26
|
-
t = Rufus::Tokyo::Table.new('test_new.tdb', :create, :write)
|
27
|
-
t.clear
|
28
|
-
|
29
|
-
assert_equal 0, t.size
|
30
|
-
|
31
|
-
assert t.genuid > 0, 'unique id is 0, bad'
|
32
|
-
assert t.generate_unique_id > 0, 'unique id is 0, bad'
|
33
|
-
|
34
|
-
t.tabbed_put('toto', 'name', 'toto', 'age', '3')
|
35
|
-
t.tabbed_put('fred', 'name', 'fred', 'age', '4')
|
36
|
-
|
37
|
-
assert_equal 2, t.size
|
38
|
-
|
39
|
-
t.close
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_put
|
43
|
-
|
44
|
-
t = Rufus::Tokyo::Table.new('test_new.tdb', :create, :write)
|
45
|
-
t.clear
|
46
|
-
|
47
|
-
t['pk0'] = [ 'name', 'alfred', 'age', '22']
|
48
|
-
t['pk1'] = { 'name' => 'jim', 'age' => '23' }
|
49
|
-
|
50
|
-
assert_equal 2, t.size
|
51
|
-
|
52
|
-
assert_equal({ 'name' => 'jim', 'age' => '23' }, t['pk1'])
|
53
|
-
|
54
|
-
t.delete('pk0')
|
55
|
-
|
56
|
-
assert_equal 1, t.size
|
57
|
-
|
58
|
-
assert_nil t['pk0']
|
59
|
-
|
60
|
-
t.close
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
@@ -1,153 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Mon Jan 26 15:10:03 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/cabinet/table'
|
11
|
-
|
12
|
-
|
13
|
-
class TableOne < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@tdb = Rufus::Tokyo::Table.new('test_new.tdb', :create, :write)
|
17
|
-
@tdb.clear
|
18
|
-
@tdb['pk0'] = { 'name' => 'jim', 'age' => '25', 'lang' => 'ja,en' }
|
19
|
-
@tdb['pk1'] = { 'name' => 'jeff', 'age' => '32', 'lang' => 'en,es' }
|
20
|
-
@tdb['pk2'] = { 'name' => 'jack', 'age' => '44', 'lang' => 'en' }
|
21
|
-
@tdb['pk3'] = { 'name' => 'jake', 'age' => '45', 'lang' => 'en,li' }
|
22
|
-
end
|
23
|
-
|
24
|
-
def teardown
|
25
|
-
@tdb.close
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_prepare_query
|
29
|
-
|
30
|
-
q = @tdb.prepare_query { |q|
|
31
|
-
q.add 'lang', :includes, 'en'
|
32
|
-
}
|
33
|
-
rs = q.run
|
34
|
-
|
35
|
-
assert_equal 4, rs.size
|
36
|
-
|
37
|
-
rs.close
|
38
|
-
|
39
|
-
q.limit 2
|
40
|
-
|
41
|
-
rs = q.run
|
42
|
-
|
43
|
-
assert_equal 2, rs.size
|
44
|
-
|
45
|
-
q.close
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_limit
|
49
|
-
|
50
|
-
rs = @tdb.do_query { |q|
|
51
|
-
q.add 'lang', :includes, 'en'
|
52
|
-
q.order_by 'name', :desc
|
53
|
-
q.limit 2 # set_max
|
54
|
-
}
|
55
|
-
|
56
|
-
assert_equal 2, rs.size
|
57
|
-
|
58
|
-
assert_equal(
|
59
|
-
[
|
60
|
-
{:pk => 'pk0', "name"=>"jim", "lang"=>"ja,en", "age"=>"25"},
|
61
|
-
{:pk => 'pk1', "name"=>"jeff", "lang"=>"en,es", "age"=>"32"}
|
62
|
-
],
|
63
|
-
rs.to_a)
|
64
|
-
|
65
|
-
rs.free
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_order_strasc
|
69
|
-
|
70
|
-
assert_equal(
|
71
|
-
[
|
72
|
-
{:pk => 'pk2', "name"=>"jack", "lang"=>"en", "age"=>"44"},
|
73
|
-
{:pk => 'pk3', "name"=>"jake", "lang"=>"en,li", "age"=>"45"},
|
74
|
-
{:pk => 'pk1', "name"=>"jeff", "lang"=>"en,es", "age"=>"32"},
|
75
|
-
{:pk => 'pk0', "name"=>"jim", "lang"=>"ja,en", "age"=>"25"}
|
76
|
-
],
|
77
|
-
@tdb.query { |q|
|
78
|
-
q.add 'lang', :includes, 'en'
|
79
|
-
q.order_by 'name', :asc
|
80
|
-
})
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_order_numasc
|
84
|
-
|
85
|
-
assert_equal(
|
86
|
-
[
|
87
|
-
{:pk => 'pk0', "name"=>"jim", "lang"=>"ja,en", "age"=>"25"},
|
88
|
-
{:pk => 'pk1', "name"=>"jeff", "lang"=>"en,es", "age"=>"32"},
|
89
|
-
{:pk => 'pk2', "name"=>"jack", "lang"=>"en", "age"=>"44"},
|
90
|
-
{:pk => 'pk3', "name"=>"jake", "lang"=>"en,li", "age"=>"45"}
|
91
|
-
],
|
92
|
-
a = @tdb.query { |q|
|
93
|
-
q.add 'lang', :includes, 'en'
|
94
|
-
q.order_by 'age', :numasc
|
95
|
-
})
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_matches
|
99
|
-
|
100
|
-
assert_equal(
|
101
|
-
[
|
102
|
-
{:pk => 'pk2', "name"=>"jack", "lang"=>"en", "age"=>"44"},
|
103
|
-
{:pk => 'pk3', "name"=>"jake", "lang"=>"en,li", "age"=>"45"}
|
104
|
-
],
|
105
|
-
a = @tdb.query { |q|
|
106
|
-
q.add 'name', :matches, '^j.+k'
|
107
|
-
})
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_no_pk
|
111
|
-
|
112
|
-
assert_equal(
|
113
|
-
[
|
114
|
-
{"name"=>"jack", "lang"=>"en", "age"=>"44"},
|
115
|
-
{"name"=>"jake", "lang"=>"en,li", "age"=>"45"}
|
116
|
-
],
|
117
|
-
a = @tdb.query { |q|
|
118
|
-
q.add 'name', :matches, '^j.+k'
|
119
|
-
q.no_pk
|
120
|
-
})
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_pk_only
|
124
|
-
|
125
|
-
assert_equal(
|
126
|
-
[ 'pk2', 'pk3' ],
|
127
|
-
a = @tdb.query { |q|
|
128
|
-
q.add 'name', :matches, '^j.+k'
|
129
|
-
q.pk_only
|
130
|
-
})
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_condition_numerical_gt
|
134
|
-
|
135
|
-
assert_equal(
|
136
|
-
[ 'pk2', 'pk3' ],
|
137
|
-
a = @tdb.query { |q|
|
138
|
-
q.add 'age', :gt, '40'
|
139
|
-
q.pk_only
|
140
|
-
})
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_condition_negate
|
144
|
-
|
145
|
-
assert_equal(
|
146
|
-
[ 'pk0', 'pk1' ],
|
147
|
-
a = @tdb.query { |q|
|
148
|
-
q.add 'age', :gt, '40', false
|
149
|
-
q.pk_only
|
150
|
-
})
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
data/test/cabinet/test.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Tue Jan 27 16:30:34 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/cabinet/util'
|
11
|
-
|
12
|
-
|
13
|
-
class UtilOne < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def test_list_0
|
16
|
-
|
17
|
-
l = Rufus::Tokyo::List.new
|
18
|
-
|
19
|
-
assert_nil l.pop
|
20
|
-
assert_nil l.shift
|
21
|
-
|
22
|
-
l << 'alpha'
|
23
|
-
l << 'bravo'
|
24
|
-
l << 'charly'
|
25
|
-
|
26
|
-
assert_equal 3, l.size
|
27
|
-
assert_equal 'bravo', l[1]
|
28
|
-
assert_equal 'charly', l[-1]
|
29
|
-
assert_equal %w{ alpha bravo }, l[0, 2]
|
30
|
-
assert_equal %w{ alpha bravo charly }, l[0..-1]
|
31
|
-
assert_equal %w{ alpha bravo }, l[0..1]
|
32
|
-
assert_nil l[0, -1]
|
33
|
-
|
34
|
-
assert_equal %w{ ALPHA BRAVO CHARLY }, l.collect { |e| e.upcase }
|
35
|
-
|
36
|
-
assert_equal 'charly', l.pop
|
37
|
-
assert_equal 2, l.size
|
38
|
-
|
39
|
-
l.unshift('delta')
|
40
|
-
assert_equal 3, l.size
|
41
|
-
|
42
|
-
assert_equal 'delta', l.shift
|
43
|
-
assert_equal 2, l.size
|
44
|
-
|
45
|
-
l.push 'echo', 'foxtrott'
|
46
|
-
assert_equal 4, l.size
|
47
|
-
|
48
|
-
l.close
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_list_1
|
52
|
-
|
53
|
-
l = Rufus::Tokyo::List.new
|
54
|
-
|
55
|
-
#assert_raises RuntimeError do
|
56
|
-
# l << nil
|
57
|
-
#end
|
58
|
-
|
59
|
-
l << '-'
|
60
|
-
l << '-'
|
61
|
-
l << '-'
|
62
|
-
l << '-'
|
63
|
-
l << '4'
|
64
|
-
|
65
|
-
l[0, 3] = [ 'a', 'b', 'c' ]
|
66
|
-
assert_equal %w{ a b c - 4 }, l.to_a
|
67
|
-
|
68
|
-
l[1..2] = [ '1', '2' ]
|
69
|
-
assert_equal %w{ a 1 2 - 4 }, l.to_a
|
70
|
-
|
71
|
-
l[0, 2] = '?'
|
72
|
-
assert_equal %w{ ? 2 - 4 }, l.to_a
|
73
|
-
|
74
|
-
l[0..2] = 'A'
|
75
|
-
assert_equal %w{ A 4 }, l.to_a
|
76
|
-
|
77
|
-
l[-1] = 'Z'
|
78
|
-
assert_equal %w{ A Z }, l.to_a
|
79
|
-
|
80
|
-
l[1..-1] = nil
|
81
|
-
assert_equal %w{ A }, l.to_a
|
82
|
-
|
83
|
-
l.free
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
@@ -1,69 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Mon Jan 26 15:10:03 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/cabinet/util'
|
11
|
-
|
12
|
-
|
13
|
-
class UtilZero < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def test_map_0
|
16
|
-
|
17
|
-
m = Rufus::Tokyo::Map.new
|
18
|
-
m['a'] = 'b'
|
19
|
-
m['c'] = 'd'
|
20
|
-
|
21
|
-
assert_equal 'b', m['a']
|
22
|
-
assert_equal nil, m['Z']
|
23
|
-
|
24
|
-
assert_equal [ 'a', 'c' ], m.keys
|
25
|
-
assert_equal [ 'b', 'd' ], m.values
|
26
|
-
|
27
|
-
assert_equal 'a=b&c=d', m.collect { |k, v| "#{k}=#{v}" }.join('&')
|
28
|
-
|
29
|
-
assert_equal 2, m.size
|
30
|
-
assert_equal 2, m.length
|
31
|
-
|
32
|
-
m.delete('a')
|
33
|
-
assert_equal 1, m.size
|
34
|
-
|
35
|
-
m.clear
|
36
|
-
assert_equal 0, m.length
|
37
|
-
|
38
|
-
m.destroy
|
39
|
-
|
40
|
-
assert_raises RuntimeError do
|
41
|
-
m['c']
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_map_to_from_h
|
46
|
-
|
47
|
-
h = { 'a' => 'A', 'b' => 'B' }
|
48
|
-
m = Rufus::Tokyo::Map.from_h(h)
|
49
|
-
|
50
|
-
assert_equal 'A', m['a']
|
51
|
-
|
52
|
-
h1 = m.to_h
|
53
|
-
assert_kind_of Hash, h1
|
54
|
-
assert_equal h, h1
|
55
|
-
|
56
|
-
m.free
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_map_merge
|
60
|
-
|
61
|
-
m = Rufus::Tokyo::Map.from_h({ 'a' => 'A', 'b' => 'B' })
|
62
|
-
m.merge!('c' => 'C')
|
63
|
-
|
64
|
-
assert_equal 3, m.size
|
65
|
-
|
66
|
-
m.free
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
data/test/dystopia/test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Testing rufus-tokyo
|
4
|
-
#
|
5
|
-
# Mon Jan 26 12:54:32 JST 2009
|
6
|
-
#
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../test_base'
|
9
|
-
|
10
|
-
require 'rufus/tokyo/dystopia/words'
|
11
|
-
|
12
|
-
|
13
|
-
class CabinetZero < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def test_open_missing
|
16
|
-
|
17
|
-
e = assert_raises Rufus::Tokyo::DystopianError do
|
18
|
-
db = Rufus::Tokyo::Words.new('missing.tcw')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
data/test/mem.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
|
2
|
-
%w{ lib test }.each do |path|
|
3
|
-
path = File.expand_path(File.dirname(__FILE__) + '/../' + path)
|
4
|
-
$: << path unless $:.include?(path)
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'fileutils'
|
8
|
-
|
9
|
-
|
10
|
-
def self_ps
|
11
|
-
ps = `ps -v #{$$}`.split("\n").last.split(' ')
|
12
|
-
%w{
|
13
|
-
pid stat time sl re pagein vsz rss lim tsiz pcpu pmem command
|
14
|
-
}.inject({}) { |h, k|
|
15
|
-
h[k.intern] = ps.shift; h
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def pmem (msg)
|
20
|
-
p [ msg, "#{self_ps[:vsz].to_i / 1024}k" ]
|
21
|
-
end
|
22
|
-
|
23
|
-
pmem 'starting'
|
24
|
-
|
25
|
-
require 'rubygems'
|
26
|
-
require 'rufus/tokyo'
|
27
|
-
|
28
|
-
FileUtils.rm('test_mem.tch')
|
29
|
-
|
30
|
-
db = Rufus::Tokyo::Cabinet.new('test_mem.tch')
|
31
|
-
|
32
|
-
pmem 'wired to db'
|
33
|
-
|
34
|
-
500_000.times { |i| db[i.to_s] = "value#{i}" }
|
35
|
-
|
36
|
-
pmem 'loaded 500_000 records'
|
37
|
-
|
38
|
-
db.each { |k, v| k }
|
39
|
-
|
40
|
-
pmem 'iterated 500_000 records'
|
41
|
-
|
42
|
-
a = db.collect { |k, v| k + v }
|
43
|
-
|
44
|
-
pmem 'collected 500_000 records'
|
45
|
-
|
46
|
-
db.close
|
47
|
-
|
48
|
-
pmem 'closed db'
|
49
|
-
|
data/test/mem1.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
%w{ lib test }.each do |path|
|
3
|
-
path = File.expand_path(File.dirname(__FILE__) + '/../' + path)
|
4
|
-
$: << path unless $:.include?(path)
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'fileutils'
|
8
|
-
|
9
|
-
|
10
|
-
def self_ps
|
11
|
-
ps = `ps -v #{$$}`.split("\n").last.split(' ')
|
12
|
-
%w{
|
13
|
-
pid stat time sl re pagein vsz rss lim tsiz pcpu pmem command
|
14
|
-
}.inject({}) { |h, k|
|
15
|
-
h[k.intern] = ps.shift; h
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def pmem (msg)
|
20
|
-
p [ msg, "#{self_ps[:vsz].to_i / 1024}k" ]
|
21
|
-
end
|
22
|
-
|
23
|
-
pmem 'starting'
|
24
|
-
|
25
|
-
require 'rubygems'
|
26
|
-
require 'rufus/tokyo/util'
|
27
|
-
|
28
|
-
pmem 'required'
|
29
|
-
|
30
|
-
l = Rufus::Tokyo::List.new
|
31
|
-
|
32
|
-
100000.times { |i| l << i.to_s }
|
33
|
-
|
34
|
-
pmem 'stored'
|
35
|
-
|
36
|
-
#100000.times { |i| l.delete_at(0) }
|
37
|
-
#100000.times { |i| s = l.delete_at(0); Rufus::Tokyo::CabinetLib.tcfree(s) }
|
38
|
-
s = nil
|
39
|
-
100000.times { |i| s ||= l.delete_at(0); }
|
40
|
-
p s.class
|
41
|
-
p s.public_methods.sort
|
42
|
-
|
43
|
-
pmem 'cleared'
|
44
|
-
|