oklahoma_mixer 0.1.0 → 0.2.0

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/test/test_helper.rb CHANGED
@@ -29,17 +29,16 @@ module TestHelper
29
29
  "#{self.class.to_s.sub(/\ATest/, '').downcase}.#{ext}" )
30
30
  end
31
31
 
32
- def hdb(*args)
33
- db = OKMixer::HashDatabase.new(db_path("tch"), *args)
34
- if block_given?
35
- begin
36
- yield db
37
- ensure
38
- db.close
39
- end
40
- else
41
- db
42
- end
32
+ def hdb(*args, &block)
33
+ OKMixer.open(db_path("tch"), *args, &block)
34
+ end
35
+
36
+ def bdb(*args, &block)
37
+ OKMixer.open(db_path("tcb"), *args, &block)
38
+ end
39
+
40
+ def fdb(*args, &block)
41
+ OKMixer.open(db_path("tcf"), *args, &block)
43
42
  end
44
43
 
45
44
  def remove_db_files
@@ -15,6 +15,18 @@ class TestTopLevelInterface < Test::Unit::TestCase
15
15
  end
16
16
  end
17
17
 
18
+ def test_open_of_a_tcb_extension_file_creates_a_b_tree_database
19
+ OKMixer.open(db_path("tcb")) do |db|
20
+ assert_instance_of(OKMixer::BTreeDatabase, db)
21
+ end
22
+ end
23
+
24
+ def test_open_of_a_tcf_extension_file_creates_a_fixed_length_database
25
+ OKMixer.open(db_path("tcf")) do |db|
26
+ assert_instance_of(OKMixer::FixedLengthDatabase, db)
27
+ end
28
+ end
29
+
18
30
  def test_open_of_an_unrecognized_extension_fails_with_an_error
19
31
  assert_raise(ArgumentError) do
20
32
  OKMixer.open("unrecognized")
data/test/tuning_test.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require "test_helper"
2
+ require "shared_tuning"
2
3
 
3
4
  class TestTuning < Test::Unit::TestCase
4
5
  def teardown
5
6
  remove_db_files
6
7
  end
7
8
 
8
- def test_a_mutex_can_be_activated_as_the_database_is_created
9
- assert_option_calls([:setmutex], :mutex => true)
10
- end
9
+ include SharedTuning
11
10
 
12
11
  def test_a_bucket_array_size_can_be_set_with_other_tuning_defaults
13
12
  size = rand(1_000) + 1
@@ -41,8 +40,7 @@ class TestTuning < Test::Unit::TestCase
41
40
  end
42
41
 
43
42
  def test_options_is_a_string_of_characters_mapped_to_enums_and_ored_together
44
- opts = { "l" => OKMixer::HashDatabase::C::OPTS[:HDBTLARGE],
45
- "b" => OKMixer::HashDatabase::C::OPTS[:HDBTBZIP] }
43
+ opts = {"l" => lib::OPTS[:HDBTLARGE], "b" => lib::OPTS[:HDBTBZIP]}
46
44
  assert_option_calls( [ :tune, 0, -1, -1,
47
45
  opts.values.inject(0) { |o, v| o | v } ],
48
46
  :opts => opts.keys.join )
@@ -67,8 +65,8 @@ class TestTuning < Test::Unit::TestCase
67
65
  end
68
66
 
69
67
  def test_optimize_allows_the_adjustment_of_tune_options_for_an_open_database
70
- hdb do |db|
71
- args = capture_args(OKMixer::HashDatabase::C, :optimize) do
68
+ db do |db|
69
+ args = capture_args(lib, :optimize) do
72
70
  db.optimize(:apow => "42", :opts => "ld")
73
71
  end
74
72
  assert_instance_of(FFI::Pointer, args[0])
@@ -85,89 +83,15 @@ class TestTuning < Test::Unit::TestCase
85
83
  assert_option_calls([:setcache, 42], :rcnum => "42")
86
84
  end
87
85
 
