xunch 0.0.6 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xunch/cache/cache.rb +10 -2
- data/lib/xunch/cache/cache_builder.rb +3 -0
- data/lib/xunch/cache/list_field_object_cache.rb +11 -7
- data/lib/xunch/cache/list_id_cache.rb +61 -0
- data/lib/xunch/cache/list_object_cache.rb +15 -7
- data/lib/xunch/shard/redis.rb +17 -5
- data/lib/xunch/shard/shard_redis.rb +6 -5
- data/lib/xunch/utils/nginx_cache_helper.rb +1 -1
- data/lib/xunch/utils/types.rb +1 -0
- data/lib/xunch.rb +1 -0
- data/test/cache_builder_test.rb +13 -3
- data/test/cache_test.rb +57 -0
- data/test/field_object_cache_test.rb +28 -84
- data/test/hash_codec_test.rb +41 -38
- data/test/json_codec_test.rb +83 -38
- data/test/list_field_object_cache_test.rb +11 -81
- data/test/list_id_cache_test.rb +75 -0
- data/test/list_object_cache_test.rb +11 -81
- data/test/nginx_cache_helper_test.rb +4 -0
- data/test/object_cache_test.rb +15 -82
- data/test/rb_tree_test.rb +63 -20
- data/test/{redis_test.rb → redis_client_test.rb} +8 -5
- metadata +10 -19
- data/test/benchmark_test.rb +0 -68
- data/test/cache_object.rb +0 -120
- data/test/consistency_hash_test.rb +0 -31
- data/test/redis_benchmark_test.rb +0 -54
- data/test/running_test.rb +0 -212
- data/test/test.rb +0 -176
- data/test/track_record_origin.rb +0 -58
data/test/object_cache_test.rb
CHANGED
@@ -3,9 +3,7 @@ $:.unshift File.expand_path("../../test", __FILE__)
|
|
3
3
|
require "test/unit"
|
4
4
|
require "xunch"
|
5
5
|
require 'yaml'
|
6
|
-
require '
|
7
|
-
require 'hessian2'
|
8
|
-
require 'track_record_origin'
|
6
|
+
require 'test_helper'
|
9
7
|
|
10
8
|
class ObjectCacheTest < Test::Unit::TestCase
|
11
9
|
include Test::Unit::Assertions
|
@@ -15,87 +13,15 @@ class ObjectCacheTest < Test::Unit::TestCase
|
|
15
13
|
file = File.join(root, 'test/xunch.yaml')
|
16
14
|
caches = Xunch::CacheBuilder.build(file)
|
17
15
|
@object_cache = caches["track"]
|
18
|
-
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
22
|
-
new_cache_object = TrackRecordOrigin.new
|
23
|
-
new_cache_object.track_id = @cache_object.track_id
|
24
|
-
new_cache_object.track_uid = @cache_object.track_uid
|
25
|
-
new_cache_object.track_upload_source = @cache_object.track_upload_source
|
26
|
-
new_cache_object.op_type = @cache_object.op_type
|
27
|
-
new_cache_object.is_publish = @cache_object.is_publish
|
28
|
-
new_cache_object.upload_source = @cache_object.upload_source
|
29
|
-
new_cache_object.uid = @cache_object.uid
|
30
|
-
new_cache_object.nickname = @cache_object.nickname
|
31
|
-
new_cache_object.avatar_path = @cache_object.avatar_path
|
32
|
-
new_cache_object.is_v = @cache_object.is_v
|
33
|
-
new_cache_object.human_category_id = @cache_object.human_category_id
|
34
|
-
new_cache_object.title = @cache_object.title
|
35
|
-
new_cache_object.intro = @cache_object.intro
|
36
|
-
new_cache_object.user_source = @cache_object.user_source
|
37
|
-
new_cache_object.category_id = @cache_object.category_id
|
38
|
-
new_cache_object.duration = @cache_object.duration
|
39
|
-
new_cache_object.play_path = @cache_object.play_path
|
40
|
-
new_cache_object.play_path_32 = @cache_object.play_path_32
|
41
|
-
new_cache_object.play_path_64 = @cache_object.play_path_64
|
42
|
-
new_cache_object.play_path_128 = @cache_object.play_path_128
|
43
|
-
new_cache_object.transcode_state = @cache_object.transcode_state
|
44
|
-
new_cache_object.download_path = @cache_object.download_path
|
45
|
-
new_cache_object.cover_path = @cache_object.cover_path
|
46
|
-
new_cache_object.album_id = @cache_object.album_id
|
47
|
-
new_cache_object.album_title = @cache_object.album_title
|
48
|
-
new_cache_object.album_cover_path = @cache_object.album_cover_path
|
49
|
-
new_cache_object.tags = @cache_object.tags
|
50
|
-
new_cache_object.ignore_tags = @cache_object.ignore_tags
|
51
|
-
new_cache_object.extra_tags = @cache_object.extra_tags
|
52
|
-
new_cache_object.singer = @cache_object.singer
|
53
|
-
new_cache_object.singer_category = @cache_object.singer_category
|
54
|
-
new_cache_object.author = @cache_object.author
|
55
|
-
new_cache_object.composer = @cache_object.composer
|
56
|
-
new_cache_object.arrangement = @cache_object.arrangement
|
57
|
-
new_cache_object.post_production = @cache_object.post_production
|
58
|
-
new_cache_object.lyric_path = @cache_object.lyric_path
|
59
|
-
new_cache_object.lyric = @cache_object.lyric
|
60
|
-
new_cache_object.language = @cache_object.language
|
61
|
-
new_cache_object.resinger = @cache_object.resinger
|
62
|
-
new_cache_object.announcer = @cache_object.announcer
|
63
|
-
new_cache_object.is_public = @cache_object.is_public
|
64
|
-
new_cache_object.access_password = @cache_object.access_password
|
65
|
-
new_cache_object.allow_download = @cache_object.allow_download
|
66
|
-
new_cache_object.allow_comment = @cache_object.allow_comment
|
67
|
-
new_cache_object.is_crawler = @cache_object.is_crawler
|
68
|
-
new_cache_object.inet_aton_ip = @cache_object.inet_aton_ip
|
69
|
-
new_cache_object.longitude = @cache_object.longitude
|
70
|
-
new_cache_object.latitude = @cache_object.latitude
|
71
|
-
new_cache_object.music_category = @cache_object.music_category
|
72
|
-
new_cache_object.order_num = @cache_object.order_num
|
73
|
-
new_cache_object.is_pick = @cache_object.is_pick
|
74
|
-
new_cache_object.rich_intro = @cache_object.rich_intro
|
75
|
-
new_cache_object.short_intro = @cache_object.short_intro
|
76
|
-
new_cache_object.comment_content = @cache_object.comment_content
|
77
|
-
new_cache_object.comment_id = @cache_object.comment_id
|
78
|
-
new_cache_object.dig_status = @cache_object.dig_status
|
79
|
-
new_cache_object.approved_at = @cache_object.approved_at
|
80
|
-
new_cache_object.is_deleted = @cache_object.is_deleted
|
81
|
-
new_cache_object.mp3size = @cache_object.mp3size
|
82
|
-
new_cache_object.mp3size_32 = @cache_object.mp3size_32
|
83
|
-
new_cache_object.mp3size_64 = @cache_object.mp3size_64
|
84
|
-
new_cache_object.waveform = @cache_object.waveform
|
85
|
-
new_cache_object.upload_id = @cache_object.upload_id
|
86
|
-
new_cache_object.updated_at = @cache_object.updated_at
|
87
|
-
new_cache_object.created_at = @cache_object.created_at
|
88
|
-
new_cache_object.source_url = @cache_object.source_url
|
89
|
-
new_cache_object.status = @cache_object.status
|
90
|
-
new_cache_object.explore_height = @cache_object.explore_height
|
91
|
-
new_cache_object.id = i
|
92
|
-
@cache_objects.push new_cache_object
|
93
|
-
@keys.push new_cache_object.id
|
94
|
-
end
|
16
|
+
hash = TestHelper.build_objects
|
17
|
+
@cache_object = hash["object"]
|
18
|
+
@cache_objects = hash["objects"]
|
19
|
+
@keys = hash["keys"]
|
95
20
|
puts "setup"
|
96
21
|
end
|
97
22
|
|
98
23
|
def test_get_set
|
24
|
+
puts "ObjectCacheTest test_get_set method start"
|
99
25
|
assert_equal('OK',@object_cache.put(@cache_object))
|
100
26
|
object = @object_cache.get(1)
|
101
27
|
|
@@ -180,11 +106,13 @@ class ObjectCacheTest < Test::Unit::TestCase
|
|
180
106
|
assert_equal(@cache_object.status,object.status)
|
181
107
|
assert_equal(@cache_object.explore_height,object.explore_height)
|
182
108
|
assert_equal(@cache_object.id,object.id)
|
109
|
+
puts "ObjectCacheTest test_get_set method stop"
|
183
110
|
end
|
184
111
|
|
185
112
|
def test_get_set_benchmark
|
113
|
+
puts "ObjectCacheTest test_get_set_benchmark method start"
|
186
114
|
@object_cache.evict(1)
|
187
|
-
times =
|
115
|
+
times = TestHelper::TIMES
|
188
116
|
start = Time.now
|
189
117
|
for i in 1 .. times do
|
190
118
|
@object_cache.put(@cache_object)
|
@@ -198,9 +126,11 @@ class ObjectCacheTest < Test::Unit::TestCase
|
|
198
126
|
end
|
199
127
|
stop = Time.now
|
200
128
|
puts "#{times} times get operation total use #{stop-start} seconds"
|
129
|
+
puts "ObjectCacheTest test_get_set_benchmark method stop"
|
201
130
|
end
|
202
131
|
|
203
132
|
def test_mget_mset
|
133
|
+
puts "ObjectCacheTest test_mget_mset method start"
|
204
134
|
result = @object_cache.multi_put(@cache_objects)
|
205
135
|
for i in 0 .. result.length - 1 do
|
206
136
|
success = false
|
@@ -293,12 +223,14 @@ class ObjectCacheTest < Test::Unit::TestCase
|
|
293
223
|
assert_equal(@cache_objects[i].explore_height,objects[i].explore_height)
|
294
224
|
assert_equal(@cache_objects[i].id,objects[i].id)
|
295
225
|
end
|
226
|
+
puts "ObjectCacheTest test_mget_mset method stop"
|
296
227
|
end
|
297
228
|
|
298
229
|
def test_mget_mset_benchmark
|
230
|
+
puts "ObjectCacheTest test_mget_mset_benchmark method start"
|
299
231
|
@object_cache.batch_evict @keys
|
300
232
|
|
301
|
-
times =
|
233
|
+
times = TestHelper::TIMES
|
302
234
|
start = Time.now
|
303
235
|
for i in 1 .. times do
|
304
236
|
@object_cache.multi_put(@cache_objects)
|
@@ -312,6 +244,7 @@ class ObjectCacheTest < Test::Unit::TestCase
|
|
312
244
|
end
|
313
245
|
stop = Time.now
|
314
246
|
puts "#{times} times multi_get operation total use #{stop-start} seconds"
|
247
|
+
puts "ObjectCacheTest test_mget_mset_benchmark method stop"
|
315
248
|
end
|
316
249
|
|
317
250
|
def teardown
|
data/test/rb_tree_test.rb
CHANGED
@@ -11,6 +11,7 @@ class RBTreeTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_rb_tree
|
14
|
+
puts "RBTreeTest test_rb_tree method start"
|
14
15
|
tree = Xunch::RBTree.new
|
15
16
|
|
16
17
|
tree.put(1,"1")
|
@@ -19,26 +20,68 @@ class RBTreeTest < Test::Unit::TestCase
|
|
19
20
|
tree.put(7,"7")
|
20
21
|
tree.put(9,"9")
|
21
22
|
tree.put(11,"11")
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
23
|
+
|
24
|
+
assert_equal(6,tree.size)
|
25
|
+
assert_equal("1",tree.first_node.value)
|
26
|
+
assert_equal("11",tree.last_node.value)
|
27
|
+
|
28
|
+
assert_equal("1",tree.ceiling_node(0).value)
|
29
|
+
assert_equal("1",tree.ceiling_node(1).value)
|
30
|
+
assert_equal("3",tree.ceiling_node(2).value)
|
31
|
+
assert_equal("3",tree.ceiling_node(3).value)
|
32
|
+
assert_equal("5",tree.ceiling_node(4).value)
|
33
|
+
assert_equal("5",tree.ceiling_node(5).value)
|
34
|
+
assert_equal("7",tree.ceiling_node(6).value)
|
35
|
+
assert_equal("7",tree.ceiling_node(7).value)
|
36
|
+
assert_equal("9",tree.ceiling_node(8).value)
|
37
|
+
assert_equal("9",tree.ceiling_node(9).value)
|
38
|
+
assert_equal("11",tree.ceiling_node(10).value)
|
39
|
+
assert_equal("11",tree.ceiling_node(11).value)
|
40
|
+
assert_equal(nil,tree.ceiling_node(12))
|
41
|
+
|
42
|
+
assert_equal("11",tree.floor_node(12).value)
|
43
|
+
assert_equal("11",tree.floor_node(11).value)
|
44
|
+
assert_equal("9",tree.floor_node(10).value)
|
45
|
+
assert_equal("9",tree.floor_node(9).value)
|
46
|
+
assert_equal("7",tree.floor_node(8).value)
|
47
|
+
assert_equal("7",tree.floor_node(7).value)
|
48
|
+
assert_equal("5",tree.floor_node(6).value)
|
49
|
+
assert_equal("5",tree.floor_node(5).value)
|
50
|
+
assert_equal("3",tree.floor_node(4).value)
|
51
|
+
assert_equal("3",tree.floor_node(3).value)
|
52
|
+
assert_equal("1",tree.floor_node(2).value)
|
53
|
+
assert_equal("1",tree.floor_node(1).value)
|
54
|
+
assert_equal(nil,tree.floor_node(0))
|
55
|
+
|
56
|
+
assert_equal("11",tree.lower_node(12).value)
|
57
|
+
assert_equal("9",tree.lower_node(11).value)
|
58
|
+
assert_equal("9",tree.lower_node(10).value)
|
59
|
+
assert_equal("7",tree.lower_node(9).value)
|
60
|
+
assert_equal("7",tree.lower_node(8).value)
|
61
|
+
assert_equal("5",tree.lower_node(7).value)
|
62
|
+
assert_equal("5",tree.lower_node(6).value)
|
63
|
+
assert_equal("3",tree.lower_node(5).value)
|
64
|
+
assert_equal("3",tree.lower_node(4).value)
|
65
|
+
assert_equal("1",tree.lower_node(3).value)
|
66
|
+
assert_equal("1",tree.lower_node(2).value)
|
67
|
+
assert_equal(nil,tree.lower_node(1))
|
68
|
+
assert_equal(nil,tree.lower_node(0))
|
69
|
+
|
70
|
+
assert_equal("1",tree.higher_node(0).value)
|
71
|
+
assert_equal("3",tree.higher_node(1).value)
|
72
|
+
assert_equal("3",tree.higher_node(2).value)
|
73
|
+
assert_equal("5",tree.higher_node(3).value)
|
74
|
+
assert_equal("5",tree.higher_node(4).value)
|
75
|
+
assert_equal("7",tree.higher_node(5).value)
|
76
|
+
assert_equal("7",tree.higher_node(6).value)
|
77
|
+
assert_equal("9",tree.higher_node(7).value)
|
78
|
+
assert_equal("9",tree.higher_node(8).value)
|
79
|
+
assert_equal("11",tree.higher_node(9).value)
|
80
|
+
assert_equal("11",tree.higher_node(10).value)
|
81
|
+
assert_equal(nil,tree.higher_node(11))
|
82
|
+
assert_equal(nil,tree.higher_node(12))
|
83
|
+
|
84
|
+
puts "RBTreeTest test_rb_tree method stop"
|
42
85
|
end
|
43
86
|
|
44
87
|
def teardown
|
@@ -21,19 +21,21 @@ class RedisTest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_redis
|
24
|
+
puts "RedisTest test_redis method start"
|
24
25
|
assert_equal('OK',@redis_client.set('key1','value1',100000))
|
25
26
|
assert(@redis_client.exists('key1'),"expect exists key1")
|
26
|
-
assert((@redis_client.ttl('key1')
|
27
|
+
assert((@redis_client.ttl('key1') == 100000),"expect ttl less than 100000")
|
27
28
|
assert(@redis_client.expire('key1',1000000))
|
28
|
-
assert(@redis_client.ttl('key1')>100000,"expect ttl more than 100000")
|
29
|
-
assert(@redis_client.ttl('key1')
|
29
|
+
# assert(@redis_client.ttl('key1') > 100000,"expect ttl more than 100000")
|
30
|
+
assert(@redis_client.ttl('key1') == 1000000,"expect ttl less than 1000000")
|
30
31
|
assert_equal('value1',@redis_client.get('key1'))
|
31
32
|
assert(@redis_client.del('key1'),"del key1 didn't success")
|
32
33
|
|
33
34
|
hash = {"k1"=>"v1","k2"=>"v2","k3"=>"v3","k4"=>"v4","k5"=>"v5"}
|
34
|
-
assert_equal(["OK",
|
35
|
+
assert_equal(["OK", "OK", "OK", "OK", "OK"],@redis_client.mset(hash,1000000))
|
36
|
+
assert_equal("OK",@redis_client.mset(hash,0))
|
35
37
|
|
36
|
-
assert_equal(["v1", "v2", "v3", "v4", "v5", nil],@redis_client.mget("k1","k2","k3","k4","k5","k6"))
|
38
|
+
assert_equal(["v1", "v2", "v3", "v4", "v5", nil],@redis_client.mget(["k1","k2","k3","k4","k5","k6"]))
|
37
39
|
|
38
40
|
fields = {"field1"=>"v1","field2"=>"v2","field3"=>"v3","field4"=>"v4","field5"=>"v5"}
|
39
41
|
fieldkeys = ["field1","field2","field3","field4","field5"]
|
@@ -48,6 +50,7 @@ class RedisTest < Test::Unit::TestCase
|
|
48
50
|
|
49
51
|
@redis_client.hmget(hashkeys,*fieldkeys)
|
50
52
|
|
53
|
+
puts "RedisTest test_redis method stop"
|
51
54
|
end
|
52
55
|
|
53
56
|
def teardown
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ted Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/xunch/cache/object_cache.rb
|
55
55
|
- lib/xunch/cache/cache.rb
|
56
56
|
- lib/xunch/cache/field_object_cache.rb
|
57
|
+
- lib/xunch/cache/list_id_cache.rb
|
57
58
|
- lib/xunch/utils/rb_tree.rb
|
58
59
|
- lib/xunch/utils/utils.rb
|
59
60
|
- lib/xunch/utils/types.rb
|
@@ -65,25 +66,20 @@ files:
|
|
65
66
|
- lib/xunch/codec/json_codec.rb
|
66
67
|
- lib/xunch.rb
|
67
68
|
- test/json_codec_test.rb
|
68
|
-
- test/
|
69
|
+
- test/cache_test.rb
|
69
70
|
- test/cache_builder_test.rb
|
70
|
-
- test/consistency_hash_test.rb
|
71
71
|
- test/rb_tree_test.rb
|
72
|
+
- test/redis_client_test.rb
|
72
73
|
- test/list_field_object_cache_test.rb
|
73
|
-
- test/
|
74
|
-
- test/benchmark_test.rb
|
75
|
-
- test/test.rb
|
74
|
+
- test/list_id_cache_test.rb
|
76
75
|
- test/hash_codec_test.rb
|
77
76
|
- test/nginx_cache_helper_test.rb
|
78
|
-
- test/running_test.rb
|
79
77
|
- test/object_cache_test.rb
|
80
78
|
- test/list_object_cache_test.rb
|
81
|
-
- test/redis_test.rb
|
82
79
|
- test/field_object_cache_test.rb
|
83
|
-
- test/track_record_origin.rb
|
84
80
|
homepage: http://www.ximalaya.com
|
85
81
|
licenses:
|
86
|
-
-
|
82
|
+
- Apache License Version 2.0
|
87
83
|
metadata: {}
|
88
84
|
post_install_message:
|
89
85
|
rdoc_options: []
|
@@ -107,19 +103,14 @@ specification_version: 4
|
|
107
103
|
summary: A distribute cache client library based on redis.
|
108
104
|
test_files:
|
109
105
|
- test/json_codec_test.rb
|
110
|
-
- test/
|
106
|
+
- test/cache_test.rb
|
111
107
|
- test/cache_builder_test.rb
|
112
|
-
- test/consistency_hash_test.rb
|
113
108
|
- test/rb_tree_test.rb
|
109
|
+
- test/redis_client_test.rb
|
114
110
|
- test/list_field_object_cache_test.rb
|
115
|
-
- test/
|
116
|
-
- test/benchmark_test.rb
|
117
|
-
- test/test.rb
|
111
|
+
- test/list_id_cache_test.rb
|
118
112
|
- test/hash_codec_test.rb
|
119
113
|
- test/nginx_cache_helper_test.rb
|
120
|
-
- test/running_test.rb
|
121
114
|
- test/object_cache_test.rb
|
122
115
|
- test/list_object_cache_test.rb
|
123
|
-
- test/redis_test.rb
|
124
116
|
- test/field_object_cache_test.rb
|
125
|
-
- test/track_record_origin.rb
|
data/test/benchmark_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
-
$:.unshift File.expand_path("../../test", __FILE__)
|
3
|
-
require "test/unit"
|
4
|
-
require "xunch"
|
5
|
-
require 'yaml'
|
6
|
-
require 'cache_object'
|
7
|
-
require 'bigdecimal'
|
8
|
-
require 'hessian2'
|
9
|
-
require 'track_record_origin'
|
10
|
-
|
11
|
-
DEFAULTS = {
|
12
|
-
:size => 1,
|
13
|
-
:timeout => nil,
|
14
|
-
:driver => :hiredis,
|
15
|
-
:host => '192.168.1.174',
|
16
|
-
:port=>6379,
|
17
|
-
:password=>'jredis123456',
|
18
|
-
:db=>14,
|
19
|
-
:timeout=>6
|
20
|
-
}
|
21
|
-
TrackInRecordStruct = Struct.new(:id, :track_id, :uid, :op_type, :nickname, :avatar_path, :is_v, :is_public, :is_publish, :user_source, :category_id, :title, :intro, :tags, :cover_path, :duration, :download_path, :play_path, :play_path_128, :play_path_64, :play_path_32, :singer, :singer_category, :author, :composer, :arrangement, :post_production, :lyric, :lyric_path, :language, :resinger, :announcer, :access_password, :allow_download, :allow_comment, :is_crawler, :inet_aton_ip, :upload_source, :longitude, :latitude, :album_id, :album_title, :album_cover_path, :transcode_state, :created_at, :updated_at, :rich_intro, :comment_content, :comment_id, :track_upload_source, :is_pick, :track_uid, :short_intro, :is_deleted, :dig_status, :approved_at, :mp3size, :mp3size_32, :mp3size_64, :upload_id, :waveform, :extra_tags, :ignore_tags, :music_category, :order_num, :source_url, :status, :human_category_id, :explore_height)
|
22
|
-
class ObjectCacheTest < Test::Unit::TestCase
|
23
|
-
include Test::Unit::Assertions
|
24
|
-
def setup
|
25
|
-
super
|
26
|
-
root = File.expand_path("../..", __FILE__)
|
27
|
-
file = File.join(root, 'test/xunch.yaml')
|
28
|
-
caches = Xunch::CacheBuilder.build(file)
|
29
|
-
@object_cache = caches["track"]
|
30
|
-
puts "setup"
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_benchmark
|
34
|
-
redis = Redis.new(DEFAULTS)
|
35
|
-
cache_object = TrackRecordOrigin.find(1)
|
36
|
-
assert_equal('OK',@object_cache.put(cache_object))
|
37
|
-
# puts "object: #{@object_cache.get(1).inspect}"
|
38
|
-
object = nil
|
39
|
-
s1 = Time.now
|
40
|
-
2.times do
|
41
|
-
object = @object_cache.get(1)
|
42
|
-
# data = redis.get("track_1_1")
|
43
|
-
end
|
44
|
-
puts object.inspect
|
45
|
-
s2 = Time.now
|
46
|
-
puts s2-s1
|
47
|
-
|
48
|
-
|
49
|
-
redis.set("track_1_2", Hessian2.write(Hessian2::StructWrapper.new(TrackInRecordStruct, cache_object)))
|
50
|
-
redis.pexpire("track_1_2",100000)
|
51
|
-
object2 = nil
|
52
|
-
s1 = Time.now
|
53
|
-
2.times do
|
54
|
-
data = redis.get("track_1_2")
|
55
|
-
object2 = Hessian2.parse(data, TrackInRecordStruct)
|
56
|
-
end
|
57
|
-
s2 = Time.now
|
58
|
-
puts object2.inspect
|
59
|
-
puts s2-s1
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def teardown
|
64
|
-
super
|
65
|
-
puts "teardown"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
data/test/cache_object.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'bigdecimal'
|
3
|
-
require 'mysql2'
|
4
|
-
|
5
|
-
class CacheObject < ActiveRecord::Base
|
6
|
-
self.table_name = 'tb_xunch'
|
7
|
-
self.primary_key = "big_num_field"
|
8
|
-
conn = {
|
9
|
-
:adapter => "mysql2",
|
10
|
-
:encoding => "utf8",
|
11
|
-
:reconnect => false,
|
12
|
-
:database => "test",
|
13
|
-
:username => "root",
|
14
|
-
:password => "111111",
|
15
|
-
:host => "127.0.0.1"
|
16
|
-
}
|
17
|
-
ActiveRecord::Base.establish_connection(conn)
|
18
|
-
|
19
|
-
# include Xzunch::ColumnMethods
|
20
|
-
# include Xunch::Converter
|
21
|
-
attr_accessible :fix_num_field, :string_field, :big_num_field, :datetime_field, :float_field, :big_decimal_field
|
22
|
-
# attr_type_define :time_field => :datetime, :big_decimal_field => :big_decimal
|
23
|
-
|
24
|
-
TYPE_MAP = {
|
25
|
-
"datetime_field" =>:datetime,
|
26
|
-
"big_decimal_field" => :bigdecimal,
|
27
|
-
"fix_num_field" => :fixnum,
|
28
|
-
"float_field" => :float,
|
29
|
-
"big_num_field" => :bignum
|
30
|
-
}
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
"{fix_num_field=>#{@fix_num_field},string_field=>#{@string_field}," <<
|
34
|
-
"big_num_field=>#{@big_num_field},time_field=>#{@time_field}," <<
|
35
|
-
"float_field=>#{@float_field},big_decimal_field=>#{@big_decimal_field}}"
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize
|
40
|
-
super
|
41
|
-
# @fix_num_field = 111
|
42
|
-
# @string_field = "111"
|
43
|
-
# @big_num_field = 123123123123123123123123123123123
|
44
|
-
# @datetime_field = DateTime.new
|
45
|
-
# @float_field = 111.123213213123
|
46
|
-
# @big_decimal_field = BigDecimal.new("111111111111111111111111111111234.45466689324211111111111111111")
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
# puts CacheObject.kind_of?(ActiveRecord::Base)
|
52
|
-
# puts CacheObject.is_a?(ActiveRecord::Base)
|
53
|
-
# puts CacheObject.ancestors
|
54
|
-
# puts CacheObject.method_defined?(:_accessible_attributes)
|
55
|
-
# raise ArgumentError.new("Codec class does not defined method '_accessible_attributes', maybe this klass is not a subclass of ActiveRecord::Base.") unless CacheObject.method_defined?(:_accessible_attributes)
|
56
|
-
|
57
|
-
# o = CacheObject.new
|
58
|
-
|
59
|
-
# methods = CacheObject.instance_methods()
|
60
|
-
|
61
|
-
# set_methods = {}
|
62
|
-
# get_methods = {}
|
63
|
-
# methods.each { | method |
|
64
|
-
# puts method[method.length-1] == '='
|
65
|
-
# if method[method.length-1] == '='
|
66
|
-
# set_methods[method[0,method.length-1]] = method
|
67
|
-
# get_methods[method[0,method.length-1]] = method[0,method.length-1].to_sym
|
68
|
-
# end
|
69
|
-
# }
|
70
|
-
# puts set_methods
|
71
|
-
# puts get_methods
|
72
|
-
|
73
|
-
# object = CacheObject.new
|
74
|
-
# start = Time.new
|
75
|
-
# for i in 0 .. 10000000 do
|
76
|
-
# object.fix_num_field = i
|
77
|
-
# end
|
78
|
-
# stop = Time.new
|
79
|
-
# puts stop - start
|
80
|
-
# start = Time.new
|
81
|
-
# for i in 0 .. 10000000 do
|
82
|
-
# object.instance_variable_set(("@" + "fix_num_field"), i)
|
83
|
-
# end
|
84
|
-
# stop = Time.new
|
85
|
-
# puts stop - start
|
86
|
-
|
87
|
-
# start = Time.new
|
88
|
-
# for i in 0 .. 10000000 do
|
89
|
-
# object.fix_num_field
|
90
|
-
# end
|
91
|
-
# stop = Time.new
|
92
|
-
# puts stop - start
|
93
|
-
# start = Time.new
|
94
|
-
# for i in 0 .. 10000000 do
|
95
|
-
# object.instance_variable_get(:@fix_num_field)
|
96
|
-
# end
|
97
|
-
# stop = Time.new
|
98
|
-
# puts stop - start
|
99
|
-
|
100
|
-
# start = Time.new
|
101
|
-
# for i in 0 .. 10000000 do
|
102
|
-
# object.send(:fix_num_field)
|
103
|
-
# end
|
104
|
-
# stop = Time.new
|
105
|
-
# puts stop - start
|
106
|
-
# start = Time.new
|
107
|
-
# for i in 0 .. 10000000 do
|
108
|
-
# object.send("fix_num_field=",i)
|
109
|
-
# end
|
110
|
-
# stop = Time.new
|
111
|
-
# puts stop - start
|
112
|
-
# set_methods = {}
|
113
|
-
# get_methods = {}
|
114
|
-
# CacheObject._accessible_attributes[:default].each { |attribute|
|
115
|
-
# get_methods[attribute] = attribute.to_sym
|
116
|
-
# set_methods[attribute] = (attribute + "=").to_sym
|
117
|
-
# }
|
118
|
-
|
119
|
-
# p set_methods
|
120
|
-
# p get_methods
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require 'rbtree'
|
3
|
-
require 'murmurhash'
|
4
|
-
require 'redis'
|
5
|
-
|
6
|
-
class ConsistencyhashTest < Test::Unit::TestCase
|
7
|
-
include Test::Unit::Assertions
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
puts "setup"
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_consistency_hash
|
14
|
-
redis = Redis.new(:host => "192.168.1.174", :port => 6379, :password => "jredis123456")
|
15
|
-
redis.select 10
|
16
|
-
rbtree = RBTree[]
|
17
|
-
rbtree[1] = redis
|
18
|
-
rbtree[5] = redis
|
19
|
-
rbtree[11] = redis
|
20
|
-
puts rbtree[1].inspect
|
21
|
-
# puts rbtree.lower_bound(1)
|
22
|
-
# puts rbtree.upper_bound(2)
|
23
|
-
# puts rbtree.first.class
|
24
|
-
puts Murmurhash.hash2A("2")
|
25
|
-
end
|
26
|
-
|
27
|
-
def teardown
|
28
|
-
super
|
29
|
-
puts "teardown"
|
30
|
-
end
|
31
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'redis'
|
2
|
-
require 'hiredis'
|
3
|
-
require "test/unit"
|
4
|
-
require 'bigdecimal'
|
5
|
-
require 'time'
|
6
|
-
|
7
|
-
class ConsistencyhashTest < Test::Unit::TestCase
|
8
|
-
include Test::Unit::Assertions
|
9
|
-
def setup
|
10
|
-
super
|
11
|
-
puts "setup"
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_consistency_hash
|
15
|
-
redis = Redis.new(:host => "192.168.1.174", :port => 6379, :password => "jredis123456", :driver => :hiredis)
|
16
|
-
redis.select 10
|
17
|
-
hash = {
|
18
|
-
"field1" => "value1",
|
19
|
-
"field2" => BigDecimal.new("1231312321.1545727"),
|
20
|
-
"field3" => Time.new.to_datetime,
|
21
|
-
"field4" => 123432432141324321432432,
|
22
|
-
"field5" => 54444.4545,
|
23
|
-
"field6" => 12313123,
|
24
|
-
# "field7" => "value7",
|
25
|
-
# "field8" => "value8",
|
26
|
-
# "field9" => "value9",
|
27
|
-
# "field10" => "value10",
|
28
|
-
# "field11" => "value11",
|
29
|
-
# "field12" => "value12",
|
30
|
-
# "field13" => "value13",
|
31
|
-
# "field14" => "value14",
|
32
|
-
# "field15" => "value15",
|
33
|
-
# "field16" => "value16",
|
34
|
-
# "field17" => "value17",
|
35
|
-
# "field18" => "value18",
|
36
|
-
# "field19" => "value19",
|
37
|
-
# "field20" => "value20",
|
38
|
-
}
|
39
|
-
start = Time.new
|
40
|
-
for i in 0 ..10000 do
|
41
|
-
redis.pipelined do
|
42
|
-
redis.mapped_hmset("key", hash)
|
43
|
-
redis.pexpire("key",10000)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
stop = Time.new
|
47
|
-
puts stop - start
|
48
|
-
end
|
49
|
-
|
50
|
-
def teardown
|
51
|
-
super
|
52
|
-
puts "teardown"
|
53
|
-
end
|
54
|
-
end
|