xunch 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/xunch.rb +25 -0
- data/lib/xunch/cache/cache.rb +88 -0
- data/lib/xunch/cache/cache_builder.rb +68 -0
- data/lib/xunch/cache/field_object_cache.rb +120 -0
- data/lib/xunch/cache/list_field_object_cache.rb +63 -0
- data/lib/xunch/cache/list_object_cache.rb +59 -0
- data/lib/xunch/cache/object_cache.rb +63 -0
- data/lib/xunch/codec/codec.rb +31 -0
- data/lib/xunch/codec/hash_codec.rb +98 -0
- data/lib/xunch/codec/json_codec.rb +81 -0
- data/lib/xunch/shard/redis.rb +270 -0
- data/lib/xunch/shard/shard_info.rb +37 -0
- data/lib/xunch/shard/shard_redis.rb +267 -0
- data/lib/xunch/shard/sharded.rb +50 -0
- data/lib/xunch/utils/exceptions.rb +11 -0
- data/lib/xunch/utils/nginx_cache_helper.rb +52 -0
- data/lib/xunch/utils/rb_tree.rb +634 -0
- data/lib/xunch/utils/rb_tree_node.rb +67 -0
- data/lib/xunch/utils/types.rb +8 -0
- data/lib/xunch/utils/utils.rb +24 -0
- data/test/benchmark_test.rb +68 -0
- data/test/cache_builder_test.rb +28 -0
- data/test/cache_object.rb +120 -0
- data/test/consistency_hash_test.rb +31 -0
- data/test/field_object_cache_test.rb +430 -0
- data/test/hash_codec_test.rb +57 -0
- data/test/json_codec_test.rb +57 -0
- data/test/list_field_object_cache_test.rb +211 -0
- data/test/list_object_cache_test.rb +211 -0
- data/test/nginx_cache_helper_test.rb +45 -0
- data/test/object_cache_test.rb +322 -0
- data/test/rb_tree_test.rb +48 -0
- data/test/redis_benchmark_test.rb +54 -0
- data/test/redis_test.rb +58 -0
- data/test/running_test.rb +212 -0
- data/test/test.rb +176 -0
- data/test/track_record_origin.rb +58 -0
- metadata +125 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "test/unit"
|
3
|
+
require "xunch"
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
class HashObject < ActiveRecord::Base
|
7
|
+
attr_accessor :a,:b,:c,:d
|
8
|
+
TYPE_MAP = {}
|
9
|
+
def initialize
|
10
|
+
@a = 1
|
11
|
+
@b = 2
|
12
|
+
@c = 3
|
13
|
+
end
|
14
|
+
|
15
|
+
def setA(a)
|
16
|
+
@a = a
|
17
|
+
end
|
18
|
+
|
19
|
+
def setB(b)
|
20
|
+
@b = b
|
21
|
+
end
|
22
|
+
|
23
|
+
def setC(c)
|
24
|
+
@c = c
|
25
|
+
end
|
26
|
+
|
27
|
+
def setD(d)
|
28
|
+
@d = d
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"{a=#{@a},b=#{@b},c=#{@c},d=#{@d}}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class HashCodecTest < Test::Unit::TestCase
|
37
|
+
include Test::Unit::Assertions
|
38
|
+
def setup
|
39
|
+
super
|
40
|
+
@codec = Xunch::HashCodec.new(HashObject)
|
41
|
+
puts "setup"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_codec
|
45
|
+
json_object = HashObject.new
|
46
|
+
hash = @codec.encode(json_object)
|
47
|
+
puts hash
|
48
|
+
json_hash = @codec.decode(hash)
|
49
|
+
puts json_hash.class
|
50
|
+
puts json_hash.instance_variable_get(:@a)
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
super
|
55
|
+
puts "teardown"
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "test/unit"
|
3
|
+
require "xunch"
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
class JsonObject < ActiveRecord::Base
|
7
|
+
attr_accessor :a,:b,:c,:d
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@a = 1
|
11
|
+
@b = 2
|
12
|
+
@c = 3
|
13
|
+
end
|
14
|
+
|
15
|
+
def setA(a)
|
16
|
+
@a = a
|
17
|
+
end
|
18
|
+
|
19
|
+
def setB(b)
|
20
|
+
@b = b
|
21
|
+
end
|
22
|
+
|
23
|
+
def setC(c)
|
24
|
+
@c = c
|
25
|
+
end
|
26
|
+
|
27
|
+
def setD(d)
|
28
|
+
@d = d
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"{a=#{@a},b=#{@b},c=#{@c},d=#{@d}}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class JsonCodecTest < Test::Unit::TestCase
|
37
|
+
include Test::Unit::Assertions
|
38
|
+
def setup
|
39
|
+
super
|
40
|
+
@codec = Xunch::JsonCodec.new(JsonObject)
|
41
|
+
puts "setup"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_codec
|
45
|
+
json_object = JsonObject.new
|
46
|
+
json_string = @codec.encode(json_object)
|
47
|
+
puts json_string
|
48
|
+
json_hash = @codec.decode(json_string)
|
49
|
+
puts json_hash.class
|
50
|
+
puts json_hash.instance_variable_get(:@a)
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
super
|
55
|
+
puts "teardown"
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,211 @@
|
|
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 'track_record_origin'
|
7
|
+
|
8
|
+
|
9
|
+
class ObjectCacheTest < Test::Unit::TestCase
|
10
|
+
include Test::Unit::Assertions
|
11
|
+
def setup
|
12
|
+
super
|
13
|
+
root = File.expand_path("../..", __FILE__)
|
14
|
+
file = File.join(root, 'test/xunch.yaml')
|
15
|
+
caches = Xunch::CacheBuilder.build(file)
|
16
|
+
@list_object_cache = caches["fieldtracklist"]
|
17
|
+
@cache_object = TrackRecordOrigin.find(1)
|
18
|
+
@cache_objects = [@cache_object]
|
19
|
+
@keys = [1]
|
20
|
+
for i in 2 .. 100 do
|
21
|
+
new_cache_object = TrackRecordOrigin.new
|
22
|
+
new_cache_object.track_id = @cache_object.track_id
|
23
|
+
new_cache_object.track_uid = @cache_object.track_uid
|
24
|
+
new_cache_object.track_upload_source = @cache_object.track_upload_source
|
25
|
+
new_cache_object.op_type = @cache_object.op_type
|
26
|
+
new_cache_object.is_publish = @cache_object.is_publish
|
27
|
+
new_cache_object.upload_source = @cache_object.upload_source
|
28
|
+
new_cache_object.uid = @cache_object.uid
|
29
|
+
new_cache_object.nickname = @cache_object.nickname
|
30
|
+
new_cache_object.avatar_path = @cache_object.avatar_path
|
31
|
+
new_cache_object.is_v = @cache_object.is_v
|
32
|
+
new_cache_object.human_category_id = @cache_object.human_category_id
|
33
|
+
new_cache_object.title = @cache_object.title
|
34
|
+
new_cache_object.intro = @cache_object.intro
|
35
|
+
new_cache_object.user_source = @cache_object.user_source
|
36
|
+
new_cache_object.category_id = @cache_object.category_id
|
37
|
+
new_cache_object.duration = @cache_object.duration
|
38
|
+
new_cache_object.play_path = @cache_object.play_path
|
39
|
+
new_cache_object.play_path_32 = @cache_object.play_path_32
|
40
|
+
new_cache_object.play_path_64 = @cache_object.play_path_64
|
41
|
+
new_cache_object.play_path_128 = @cache_object.play_path_128
|
42
|
+
new_cache_object.transcode_state = @cache_object.transcode_state
|
43
|
+
new_cache_object.download_path = @cache_object.download_path
|
44
|
+
new_cache_object.cover_path = @cache_object.cover_path
|
45
|
+
new_cache_object.album_id = @cache_object.album_id
|
46
|
+
new_cache_object.album_title = @cache_object.album_title
|
47
|
+
new_cache_object.album_cover_path = @cache_object.album_cover_path
|
48
|
+
new_cache_object.tags = @cache_object.tags
|
49
|
+
new_cache_object.ignore_tags = @cache_object.ignore_tags
|
50
|
+
new_cache_object.extra_tags = @cache_object.extra_tags
|
51
|
+
new_cache_object.singer = @cache_object.singer
|
52
|
+
new_cache_object.singer_category = @cache_object.singer_category
|
53
|
+
new_cache_object.author = @cache_object.author
|
54
|
+
new_cache_object.composer = @cache_object.composer
|
55
|
+
new_cache_object.arrangement = @cache_object.arrangement
|
56
|
+
new_cache_object.post_production = @cache_object.post_production
|
57
|
+
new_cache_object.lyric_path = @cache_object.lyric_path
|
58
|
+
new_cache_object.lyric = @cache_object.lyric
|
59
|
+
new_cache_object.language = @cache_object.language
|
60
|
+
new_cache_object.resinger = @cache_object.resinger
|
61
|
+
new_cache_object.announcer = @cache_object.announcer
|
62
|
+
new_cache_object.is_public = @cache_object.is_public
|
63
|
+
new_cache_object.access_password = @cache_object.access_password
|
64
|
+
new_cache_object.allow_download = @cache_object.allow_download
|
65
|
+
new_cache_object.allow_comment = @cache_object.allow_comment
|
66
|
+
new_cache_object.is_crawler = @cache_object.is_crawler
|
67
|
+
new_cache_object.inet_aton_ip = @cache_object.inet_aton_ip
|
68
|
+
new_cache_object.longitude = @cache_object.longitude
|
69
|
+
new_cache_object.latitude = @cache_object.latitude
|
70
|
+
new_cache_object.music_category = @cache_object.music_category
|
71
|
+
new_cache_object.order_num = @cache_object.order_num
|
72
|
+
new_cache_object.is_pick = @cache_object.is_pick
|
73
|
+
new_cache_object.rich_intro = @cache_object.rich_intro
|
74
|
+
new_cache_object.short_intro = @cache_object.short_intro
|
75
|
+
new_cache_object.comment_content = @cache_object.comment_content
|
76
|
+
new_cache_object.comment_id = @cache_object.comment_id
|
77
|
+
new_cache_object.dig_status = @cache_object.dig_status
|
78
|
+
new_cache_object.approved_at = @cache_object.approved_at
|
79
|
+
new_cache_object.is_deleted = @cache_object.is_deleted
|
80
|
+
new_cache_object.mp3size = @cache_object.mp3size
|
81
|
+
new_cache_object.mp3size_32 = @cache_object.mp3size_32
|
82
|
+
new_cache_object.mp3size_64 = @cache_object.mp3size_64
|
83
|
+
new_cache_object.waveform = @cache_object.waveform
|
84
|
+
new_cache_object.upload_id = @cache_object.upload_id
|
85
|
+
new_cache_object.updated_at = @cache_object.updated_at
|
86
|
+
new_cache_object.created_at = @cache_object.created_at
|
87
|
+
new_cache_object.source_url = @cache_object.source_url
|
88
|
+
new_cache_object.status = @cache_object.status
|
89
|
+
new_cache_object.explore_height = @cache_object.explore_height
|
90
|
+
new_cache_object.id = i
|
91
|
+
@cache_objects.push new_cache_object
|
92
|
+
@keys.push new_cache_object.id
|
93
|
+
end
|
94
|
+
puts "setup"
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_put_get
|
98
|
+
result = @list_object_cache.put("1",@cache_objects)
|
99
|
+
hash = @list_object_cache.get("1",1,100)
|
100
|
+
keys = hash["keys"]
|
101
|
+
objects = hash["values"]
|
102
|
+
assert_equal(@cache_objects.length, objects.length)
|
103
|
+
for i in 0 .. @cache_objects.length - 1 do
|
104
|
+
assert_equal(keys[i],@keys[i].to_s)
|
105
|
+
assert_equal(Time.name,objects[i].created_at.class.name)
|
106
|
+
assert_equal(Time.name,objects[i].updated_at.class.name)
|
107
|
+
assert_equal(Time.name,objects[i].approved_at.class.name)
|
108
|
+
assert_equal(FalseClass.name,objects[i].is_crawler.class.name)
|
109
|
+
assert_equal(TrueClass.name,objects[i].is_public.class.name)
|
110
|
+
assert_equal(Fixnum.name,objects[i].mp3size.class.name)
|
111
|
+
assert_equal(BigDecimal.name,objects[i].longitude.class.name)
|
112
|
+
assert_equal(Bignum.name,objects[i].track_id.class.name)
|
113
|
+
assert_equal(String.name,objects[i].play_path.class.name)
|
114
|
+
|
115
|
+
#VALUE assert
|
116
|
+
assert_equal(@cache_objects[i].track_id,objects[i].track_id)
|
117
|
+
assert_equal(@cache_objects[i].track_uid,objects[i].track_uid)
|
118
|
+
assert_equal(@cache_objects[i].track_upload_source,objects[i].track_upload_source)
|
119
|
+
assert_equal(@cache_objects[i].op_type,objects[i].op_type)
|
120
|
+
assert_equal(@cache_objects[i].is_publish,objects[i].is_publish)
|
121
|
+
assert_equal(@cache_objects[i].upload_source,objects[i].upload_source)
|
122
|
+
assert_equal(@cache_objects[i].uid,objects[i].uid)
|
123
|
+
assert_equal(@cache_objects[i].nickname,objects[i].nickname)
|
124
|
+
assert_equal(@cache_objects[i].title,objects[i].title)
|
125
|
+
assert_equal(@cache_objects[i].intro,objects[i].intro)
|
126
|
+
assert_equal(@cache_objects[i].duration,objects[i].duration)
|
127
|
+
assert_equal(@cache_objects[i].play_path,objects[i].play_path)
|
128
|
+
assert_equal(@cache_objects[i].is_public,objects[i].is_public)
|
129
|
+
assert_equal(@cache_objects[i].is_crawler,objects[i].is_crawler)
|
130
|
+
assert_equal(@cache_objects[i].longitude,objects[i].longitude)
|
131
|
+
assert_equal(@cache_objects[i].approved_at,objects[i].approved_at)
|
132
|
+
assert_equal(@cache_objects[i].mp3size,objects[i].mp3size)
|
133
|
+
assert_equal(@cache_objects[i].updated_at,objects[i].updated_at)
|
134
|
+
assert_equal(@cache_objects[i].created_at,objects[i].created_at)
|
135
|
+
assert_equal(@cache_objects[i].id,objects[i].id)
|
136
|
+
# assert_equal(@cache_objects[i].avatar_path,objects[i].avatar_path)
|
137
|
+
# assert_equal(@cache_objects[i].is_v,objects[i].is_v)
|
138
|
+
# assert_equal(@cache_objects[i].human_category_id,objects[i].human_category_id)
|
139
|
+
# assert_equal(@cache_objects[i].user_source,objects[i].user_source)
|
140
|
+
# assert_equal(@cache_objects[i].category_id,objects[i].category_id)
|
141
|
+
# assert_equal(@cache_objects[i].play_path_32,objects[i].play_path_32)
|
142
|
+
# assert_equal(@cache_objects[i].play_path_64,objects[i].play_path_64)
|
143
|
+
# assert_equal(@cache_objects[i].play_path_128,objects[i].play_path_128)
|
144
|
+
# assert_equal(@cache_objects[i].transcode_state,objects[i].transcode_state)
|
145
|
+
# assert_equal(@cache_objects[i].download_path,objects[i].download_path)
|
146
|
+
# assert_equal(@cache_objects[i].cover_path,objects[i].cover_path)
|
147
|
+
# assert_equal(@cache_objects[i].album_id,objects[i].album_id)
|
148
|
+
# assert_equal(@cache_objects[i].album_title,objects[i].album_title)
|
149
|
+
# assert_equal(@cache_objects[i].album_cover_path,objects[i].album_cover_path)
|
150
|
+
# assert_equal(@cache_objects[i].tags,objects[i].tags)
|
151
|
+
# assert_equal(@cache_objects[i].ignore_tags,objects[i].ignore_tags)
|
152
|
+
# assert_equal(@cache_objects[i].extra_tags,objects[i].extra_tags)
|
153
|
+
# assert_equal(@cache_objects[i].singer,objects[i].singer)
|
154
|
+
# assert_equal(@cache_objects[i].singer_category,objects[i].singer_category)
|
155
|
+
# assert_equal(@cache_objects[i].author,objects[i].author)
|
156
|
+
# assert_equal(@cache_objects[i].composer,objects[i].composer)
|
157
|
+
# assert_equal(@cache_objects[i].arrangement,objects[i].arrangement)
|
158
|
+
# assert_equal(@cache_objects[i].post_production,objects[i].post_production)
|
159
|
+
# assert_equal(@cache_objects[i].lyric_path,objects[i].lyric_path)
|
160
|
+
# assert_equal(@cache_objects[i].language,objects[i].language)
|
161
|
+
# assert_equal(@cache_objects[i].lyric,objects[i].lyric)
|
162
|
+
# assert_equal(@cache_objects[i].resinger,objects[i].resinger)
|
163
|
+
# assert_equal(@cache_objects[i].announcer,objects[i].announcer)
|
164
|
+
# assert_equal(@cache_objects[i].access_password,objects[i].access_password)
|
165
|
+
# assert_equal(@cache_objects[i].allow_download,objects[i].allow_download)
|
166
|
+
# assert_equal(@cache_objects[i].allow_comment,objects[i].allow_comment)
|
167
|
+
# assert_equal(@cache_objects[i].inet_aton_ip,objects[i].inet_aton_ip)
|
168
|
+
# assert_equal(@cache_objects[i].latitude,objects[i].latitude)
|
169
|
+
# assert_equal(@cache_objects[i].music_category,objects[i].music_category)
|
170
|
+
# assert_equal(@cache_objects[i].order_num,objects[i].order_num)
|
171
|
+
# assert_equal(@cache_objects[i].is_pick,objects[i].is_pick)
|
172
|
+
# assert_equal(@cache_objects[i].rich_intro,objects[i].rich_intro)
|
173
|
+
# assert_equal(@cache_objects[i].short_intro,objects[i].short_intro)
|
174
|
+
# assert_equal(@cache_objects[i].comment_content,objects[i].comment_content)
|
175
|
+
# assert_equal(@cache_objects[i].comment_id,objects[i].comment_id)
|
176
|
+
# assert_equal(@cache_objects[i].dig_status,objects[i].dig_status)
|
177
|
+
# assert_equal(@cache_objects[i].is_deleted,objects[i].is_deleted)
|
178
|
+
# assert_equal(@cache_objects[i].mp3size_32,objects[i].mp3size_32)
|
179
|
+
# assert_equal(@cache_objects[i].mp3size_64,objects[i].mp3size_64)
|
180
|
+
# assert_equal(@cache_objects[i].waveform,objects[i].waveform)
|
181
|
+
# assert_equal(@cache_objects[i].upload_id,objects[i].upload_id)
|
182
|
+
# assert_equal(@cache_objects[i].source_url,objects[i].source_url)
|
183
|
+
# assert_equal(@cache_objects[i].status,objects[i].status)
|
184
|
+
# assert_equal(@cache_objects[i].explore_height,objects[i].explore_height)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_put_get_benchmark
|
189
|
+
times = 1000
|
190
|
+
start = Time.now
|
191
|
+
for i in 1 .. times do
|
192
|
+
result = @list_object_cache.put("1",@cache_objects)
|
193
|
+
end
|
194
|
+
stop = Time.now
|
195
|
+
use = stop - start
|
196
|
+
puts "#{times} times put operations total use #{use} seconds"
|
197
|
+
start = Time.now
|
198
|
+
for i in 1 .. times do
|
199
|
+
result = @list_object_cache.get("1",1,100)
|
200
|
+
end
|
201
|
+
stop = Time.now
|
202
|
+
use = stop - start
|
203
|
+
puts "#{times} times get operations total use #{use} seconds"
|
204
|
+
end
|
205
|
+
|
206
|
+
def teardown
|
207
|
+
super
|
208
|
+
puts "teardown"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
@@ -0,0 +1,211 @@
|
|
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 'track_record_origin'
|
7
|
+
|
8
|
+
|
9
|
+
class ObjectCacheTest < Test::Unit::TestCase
|
10
|
+
include Test::Unit::Assertions
|
11
|
+
def setup
|
12
|
+
super
|
13
|
+
root = File.expand_path("../..", __FILE__)
|
14
|
+
file = File.join(root, 'test/xunch.yaml')
|
15
|
+
caches = Xunch::CacheBuilder.build(file)
|
16
|
+
@list_object_cache = caches["tracklist"]
|
17
|
+
@cache_object = TrackRecordOrigin.find(1)
|
18
|
+
@cache_objects = [@cache_object]
|
19
|
+
@keys = [1]
|
20
|
+
for i in 2 .. 100 do
|
21
|
+
new_cache_object = TrackRecordOrigin.new
|
22
|
+
new_cache_object.track_id = @cache_object.track_id
|
23
|
+
new_cache_object.track_uid = @cache_object.track_uid
|
24
|
+
new_cache_object.track_upload_source = @cache_object.track_upload_source
|
25
|
+
new_cache_object.op_type = @cache_object.op_type
|
26
|
+
new_cache_object.is_publish = @cache_object.is_publish
|
27
|
+
new_cache_object.upload_source = @cache_object.upload_source
|
28
|
+
new_cache_object.uid = @cache_object.uid
|
29
|
+
new_cache_object.nickname = @cache_object.nickname
|
30
|
+
new_cache_object.avatar_path = @cache_object.avatar_path
|
31
|
+
new_cache_object.is_v = @cache_object.is_v
|
32
|
+
new_cache_object.human_category_id = @cache_object.human_category_id
|
33
|
+
new_cache_object.title = @cache_object.title
|
34
|
+
new_cache_object.intro = @cache_object.intro
|
35
|
+
new_cache_object.user_source = @cache_object.user_source
|
36
|
+
new_cache_object.category_id = @cache_object.category_id
|
37
|
+
new_cache_object.duration = @cache_object.duration
|
38
|
+
new_cache_object.play_path = @cache_object.play_path
|
39
|
+
new_cache_object.play_path_32 = @cache_object.play_path_32
|
40
|
+
new_cache_object.play_path_64 = @cache_object.play_path_64
|
41
|
+
new_cache_object.play_path_128 = @cache_object.play_path_128
|
42
|
+
new_cache_object.transcode_state = @cache_object.transcode_state
|
43
|
+
new_cache_object.download_path = @cache_object.download_path
|
44
|
+
new_cache_object.cover_path = @cache_object.cover_path
|
45
|
+
new_cache_object.album_id = @cache_object.album_id
|
46
|
+
new_cache_object.album_title = @cache_object.album_title
|
47
|
+
new_cache_object.album_cover_path = @cache_object.album_cover_path
|
48
|
+
new_cache_object.tags = @cache_object.tags
|
49
|
+
new_cache_object.ignore_tags = @cache_object.ignore_tags
|
50
|
+
new_cache_object.extra_tags = @cache_object.extra_tags
|
51
|
+
new_cache_object.singer = @cache_object.singer
|
52
|
+
new_cache_object.singer_category = @cache_object.singer_category
|
53
|
+
new_cache_object.author = @cache_object.author
|
54
|
+
new_cache_object.composer = @cache_object.composer
|
55
|
+
new_cache_object.arrangement = @cache_object.arrangement
|
56
|
+
new_cache_object.post_production = @cache_object.post_production
|
57
|
+
new_cache_object.lyric_path = @cache_object.lyric_path
|
58
|
+
new_cache_object.lyric = @cache_object.lyric
|
59
|
+
new_cache_object.language = @cache_object.language
|
60
|
+
new_cache_object.resinger = @cache_object.resinger
|
61
|
+
new_cache_object.announcer = @cache_object.announcer
|
62
|
+
new_cache_object.is_public = @cache_object.is_public
|
63
|
+
new_cache_object.access_password = @cache_object.access_password
|
64
|
+
new_cache_object.allow_download = @cache_object.allow_download
|
65
|
+
new_cache_object.allow_comment = @cache_object.allow_comment
|
66
|
+
new_cache_object.is_crawler = @cache_object.is_crawler
|
67
|
+
new_cache_object.inet_aton_ip = @cache_object.inet_aton_ip
|
68
|
+
new_cache_object.longitude = @cache_object.longitude
|
69
|
+
new_cache_object.latitude = @cache_object.latitude
|
70
|
+
new_cache_object.music_category = @cache_object.music_category
|
71
|
+
new_cache_object.order_num = @cache_object.order_num
|
72
|
+
new_cache_object.is_pick = @cache_object.is_pick
|
73
|
+
new_cache_object.rich_intro = @cache_object.rich_intro
|
74
|
+
new_cache_object.short_intro = @cache_object.short_intro
|
75
|
+
new_cache_object.comment_content = @cache_object.comment_content
|
76
|
+
new_cache_object.comment_id = @cache_object.comment_id
|
77
|
+
new_cache_object.dig_status = @cache_object.dig_status
|
78
|
+
new_cache_object.approved_at = @cache_object.approved_at
|
79
|
+
new_cache_object.is_deleted = @cache_object.is_deleted
|
80
|
+
new_cache_object.mp3size = @cache_object.mp3size
|
81
|
+
new_cache_object.mp3size_32 = @cache_object.mp3size_32
|
82
|
+
new_cache_object.mp3size_64 = @cache_object.mp3size_64
|
83
|
+
new_cache_object.waveform = @cache_object.waveform
|
84
|
+
new_cache_object.upload_id = @cache_object.upload_id
|
85
|
+
new_cache_object.updated_at = @cache_object.updated_at
|
86
|
+
new_cache_object.created_at = @cache_object.created_at
|
87
|
+
new_cache_object.source_url = @cache_object.source_url
|
88
|
+
new_cache_object.status = @cache_object.status
|
89
|
+
new_cache_object.explore_height = @cache_object.explore_height
|
90
|
+
new_cache_object.id = i
|
91
|
+
@cache_objects.push new_cache_object
|
92
|
+
@keys.push new_cache_object.id
|
93
|
+
end
|
94
|
+
puts "setup"
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_put_get
|
98
|
+
result = @list_object_cache.put("1",@cache_objects)
|
99
|
+
hash = @list_object_cache.get("1",1,100)
|
100
|
+
keys = hash["keys"]
|
101
|
+
objects = hash["values"]
|
102
|
+
assert_equal(@cache_objects.length, objects.length)
|
103
|
+
for i in 0 .. @cache_objects.length - 1 do
|
104
|
+
assert_equal(keys[i],@keys[i].to_s)
|
105
|
+
assert_equal(Time.name,objects[i].created_at.class.name)
|
106
|
+
assert_equal(Time.name,objects[i].updated_at.class.name)
|
107
|
+
assert_equal(Time.name,objects[i].approved_at.class.name)
|
108
|
+
assert_equal(FalseClass.name,objects[i].is_crawler.class.name)
|
109
|
+
assert_equal(TrueClass.name,objects[i].is_public.class.name)
|
110
|
+
assert_equal(Fixnum.name,objects[i].mp3size.class.name)
|
111
|
+
assert_equal(BigDecimal.name,objects[i].longitude.class.name)
|
112
|
+
assert_equal(Bignum.name,objects[i].track_id.class.name)
|
113
|
+
assert_equal(String.name,objects[i].play_path.class.name)
|
114
|
+
|
115
|
+
#VALUE assert
|
116
|
+
assert_equal(@cache_objects[i].track_id,objects[i].track_id)
|
117
|
+
assert_equal(@cache_objects[i].track_uid,objects[i].track_uid)
|
118
|
+
assert_equal(@cache_objects[i].track_upload_source,objects[i].track_upload_source)
|
119
|
+
assert_equal(@cache_objects[i].op_type,objects[i].op_type)
|
120
|
+
assert_equal(@cache_objects[i].is_publish,objects[i].is_publish)
|
121
|
+
assert_equal(@cache_objects[i].upload_source,objects[i].upload_source)
|
122
|
+
assert_equal(@cache_objects[i].uid,objects[i].uid)
|
123
|
+
assert_equal(@cache_objects[i].nickname,objects[i].nickname)
|
124
|
+
assert_equal(@cache_objects[i].avatar_path,objects[i].avatar_path)
|
125
|
+
assert_equal(@cache_objects[i].is_v,objects[i].is_v)
|
126
|
+
assert_equal(@cache_objects[i].human_category_id,objects[i].human_category_id)
|
127
|
+
assert_equal(@cache_objects[i].title,objects[i].title)
|
128
|
+
assert_equal(@cache_objects[i].intro,objects[i].intro)
|
129
|
+
assert_equal(@cache_objects[i].user_source,objects[i].user_source)
|
130
|
+
assert_equal(@cache_objects[i].category_id,objects[i].category_id)
|
131
|
+
assert_equal(@cache_objects[i].duration,objects[i].duration)
|
132
|
+
assert_equal(@cache_objects[i].play_path,objects[i].play_path)
|
133
|
+
assert_equal(@cache_objects[i].play_path_32,objects[i].play_path_32)
|
134
|
+
assert_equal(@cache_objects[i].play_path_64,objects[i].play_path_64)
|
135
|
+
assert_equal(@cache_objects[i].play_path_128,objects[i].play_path_128)
|
136
|
+
assert_equal(@cache_objects[i].transcode_state,objects[i].transcode_state)
|
137
|
+
assert_equal(@cache_objects[i].download_path,objects[i].download_path)
|
138
|
+
assert_equal(@cache_objects[i].cover_path,objects[i].cover_path)
|
139
|
+
assert_equal(@cache_objects[i].album_id,objects[i].album_id)
|
140
|
+
assert_equal(@cache_objects[i].album_title,objects[i].album_title)
|
141
|
+
assert_equal(@cache_objects[i].album_cover_path,objects[i].album_cover_path)
|
142
|
+
assert_equal(@cache_objects[i].tags,objects[i].tags)
|
143
|
+
assert_equal(@cache_objects[i].ignore_tags,objects[i].ignore_tags)
|
144
|
+
assert_equal(@cache_objects[i].extra_tags,objects[i].extra_tags)
|
145
|
+
assert_equal(@cache_objects[i].singer,objects[i].singer)
|
146
|
+
assert_equal(@cache_objects[i].singer_category,objects[i].singer_category)
|
147
|
+
assert_equal(@cache_objects[i].author,objects[i].author)
|
148
|
+
assert_equal(@cache_objects[i].composer,objects[i].composer)
|
149
|
+
assert_equal(@cache_objects[i].arrangement,objects[i].arrangement)
|
150
|
+
assert_equal(@cache_objects[i].post_production,objects[i].post_production)
|
151
|
+
assert_equal(@cache_objects[i].lyric_path,objects[i].lyric_path)
|
152
|
+
assert_equal(@cache_objects[i].language,objects[i].language)
|
153
|
+
assert_equal(@cache_objects[i].lyric,objects[i].lyric)
|
154
|
+
assert_equal(@cache_objects[i].resinger,objects[i].resinger)
|
155
|
+
assert_equal(@cache_objects[i].announcer,objects[i].announcer)
|
156
|
+
assert_equal(@cache_objects[i].is_public,objects[i].is_public)
|
157
|
+
assert_equal(@cache_objects[i].access_password,objects[i].access_password)
|
158
|
+
assert_equal(@cache_objects[i].allow_download,objects[i].allow_download)
|
159
|
+
assert_equal(@cache_objects[i].allow_comment,objects[i].allow_comment)
|
160
|
+
assert_equal(@cache_objects[i].is_crawler,objects[i].is_crawler)
|
161
|
+
assert_equal(@cache_objects[i].inet_aton_ip,objects[i].inet_aton_ip)
|
162
|
+
assert_equal(@cache_objects[i].longitude,objects[i].longitude)
|
163
|
+
assert_equal(@cache_objects[i].latitude,objects[i].latitude)
|
164
|
+
assert_equal(@cache_objects[i].music_category,objects[i].music_category)
|
165
|
+
assert_equal(@cache_objects[i].order_num,objects[i].order_num)
|
166
|
+
assert_equal(@cache_objects[i].is_pick,objects[i].is_pick)
|
167
|
+
assert_equal(@cache_objects[i].rich_intro,objects[i].rich_intro)
|
168
|
+
assert_equal(@cache_objects[i].short_intro,objects[i].short_intro)
|
169
|
+
assert_equal(@cache_objects[i].comment_content,objects[i].comment_content)
|
170
|
+
assert_equal(@cache_objects[i].comment_id,objects[i].comment_id)
|
171
|
+
assert_equal(@cache_objects[i].dig_status,objects[i].dig_status)
|
172
|
+
assert_equal(@cache_objects[i].approved_at,objects[i].approved_at)
|
173
|
+
assert_equal(@cache_objects[i].is_deleted,objects[i].is_deleted)
|
174
|
+
assert_equal(@cache_objects[i].mp3size,objects[i].mp3size)
|
175
|
+
assert_equal(@cache_objects[i].mp3size_32,objects[i].mp3size_32)
|
176
|
+
assert_equal(@cache_objects[i].mp3size_64,objects[i].mp3size_64)
|
177
|
+
assert_equal(@cache_objects[i].waveform,objects[i].waveform)
|
178
|
+
assert_equal(@cache_objects[i].upload_id,objects[i].upload_id)
|
179
|
+
assert_equal(@cache_objects[i].updated_at,objects[i].updated_at)
|
180
|
+
assert_equal(@cache_objects[i].created_at,objects[i].created_at)
|
181
|
+
assert_equal(@cache_objects[i].source_url,objects[i].source_url)
|
182
|
+
assert_equal(@cache_objects[i].status,objects[i].status)
|
183
|
+
assert_equal(@cache_objects[i].explore_height,objects[i].explore_height)
|
184
|
+
assert_equal(@cache_objects[i].id,objects[i].id)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_put_get_benchmark
|
189
|
+
times = 1000
|
190
|
+
start = Time.now
|
191
|
+
for i in 1 .. times do
|
192
|
+
result = @list_object_cache.put("1",@cache_objects)
|
193
|
+
end
|
194
|
+
stop = Time.now
|
195
|
+
use = stop - start
|
196
|
+
puts "#{times} times put operations total use #{use} seconds"
|
197
|
+
start = Time.now
|
198
|
+
for i in 1 .. times do
|
199
|
+
result = @list_object_cache.get("1",1,100)
|
200
|
+
end
|
201
|
+
stop = Time.now
|
202
|
+
use = stop - start
|
203
|
+
puts "#{times} times get operations total use #{use} seconds"
|
204
|
+
end
|
205
|
+
|
206
|
+
def teardown
|
207
|
+
super
|
208
|
+
puts "teardown"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|