88
- def test_a_size_can_be_set_for_extra_mapped_memory
89
- size = rand(1_000) + 1
90
- assert_option_calls([:setxmsiz, size], :xmsiz => size)
91
- end
92
-
93
- def test_extra_mapped_memory_size_is_converted_to_an_int
94
- assert_option_calls([:setxmsiz, 42], :xmsiz => "42")
95
- end
96
-
97
- def test_a_step_unit_can_be_set_for_auto_defragmentation
98
- unit = rand(1_000) + 1
99
- assert_option_calls([:setdfunit, unit], :dfunit => unit)
100
- end
101
-
102
- def test_auto_defragmentation_step_unit_is_converted_to_an_int
103
- assert_option_calls([:setdfunit, 42], :dfunit => "42")
104
- end
105
-
106
- def test_nested_transactions_can_be_ignored
107
- hdb(:nested_transactions => :ignore) do |db|
108
- result = db.transaction {
109
- db.transaction { # ignored
110
- 41
111
- } + 1 # ignored
112
- }
113
- assert_equal(42, result)
114
- end
115
- end
116
-
117
- def test_nested_transactions_can_be_set_to_fail_with_an_error
118
- [:fail, :raise].each do |setting|
119
- hdb(:nested_transactions => setting) do |db|
120
- db.transaction do
121
- assert_raise(OKMixer::Error::TransactionError) do
122
- db.transaction { } # nested fails with error
123
- end
124
- end
125
- end
126
- end
127
- end
128
-
129
- def test_a_mode_string_can_be_passed
130
- assert_raise(OKMixer::Error::CabinetError) do # file not found
131
- hdb("r")
132
- end
133
- end
134
-
135
- def test_the_mode_can_be_passed_as_as_option
136
- assert_raise(OKMixer::Error::CabinetError) do # file not found
137
- hdb(:mode => "r")
138
- end
139
- end
140
-
141
- def test_an_option_mode_overrides_the_mode_argument_and_triggers_a_warning
142
- warning = capture_stderr do
143
- hdb("r", :mode => "wc") do
144
- # just open and close
145
- end
146
- end
147
- assert( !warning.empty?,
148
- "A warning was not issued for an option mode with a mode argument" )
149
- end
150
-
151
- def test_an_unknown_mode_triggers_a_warning
152
- warning = capture_stderr do
153
- hdb("wcu") do
154
- # just open and close
155
- end
156
- end
157
- assert(!warning.empty?, "A warning was not issued for an unknown mode")
158
- end
159
-
160
86
  #######
161
87
  private
162
88
  #######
163
89
 
164
- def assert_option_calls(c_call, options)
165
- args = capture_args(OKMixer::HashDatabase::C, c_call[0]) do
166
- hdb(options) do
167
- # just open and close
168
- end
169
- end
170
- assert_instance_of(FFI::Pointer, args[0])
171
- assert_equal(c_call[1..-1], args[1..-1])
90
+ def lib
91
+ OKMixer::HashDatabase::C
92
+ end
93
+
94
+ def db(*args, &block)
95
+ hdb(*args, &block)
172
96
  end
173
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oklahoma_mixer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edward Gray II
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-01 00:00:00 -06:00
12
+ date: 2010-01-09 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,17 +52,34 @@ extra_rdoc_files:
52
52
  files:
53
53
  - lib/oklahoma_mixer/array_list/c.rb
54
54
  - lib/oklahoma_mixer/array_list.rb
55
+ - lib/oklahoma_mixer/b_tree_database/c.rb
56
+ - lib/oklahoma_mixer/b_tree_database.rb
57
+ - lib/oklahoma_mixer/cursor/c.rb
58
+ - lib/oklahoma_mixer/cursor.rb
55
59
  - lib/oklahoma_mixer/error.rb
56
60
  - lib/oklahoma_mixer/extensible_string/c.rb
57
61
  - lib/oklahoma_mixer/extensible_string.rb
62
+ - lib/oklahoma_mixer/fixed_length_database/c.rb
63
+ - lib/oklahoma_mixer/fixed_length_database.rb
58
64
  - lib/oklahoma_mixer/hash_database/c.rb
59
65
  - lib/oklahoma_mixer/hash_database.rb
60
66
  - lib/oklahoma_mixer/utilities.rb
61
67
  - lib/oklahoma_mixer.rb
68
+ - test/b_tree_binary_data_test.rb
69
+ - test/b_tree_tuning_test.rb
62
70
  - test/binary_data_test.rb
71
+ - test/cursor_based_iteration_test.rb
72
+ - test/duplicate_storage_test.rb
63
73
  - test/file_system_test.rb
74
+ - test/fixed_length_tuning_test.rb
75
+ - test/getting_and_setting_by_id_test.rb
64
76
  - test/getting_and_setting_keys_test.rb
65
77
  - test/iteration_test.rb
78
+ - test/key_range_test.rb
79
+ - test/order_test.rb
80
+ - test/shared_binary_data.rb
81
+ - test/shared_iteration.rb
82
+ - test/shared_tuning.rb
66
83
  - test/test_helper.rb
67
84
  - test/top_level_interface_test.rb
68
85
  - test/transactions_test.rb
@@ -106,10 +123,18 @@ signing_key:
106
123
  specification_version: 3
107
124
  summary: An full featured and robust FFI interface to Tokyo Cabinet.
108
125
  test_files:
126
+ - test/b_tree_binary_data_test.rb
127
+ - test/b_tree_tuning_test.rb
109
128
  - test/binary_data_test.rb
129
+ - test/cursor_based_iteration_test.rb
130
+ - test/duplicate_storage_test.rb
110
131
  - test/file_system_test.rb
132
+ - test/fixed_length_tuning_test.rb
133
+ - test/getting_and_setting_by_id_test.rb
111
134
  - test/getting_and_setting_keys_test.rb
112
135
  - test/iteration_test.rb
136
+ - test/key_range_test.rb
137
+ - test/order_test.rb
113
138
  - test/top_level_interface_test.rb
114
139
  - test/transactions_test.rb
115
140
  - test/tuning_test.rb