ferret 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +23 -5
- data/TODO +2 -1
- data/ext/analysis.c +838 -177
- data/ext/analysis.h +55 -7
- data/ext/api.c +69 -0
- data/ext/api.h +27 -0
- data/ext/array.c +8 -5
- data/ext/compound_io.c +132 -96
- data/ext/document.c +58 -28
- data/ext/except.c +59 -0
- data/ext/except.h +88 -0
- data/ext/ferret.c +47 -3
- data/ext/ferret.h +3 -0
- data/ext/field.c +15 -9
- data/ext/filter.c +1 -1
- data/ext/fs_store.c +215 -34
- data/ext/global.c +72 -3
- data/ext/global.h +4 -3
- data/ext/hash.c +44 -3
- data/ext/hash.h +9 -0
- data/ext/header.h +58 -0
- data/ext/inc/except.h +88 -0
- data/ext/inc/lang.h +23 -13
- data/ext/ind.c +16 -10
- data/ext/index.h +2 -22
- data/ext/index_io.c +3 -11
- data/ext/index_rw.c +245 -193
- data/ext/lang.h +23 -13
- data/ext/libstemmer.c +92 -0
- data/ext/libstemmer.h +79 -0
- data/ext/modules.h +162 -0
- data/ext/q_boolean.c +34 -21
- data/ext/q_const_score.c +6 -12
- data/ext/q_filtered_query.c +206 -0
- data/ext/q_fuzzy.c +18 -15
- data/ext/q_match_all.c +3 -7
- data/ext/q_multi_phrase.c +10 -14
- data/ext/q_parser.c +29 -2
- data/ext/q_phrase.c +14 -21
- data/ext/q_prefix.c +15 -12
- data/ext/q_range.c +30 -28
- data/ext/q_span.c +13 -21
- data/ext/q_term.c +17 -26
- data/ext/r_analysis.c +693 -21
- data/ext/r_doc.c +11 -12
- data/ext/r_index_io.c +4 -1
- data/ext/r_qparser.c +21 -2
- data/ext/r_search.c +285 -18
- data/ext/ram_store.c +5 -2
- data/ext/search.c +11 -17
- data/ext/search.h +21 -45
- data/ext/similarity.h +67 -0
- data/ext/sort.c +30 -25
- data/ext/stem_ISO_8859_1_danish.c +338 -0
- data/ext/stem_ISO_8859_1_danish.h +16 -0
- data/ext/stem_ISO_8859_1_dutch.c +635 -0
- data/ext/stem_ISO_8859_1_dutch.h +16 -0
- data/ext/stem_ISO_8859_1_english.c +1156 -0
- data/ext/stem_ISO_8859_1_english.h +16 -0
- data/ext/stem_ISO_8859_1_finnish.c +792 -0
- data/ext/stem_ISO_8859_1_finnish.h +16 -0
- data/ext/stem_ISO_8859_1_french.c +1276 -0
- data/ext/stem_ISO_8859_1_french.h +16 -0
- data/ext/stem_ISO_8859_1_german.c +512 -0
- data/ext/stem_ISO_8859_1_german.h +16 -0
- data/ext/stem_ISO_8859_1_italian.c +1091 -0
- data/ext/stem_ISO_8859_1_italian.h +16 -0
- data/ext/stem_ISO_8859_1_norwegian.c +296 -0
- data/ext/stem_ISO_8859_1_norwegian.h +16 -0
- data/ext/stem_ISO_8859_1_porter.c +776 -0
- data/ext/stem_ISO_8859_1_porter.h +16 -0
- data/ext/stem_ISO_8859_1_portuguese.c +1035 -0
- data/ext/stem_ISO_8859_1_portuguese.h +16 -0
- data/ext/stem_ISO_8859_1_spanish.c +1119 -0
- data/ext/stem_ISO_8859_1_spanish.h +16 -0
- data/ext/stem_ISO_8859_1_swedish.c +307 -0
- data/ext/stem_ISO_8859_1_swedish.h +16 -0
- data/ext/stem_KOI8_R_russian.c +701 -0
- data/ext/stem_KOI8_R_russian.h +16 -0
- data/ext/stem_UTF_8_danish.c +344 -0
- data/ext/stem_UTF_8_danish.h +16 -0
- data/ext/stem_UTF_8_dutch.c +653 -0
- data/ext/stem_UTF_8_dutch.h +16 -0
- data/ext/stem_UTF_8_english.c +1176 -0
- data/ext/stem_UTF_8_english.h +16 -0
- data/ext/stem_UTF_8_finnish.c +808 -0
- data/ext/stem_UTF_8_finnish.h +16 -0
- data/ext/stem_UTF_8_french.c +1296 -0
- data/ext/stem_UTF_8_french.h +16 -0
- data/ext/stem_UTF_8_german.c +526 -0
- data/ext/stem_UTF_8_german.h +16 -0
- data/ext/stem_UTF_8_italian.c +1113 -0
- data/ext/stem_UTF_8_italian.h +16 -0
- data/ext/stem_UTF_8_norwegian.c +302 -0
- data/ext/stem_UTF_8_norwegian.h +16 -0
- data/ext/stem_UTF_8_porter.c +794 -0
- data/ext/stem_UTF_8_porter.h +16 -0
- data/ext/stem_UTF_8_portuguese.c +1055 -0
- data/ext/stem_UTF_8_portuguese.h +16 -0
- data/ext/stem_UTF_8_russian.c +709 -0
- data/ext/stem_UTF_8_russian.h +16 -0
- data/ext/stem_UTF_8_spanish.c +1137 -0
- data/ext/stem_UTF_8_spanish.h +16 -0
- data/ext/stem_UTF_8_swedish.c +313 -0
- data/ext/stem_UTF_8_swedish.h +16 -0
- data/ext/stopwords.c +325 -0
- data/ext/store.c +34 -2
- data/ext/tags +2953 -0
- data/ext/term.c +21 -15
- data/ext/termdocs.c +5 -3
- data/ext/utilities.c +446 -0
- data/ext/vector.c +27 -13
- data/lib/ferret/document/document.rb +1 -1
- data/lib/ferret/index/index.rb +44 -6
- data/lib/ferret/query_parser/query_parser.tab.rb +7 -3
- data/lib/rferret.rb +2 -1
- data/test/test_helper.rb +2 -2
- data/test/unit/analysis/ctc_analyzer.rb +401 -0
- data/test/unit/analysis/ctc_tokenstream.rb +423 -0
- data/test/unit/analysis/{tc_letter_tokenizer.rb → rtc_letter_tokenizer.rb} +0 -0
- data/test/unit/analysis/{tc_lower_case_filter.rb → rtc_lower_case_filter.rb} +0 -0
- data/test/unit/analysis/{tc_lower_case_tokenizer.rb → rtc_lower_case_tokenizer.rb} +0 -0
- data/test/unit/analysis/{tc_per_field_analyzer_wrapper.rb → rtc_per_field_analyzer_wrapper.rb} +0 -0
- data/test/unit/analysis/{tc_porter_stem_filter.rb → rtc_porter_stem_filter.rb} +0 -0
- data/test/unit/analysis/{tc_standard_analyzer.rb → rtc_standard_analyzer.rb} +0 -0
- data/test/unit/analysis/{tc_standard_tokenizer.rb → rtc_standard_tokenizer.rb} +0 -0
- data/test/unit/analysis/{tc_stop_analyzer.rb → rtc_stop_analyzer.rb} +0 -0
- data/test/unit/analysis/{tc_stop_filter.rb → rtc_stop_filter.rb} +0 -0
- data/test/unit/analysis/{tc_white_space_analyzer.rb → rtc_white_space_analyzer.rb} +0 -0
- data/test/unit/analysis/{tc_white_space_tokenizer.rb → rtc_white_space_tokenizer.rb} +0 -0
- data/test/unit/analysis/{tc_word_list_loader.rb → rtc_word_list_loader.rb} +0 -0
- data/test/unit/analysis/tc_analyzer.rb +1 -2
- data/test/unit/analysis/{c_token.rb → tc_token.rb} +0 -0
- data/test/unit/document/rtc_field.rb +28 -0
- data/test/unit/document/{c_document.rb → tc_document.rb} +0 -0
- data/test/unit/document/tc_field.rb +82 -12
- data/test/unit/index/{tc_compound_file_io.rb → rtc_compound_file_io.rb} +0 -0
- data/test/unit/index/{tc_field_infos.rb → rtc_field_infos.rb} +0 -0
- data/test/unit/index/{tc_fields_io.rb → rtc_fields_io.rb} +0 -0
- data/test/unit/index/{tc_multiple_term_doc_pos_enum.rb → rtc_multiple_term_doc_pos_enum.rb} +0 -0
- data/test/unit/index/{tc_segment_infos.rb → rtc_segment_infos.rb} +0 -0
- data/test/unit/index/{tc_segment_term_docs.rb → rtc_segment_term_docs.rb} +0 -0
- data/test/unit/index/{tc_segment_term_enum.rb → rtc_segment_term_enum.rb} +0 -0
- data/test/unit/index/{tc_segment_term_vector.rb → rtc_segment_term_vector.rb} +0 -0
- data/test/unit/index/{tc_term_buffer.rb → rtc_term_buffer.rb} +0 -0
- data/test/unit/index/{tc_term_info.rb → rtc_term_info.rb} +0 -0
- data/test/unit/index/{tc_term_infos_io.rb → rtc_term_infos_io.rb} +0 -0
- data/test/unit/index/{tc_term_vectors_io.rb → rtc_term_vectors_io.rb} +0 -0
- data/test/unit/index/{c_index.rb → tc_index.rb} +26 -6
- data/test/unit/index/{c_index_reader.rb → tc_index_reader.rb} +0 -0
- data/test/unit/index/{c_index_writer.rb → tc_index_writer.rb} +0 -0
- data/test/unit/index/{c_term.rb → tc_term.rb} +0 -0
- data/test/unit/index/{c_term_voi.rb → tc_term_voi.rb} +0 -0
- data/test/unit/query_parser/{c_query_parser.rb → rtc_query_parser.rb} +14 -14
- data/test/unit/query_parser/tc_query_parser.rb +24 -16
- data/test/unit/search/{tc_similarity.rb → rtc_similarity.rb} +0 -0
- data/test/unit/search/rtc_sort_field.rb +14 -0
- data/test/unit/search/{c_filter.rb → tc_filter.rb} +11 -11
- data/test/unit/search/{c_fuzzy_query.rb → tc_fuzzy_query.rb} +0 -0
- data/test/unit/search/{c_index_searcher.rb → tc_index_searcher.rb} +0 -0
- data/test/unit/search/{c_search_and_sort.rb → tc_search_and_sort.rb} +0 -0
- data/test/unit/search/{c_sort.rb → tc_sort.rb} +0 -0
- data/test/unit/search/tc_sort_field.rb +20 -7
- data/test/unit/search/{c_spans.rb → tc_spans.rb} +0 -0
- data/test/unit/store/rtc_fs_store.rb +62 -0
- data/test/unit/store/rtc_ram_store.rb +15 -0
- data/test/unit/store/rtm_store.rb +150 -0
- data/test/unit/store/rtm_store_lock.rb +2 -0
- data/test/unit/store/tc_fs_store.rb +54 -40
- data/test/unit/store/tc_ram_store.rb +20 -0
- data/test/unit/store/tm_store.rb +30 -146
- data/test/unit/store/tm_store_lock.rb +66 -0
- data/test/unit/utils/{tc_bit_vector.rb → rtc_bit_vector.rb} +0 -0
- data/test/unit/utils/{tc_date_tools.rb → rtc_date_tools.rb} +0 -0
- data/test/unit/utils/{tc_number_tools.rb → rtc_number_tools.rb} +0 -0
- data/test/unit/utils/{tc_parameter.rb → rtc_parameter.rb} +0 -0
- data/test/unit/utils/{tc_priority_queue.rb → rtc_priority_queue.rb} +0 -0
- data/test/unit/utils/{tc_string_helper.rb → rtc_string_helper.rb} +0 -0
- data/test/unit/utils/{tc_thread.rb → rtc_thread.rb} +0 -0
- data/test/unit/utils/{tc_weak_key_hash.rb → rtc_weak_key_hash.rb} +0 -0
- metadata +360 -289
- data/test/unit/document/c_field.rb +0 -98
- data/test/unit/search/c_sort_field.rb +0 -27
- data/test/unit/store/c_fs_store.rb +0 -76
- data/test/unit/store/c_ram_store.rb +0 -35
- data/test/unit/store/m_store.rb +0 -34
- data/test/unit/store/m_store_lock.rb +0 -68
@@ -88,17 +88,17 @@ class FilterTest < Test::Unit::TestCase
|
|
88
88
|
do_test_top_docs(is, q, [1,3,5,7,9], qf)
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
91
|
+
def test_filtered_query
|
92
|
+
is = IndexSearcher.new(@dir)
|
93
|
+
q = MatchAllQuery.new()
|
94
|
+
rf = RangeFilter.new("int", "2", "6", true, true)
|
95
|
+
rq = FilteredQuery.new(q, rf)
|
96
|
+
qf = QueryFilter.new(TermQuery.new(Term.new("switch", "on")))
|
97
|
+
do_test_top_docs(is, rq, [2,4,6], qf)
|
98
|
+
query = FilteredQuery.new(rq, qf)
|
99
|
+
rf2 = RangeFilter.new_more("int", "3")
|
100
|
+
do_test_top_docs(is, query, [4,6], rf2)
|
101
|
+
end
|
102
102
|
#def test_filtered_query
|
103
103
|
# is = IndexSearcher.new(@dir)
|
104
104
|
# q = MatchAllQuery.new()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -3,12 +3,25 @@ require File.dirname(__FILE__) + "/../../test_helper"
|
|
3
3
|
class SortFieldTest < Test::Unit::TestCase
|
4
4
|
include Ferret::Search
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
assert_equal(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
def test_field_score()
|
7
|
+
fs = SortField::FIELD_SCORE
|
8
|
+
assert_equal(SortField::SortType::SCORE, fs.sort_type)
|
9
|
+
assert_nil(fs.name)
|
10
|
+
assert(!fs.reverse?, "FIELD_SCORE should not be reverse")
|
11
|
+
assert_nil(fs.comparator)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_field_doc()
|
15
|
+
fs = SortField::FIELD_DOC
|
16
|
+
assert_equal(SortField::SortType::DOC, fs.sort_type)
|
17
|
+
assert_nil(fs.name)
|
18
|
+
assert(!fs.reverse?, "FIELD_DOC should not be reverse")
|
19
|
+
assert_nil(fs.comparator)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_error_raised()
|
23
|
+
assert_raise(ArgumentError) {
|
24
|
+
fs = SortField.new(nil, {:sort_type => SortField::SortType::INTEGER})
|
25
|
+
}
|
13
26
|
end
|
14
27
|
end
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
2
|
+
require File.dirname(__FILE__) + "/rtm_store"
|
3
|
+
require File.dirname(__FILE__) + "/rtm_store_lock"
|
4
|
+
|
5
|
+
module Ferret::Store
|
6
|
+
|
7
|
+
class FSDirectory
|
8
|
+
def FSDirectory.directory_cache
|
9
|
+
@@Directories
|
10
|
+
end
|
11
|
+
|
12
|
+
def ref_count
|
13
|
+
@ref_count
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_lock_prefix
|
17
|
+
lock_prefix
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FSStoreTest < Test::Unit::TestCase
|
23
|
+
include Ferret::Store
|
24
|
+
include StoreTest
|
25
|
+
include StoreLockTest
|
26
|
+
def setup
|
27
|
+
@dpath = File.join(File.dirname(__FILE__),
|
28
|
+
'../../temp/fsdir')
|
29
|
+
@dir = FSDirectory.new(@dpath, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
@dir.refresh()
|
34
|
+
@dir.close()
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_cache
|
38
|
+
dir_path = File.join(File.dirname(__FILE__),
|
39
|
+
'/../../temp/cachetest')
|
40
|
+
assert(! FSDirectory.directory_cache[dir_path],
|
41
|
+
"this directory should not be cached yet")
|
42
|
+
@dir1 = FSDirectory.new(dir_path, true)
|
43
|
+
assert(FSDirectory.directory_cache[dir_path],
|
44
|
+
"this directory should now be cached")
|
45
|
+
assert_equal(@dir1.ref_count, 1,
|
46
|
+
"There is one reference so the refcount should now be 1")
|
47
|
+
@dir2 = FSDirectory.new(dir_path, true)
|
48
|
+
assert(@dir1 === @dir2,
|
49
|
+
"The directory should be cached so the same directory object should have been returned")
|
50
|
+
assert_equal(@dir1.ref_count, 2,
|
51
|
+
"There are two references so the refcount should now be 2")
|
52
|
+
@dir1.close
|
53
|
+
assert(FSDirectory.directory_cache[dir_path],
|
54
|
+
"this directory shouldn't have been removed yet")
|
55
|
+
assert_equal(@dir2.ref_count, 1,
|
56
|
+
"There is one reference so the refcount should now be 1")
|
57
|
+
@dir2.close
|
58
|
+
assert(! FSDirectory.directory_cache[dir_path],
|
59
|
+
"this directory should have been removed from the cache")
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
2
|
+
require File.dirname(__FILE__) + "/rtm_store"
|
3
|
+
require File.dirname(__FILE__) + "/rtm_store_lock"
|
4
|
+
|
5
|
+
class RAMStoreTest < Test::Unit::TestCase
|
6
|
+
include StoreTest
|
7
|
+
include StoreLockTest
|
8
|
+
def setup
|
9
|
+
@dir = Ferret::Store::RAMDirectory.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@dir.close()
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module StoreTest
|
2
|
+
# declare dir so inheritors can access it.
|
3
|
+
@dir = nil
|
4
|
+
|
5
|
+
def test_modified
|
6
|
+
# difficult to test this one but as file mtime is only stored to the nearest second.
|
7
|
+
# we can assume this test will happen in less than a few seconds. (I hope)
|
8
|
+
time = Time.new.to_i
|
9
|
+
@dir.touch('mtime.test')
|
10
|
+
time_before = @dir.modified('mtime.test').to_i
|
11
|
+
assert(time_before - time <= 3,
|
12
|
+
"test that mtime is approximately equal to the system time when the file was touched")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_rw_bytes
|
16
|
+
bytes = [0x34, 0x87, 0xF9, 0xEA, 0x00, 0xFF]
|
17
|
+
rw_test(bytes, "byte", 6)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_rw_ints
|
21
|
+
ints = [-2147483648, 2147483647, -1, 0]
|
22
|
+
rw_test(ints, "int", 16)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_rw_longs
|
26
|
+
longs = [-9223372036854775808, 9223372036854775807, -1, 0]
|
27
|
+
rw_test(longs, "long", 32)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_rw_uints
|
31
|
+
uints = [0xffffffff, 100000, 0]
|
32
|
+
rw_test(uints, "uint", 12)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_rw_ulongs
|
36
|
+
ulongs = [0xffffffffffffffff, 100000000000000, 0]
|
37
|
+
rw_test(ulongs, "ulong", 24)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_rw_vints
|
41
|
+
vints = [ 9223372036854775807,
|
42
|
+
0x00,
|
43
|
+
0xFFFFFFFFFFFFFFFF]
|
44
|
+
rw_test(vints, "vint", 20)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_rw_vlongs
|
48
|
+
vlongs = [ 9223372036854775807,
|
49
|
+
0x00,
|
50
|
+
0xFFFFFFFFFFFFFFFF]
|
51
|
+
rw_test(vlongs, "vlong", 20)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_rw_strings
|
55
|
+
text = 'This is a ruby ferret test string ~!@#$%^&*()`123456790-=\)_+|'
|
56
|
+
ostream = @dir.create_output("rw_strings.test")
|
57
|
+
ostream.write_string(text)
|
58
|
+
ostream.write_string(text*100)
|
59
|
+
ostream.close
|
60
|
+
istream = @dir.open_input("rw_strings.test")
|
61
|
+
assert_equal(text, istream.read_string, "Short string test failed")
|
62
|
+
assert_equal(text*100, istream.read_string, "Short string test failed")
|
63
|
+
istream.close
|
64
|
+
assert_equal(6265, @dir.length('rw_strings.test'))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_rw_utf8_strings
|
68
|
+
text = '³³ ÄÄÄÄÄÄ 道德經'
|
69
|
+
ostream = @dir.create_output("rw_utf8_strings.test")
|
70
|
+
ostream.write_string(text)
|
71
|
+
ostream.write_string(text*100)
|
72
|
+
ostream.close
|
73
|
+
istream = @dir.open_input("rw_utf8_strings.test")
|
74
|
+
assert_equal(text, x = istream.read_string, "Short string test failed")
|
75
|
+
assert_equal(text*100, istream.read_string, "Short string test failed")
|
76
|
+
istream.close
|
77
|
+
end
|
78
|
+
|
79
|
+
# this test fills up the output stream so that the buffer will have to be
|
80
|
+
# written a few times. It then uses seek to make sure that it works
|
81
|
+
# correctly
|
82
|
+
def test_buffer_seek
|
83
|
+
ostream = @dir.create_output("rw_seek.test")
|
84
|
+
text = 'This is another long test string !@#$%#$%&%$*%^&*()(_'
|
85
|
+
1000.times {|i| ostream.write_long(i); ostream.write_string(text) }
|
86
|
+
ostream.seek(987)
|
87
|
+
assert_equal(987, ostream.pos)
|
88
|
+
ostream.write_vint(555)
|
89
|
+
ostream.seek(56)
|
90
|
+
assert_equal(56, ostream.pos)
|
91
|
+
ostream.write_vint(1234567890)
|
92
|
+
ostream.seek(4000)
|
93
|
+
assert_equal(4000, ostream.pos)
|
94
|
+
ostream.write_vint(9876543210)
|
95
|
+
ostream.close()
|
96
|
+
istream = @dir.open_input("rw_seek.test")
|
97
|
+
istream.seek(56)
|
98
|
+
assert_equal(56, istream.pos)
|
99
|
+
assert_equal(1234567890, istream.read_vint())
|
100
|
+
istream.seek(4000)
|
101
|
+
assert_equal(4000, istream.pos)
|
102
|
+
assert_equal(9876543210, istream.read_vint())
|
103
|
+
istream.seek(987)
|
104
|
+
assert_equal(987, istream.pos)
|
105
|
+
assert_equal(555, istream.read_vint())
|
106
|
+
istream.close()
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_clone
|
110
|
+
ostream = @dir.create_output("clone_test")
|
111
|
+
10.times {|i| ostream.write_long(i) }
|
112
|
+
ostream.close
|
113
|
+
istream = @dir.open_input("clone_test")
|
114
|
+
istream.seek(24)
|
115
|
+
alt_istream = istream.clone
|
116
|
+
assert_equal(istream.pos, alt_istream.pos)
|
117
|
+
(3...10).each {|i| assert_equal(i, alt_istream.read_long) }
|
118
|
+
assert_equal(80, alt_istream.pos)
|
119
|
+
assert_equal(24, istream.pos)
|
120
|
+
alt_istream.close
|
121
|
+
(3...10).each {|i| assert_equal(i, istream.read_long) }
|
122
|
+
istream.close
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_read_bytes
|
126
|
+
str = "0000000000"
|
127
|
+
ostream = @dir.create_output("rw_read_bytes")
|
128
|
+
ostream.write_bytes("how are you doing?", 18)
|
129
|
+
ostream.close
|
130
|
+
istream = @dir.open_input("rw_read_bytes")
|
131
|
+
istream.read_bytes(str, 2, 4)
|
132
|
+
assert_equal("00how 0000", str)
|
133
|
+
istream.read_bytes(str, 1, 8)
|
134
|
+
assert_equal("0are you 0", str)
|
135
|
+
istream.close
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def rw_test(values, type, expected_length)
|
141
|
+
ostream = @dir.create_output("rw_#{type}.test")
|
142
|
+
values.each { |b| ostream.__send__("write_" + type, b) }
|
143
|
+
ostream.close
|
144
|
+
istream = @dir.open_input("rw_#{type}.test")
|
145
|
+
values.each { |b| assert_equal(b, istream.__send__("read_" + type), "#{type} should be equal") }
|
146
|
+
istream.close
|
147
|
+
assert_equal(expected_length, @dir.length("rw_#{type}.test"))
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
@@ -2,23 +2,6 @@ require File.dirname(__FILE__) + "/../../test_helper"
|
|
2
2
|
require File.dirname(__FILE__) + "/tm_store"
|
3
3
|
require File.dirname(__FILE__) + "/tm_store_lock"
|
4
4
|
|
5
|
-
module Ferret::Store
|
6
|
-
|
7
|
-
class FSDirectory
|
8
|
-
def FSDirectory.directory_cache
|
9
|
-
@@Directories
|
10
|
-
end
|
11
|
-
|
12
|
-
def ref_count
|
13
|
-
@ref_count
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_lock_prefix
|
17
|
-
lock_prefix
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
5
|
class FSStoreTest < Test::Unit::TestCase
|
23
6
|
include Ferret::Store
|
24
7
|
include StoreTest
|
@@ -27,6 +10,8 @@ class FSStoreTest < Test::Unit::TestCase
|
|
27
10
|
@dpath = File.join(File.dirname(__FILE__),
|
28
11
|
'../../temp/fsdir')
|
29
12
|
@dir = FSDirectory.new(@dpath, true)
|
13
|
+
@dir1 = FSDirectory.new(@dpath, true)
|
14
|
+
@dir2 = FSDirectory.new(@dpath, true)
|
30
15
|
end
|
31
16
|
|
32
17
|
def teardown
|
@@ -34,29 +19,58 @@ class FSStoreTest < Test::Unit::TestCase
|
|
34
19
|
@dir.close()
|
35
20
|
end
|
36
21
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
assert(!
|
41
|
-
|
42
|
-
|
43
|
-
assert(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
"
|
57
|
-
|
58
|
-
assert(! FSDirectory.directory_cache[dir_path],
|
59
|
-
"this directory should have been removed from the cache")
|
22
|
+
def test_fslock
|
23
|
+
lock_name = "lfile"
|
24
|
+
lock_file_path = make_lock_file_path(lock_name)
|
25
|
+
assert(! File.exists?(lock_file_path), "There should be no lock file")
|
26
|
+
lock = @dir.make_lock(lock_name)
|
27
|
+
assert(! File.exists?(lock_file_path), "There should still be no lock file")
|
28
|
+
assert(! lock.locked?, "lock shouldn't be locked yet")
|
29
|
+
|
30
|
+
lock.obtain
|
31
|
+
|
32
|
+
assert(lock.locked?, "lock should now be locked")
|
33
|
+
|
34
|
+
assert(File.exists?(lock_file_path), "A lock file should have been created")
|
35
|
+
|
36
|
+
assert(! @dir.exists?(lock_file_path),
|
37
|
+
"The lock should be hidden by the FSDirectories directory scan")
|
38
|
+
|
39
|
+
lock.release
|
40
|
+
|
41
|
+
assert(! lock.locked?, "lock should be freed again")
|
42
|
+
assert(! File.exists?(lock_file_path), "The lock file should have been deleted")
|
60
43
|
end
|
61
44
|
|
45
|
+
# def make_and_loose_lock
|
46
|
+
# lock = @dir.make_lock("finalizer_lock")
|
47
|
+
# lock.obtain
|
48
|
+
# lock = nil
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def test_fslock_finalizer
|
52
|
+
# lock_name = "finalizer_lock"
|
53
|
+
# lock_file_path = make_lock_file_path(lock_name)
|
54
|
+
# assert(! File.exists?(lock_file_path), "There should be no lock file")
|
55
|
+
#
|
56
|
+
# make_and_loose_lock
|
57
|
+
#
|
58
|
+
# #assert(File.exists?(lock_file_path), "There should now be a lock file")
|
59
|
+
#
|
60
|
+
# lock = @dir.make_lock(lock_name)
|
61
|
+
# assert(lock.locked?, "lock should now be locked")
|
62
|
+
#
|
63
|
+
# GC.start
|
64
|
+
#
|
65
|
+
# assert(! lock.locked?, "lock should be freed again")
|
66
|
+
# assert(! File.exists?(lock_file_path), "The lock file should have been deleted")
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
def make_lock_file_path(name)
|
70
|
+
lock_file_path = File.join(@dpath, "ferret-#{name}.lck")
|
71
|
+
if File.exists?(lock_file_path) then
|
72
|
+
File.delete(lock_file_path)
|
73
|
+
end
|
74
|
+
return lock_file_path
|
75
|
+
end
|
62
76
|
end
|
@@ -12,4 +12,24 @@ class RAMStoreTest < Test::Unit::TestCase
|
|
12
12
|
def teardown
|
13
13
|
@dir.close()
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_ramlock
|
17
|
+
name = "lfile"
|
18
|
+
lfile = Ferret::Store::Directory::LOCK_PREFIX + name + ".lck"
|
19
|
+
assert(! @dir.exists?(lfile),
|
20
|
+
"There should be no lock file")
|
21
|
+
lock = @dir.make_lock(name)
|
22
|
+
assert(! @dir.exists?(lfile),
|
23
|
+
"There should still be no lock file")
|
24
|
+
assert(! @dir.exists?(lfile),
|
25
|
+
"The lock should be hidden by the FSDirectories directory scan")
|
26
|
+
assert(! lock.locked?, "lock shouldn't be locked yet")
|
27
|
+
lock.obtain
|
28
|
+
assert(lock.locked?, "lock should now be locked")
|
29
|
+
assert(@dir.exists?(lfile), "A lock file should have been created")
|
30
|
+
lock.release
|
31
|
+
assert(! lock.locked?, "lock should be freed again")
|
32
|
+
assert(! @dir.exists?(lfile),
|
33
|
+
"The lock file should have been deleted")
|
34
|
+
end
|
15
35
|
end
|
data/test/unit/store/tm_store.rb
CHANGED
@@ -1,150 +1,34 @@
|
|
1
1
|
module StoreTest
|
2
2
|
# declare dir so inheritors can access it.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_rw_ulongs
|
36
|
-
ulongs = [0xffffffffffffffff, 100000000000000, 0]
|
37
|
-
rw_test(ulongs, "ulong", 24)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_rw_vints
|
41
|
-
vints = [ 9223372036854775807,
|
42
|
-
0x00,
|
43
|
-
0xFFFFFFFFFFFFFFFF]
|
44
|
-
rw_test(vints, "vint", 20)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_rw_vlongs
|
48
|
-
vlongs = [ 9223372036854775807,
|
49
|
-
0x00,
|
50
|
-
0xFFFFFFFFFFFFFFFF]
|
51
|
-
rw_test(vlongs, "vlong", 20)
|
3
|
+
attr_accessor :dir
|
4
|
+
|
5
|
+
# test the basic file manipulation methods;
|
6
|
+
# - exists?
|
7
|
+
# - touch
|
8
|
+
# - delete
|
9
|
+
# - file_count
|
10
|
+
def test_basic_file_ops
|
11
|
+
assert_equal(0, @dir.file_count(), "directory should be empty")
|
12
|
+
assert(! @dir.exists?('filename'), "File should not exist")
|
13
|
+
@dir.touch('tmpfile1')
|
14
|
+
assert_equal(1, @dir.file_count(), "directory should have one file")
|
15
|
+
@dir.touch('tmpfile2')
|
16
|
+
assert_equal(2, @dir.file_count(), "directory should have two files")
|
17
|
+
assert(@dir.exists?('tmpfile1'), "'tmpfile1' should exist")
|
18
|
+
@dir.delete('tmpfile1')
|
19
|
+
assert(! @dir.exists?('tmpfile1'), "'tmpfile1' should no longer exist")
|
20
|
+
assert_equal(1, @dir.file_count(), "directory should have one file")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_rename
|
24
|
+
@dir.touch("from")
|
25
|
+
assert(@dir.exists?('from'), "File should exist")
|
26
|
+
assert(! @dir.exists?('to'), "File should not exist")
|
27
|
+
cnt_before = @dir.file_count()
|
28
|
+
@dir.rename('from', 'to')
|
29
|
+
cnt_after = @dir.file_count()
|
30
|
+
assert_equal(cnt_before, cnt_after, "the number of files shouldn't have changed")
|
31
|
+
assert(@dir.exists?('to'), "File should now exist")
|
32
|
+
assert(! @dir.exists?('from'), "File should no longer exist")
|
52
33
|
end
|
53
|
-
|
54
|
-
def test_rw_strings
|
55
|
-
text = 'This is a ruby ferret test string ~!@#$%^&*()`123456790-=\)_+|'
|
56
|
-
ostream = @dir.create_output("rw_strings.test")
|
57
|
-
ostream.write_string(text)
|
58
|
-
ostream.write_string(text*100)
|
59
|
-
ostream.close
|
60
|
-
istream = @dir.open_input("rw_strings.test")
|
61
|
-
assert_equal(text, istream.read_string, "Short string test failed")
|
62
|
-
assert_equal(text*100, istream.read_string, "Short string test failed")
|
63
|
-
istream.close
|
64
|
-
assert_equal(6265, @dir.length('rw_strings.test'))
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_rw_utf8_strings
|
68
|
-
text = '³³ ÄÄÄÄÄÄ 道德經'
|
69
|
-
ostream = @dir.create_output("rw_utf8_strings.test")
|
70
|
-
ostream.write_string(text)
|
71
|
-
ostream.write_string(text*100)
|
72
|
-
ostream.close
|
73
|
-
istream = @dir.open_input("rw_utf8_strings.test")
|
74
|
-
assert_equal(text, x = istream.read_string, "Short string test failed")
|
75
|
-
assert_equal(text*100, istream.read_string, "Short string test failed")
|
76
|
-
istream.close
|
77
|
-
end
|
78
|
-
|
79
|
-
# this test fills up the output stream so that the buffer will have to be
|
80
|
-
# written a few times. It then uses seek to make sure that it works
|
81
|
-
# correctly
|
82
|
-
def test_buffer_seek
|
83
|
-
ostream = @dir.create_output("rw_seek.test")
|
84
|
-
text = 'This is another long test string !@#$%#$%&%$*%^&*()(_'
|
85
|
-
1000.times {|i| ostream.write_long(i); ostream.write_string(text) }
|
86
|
-
ostream.seek(987)
|
87
|
-
assert_equal(987, ostream.pos)
|
88
|
-
ostream.write_vint(555)
|
89
|
-
ostream.seek(56)
|
90
|
-
assert_equal(56, ostream.pos)
|
91
|
-
ostream.write_vint(1234567890)
|
92
|
-
ostream.seek(4000)
|
93
|
-
assert_equal(4000, ostream.pos)
|
94
|
-
ostream.write_vint(9876543210)
|
95
|
-
ostream.close()
|
96
|
-
istream = @dir.open_input("rw_seek.test")
|
97
|
-
istream.seek(56)
|
98
|
-
assert_equal(56, istream.pos)
|
99
|
-
assert_equal(1234567890, istream.read_vint())
|
100
|
-
istream.seek(4000)
|
101
|
-
assert_equal(4000, istream.pos)
|
102
|
-
assert_equal(9876543210, istream.read_vint())
|
103
|
-
istream.seek(987)
|
104
|
-
assert_equal(987, istream.pos)
|
105
|
-
assert_equal(555, istream.read_vint())
|
106
|
-
istream.close()
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_clone
|
110
|
-
ostream = @dir.create_output("clone_test")
|
111
|
-
10.times {|i| ostream.write_long(i) }
|
112
|
-
ostream.close
|
113
|
-
istream = @dir.open_input("clone_test")
|
114
|
-
istream.seek(24)
|
115
|
-
alt_istream = istream.clone
|
116
|
-
assert_equal(istream.pos, alt_istream.pos)
|
117
|
-
(3...10).each {|i| assert_equal(i, alt_istream.read_long) }
|
118
|
-
assert_equal(80, alt_istream.pos)
|
119
|
-
assert_equal(24, istream.pos)
|
120
|
-
alt_istream.close
|
121
|
-
(3...10).each {|i| assert_equal(i, istream.read_long) }
|
122
|
-
istream.close
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_read_bytes
|
126
|
-
str = "0000000000"
|
127
|
-
ostream = @dir.create_output("rw_read_bytes")
|
128
|
-
ostream.write_bytes("how are you doing?", 18)
|
129
|
-
ostream.close
|
130
|
-
istream = @dir.open_input("rw_read_bytes")
|
131
|
-
istream.read_bytes(str, 2, 4)
|
132
|
-
assert_equal("00how 0000", str)
|
133
|
-
istream.read_bytes(str, 1, 8)
|
134
|
-
assert_equal("0are you 0", str)
|
135
|
-
istream.close
|
136
|
-
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
def rw_test(values, type, expected_length)
|
141
|
-
ostream = @dir.create_output("rw_#{type}.test")
|
142
|
-
values.each { |b| ostream.__send__("write_" + type, b) }
|
143
|
-
ostream.close
|
144
|
-
istream = @dir.open_input("rw_#{type}.test")
|
145
|
-
values.each { |b| assert_equal(b, istream.__send__("read_" + type), "#{type} should be equal") }
|
146
|
-
istream.close
|
147
|
-
assert_equal(expected_length, @dir.length("rw_#{type}.test"))
|
148
|
-
end
|
149
|
-
|
150
34
|
end
|