xunch 0.0.9 → 0.0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b731a19b58bfaa3292a7c859ff34428b219d7a5
4
- data.tar.gz: 7feaf350a70b458efc0fa9d9b9b78c5602ee8d5c
3
+ metadata.gz: bfa3acc12d6287ef825abf765898bf2d2437df18
4
+ data.tar.gz: dbc34ae7e29cb0d4382342cd771f7efc21512040
5
5
  SHA512:
6
- metadata.gz: 0e842d7bfa0ee9b0c317cbed99de8e30e6fc338941f1b7a728e69a6e59ded2ad8c912dfdc6144174a0bc0cadb4bcc3488a21ef672d3784479fe0eae514741852
7
- data.tar.gz: 4a7d6f78ca09f0f10ec83070cb63b5ec1a7e50f931ebf515688e4491c2cb6e344e3e22363da721a1cf47ca5b7570139780c2e3ef73574accc77efe4f371097c8
6
+ metadata.gz: 764eb9fc9264aac38fbc92b1863cd119cbb7d84d83ad3220cea36aa8273898b8d9a520469c5d8aa7fc9a3cb9ff40cdd468306721d4ab5bc08ed181fb2e63108b
7
+ data.tar.gz: 5ccaff37bca70da67af1b82eeb2bb555f1062485cf0f3e7670a4a2f576b340140d1a154919a841881a88d27c8a1a0ef3e8599419940e0183598df6b89462f8a2
@@ -15,13 +15,14 @@ module Xunch
15
15
  configs = YAML.load_file(file)
16
16
  shard_info_configs = configs["shard_infos"]
17
17
  cache_configs = configs["caches"]
18
-
18
+ driver = configs["driver"].to_sym if configs["driver"]
19
19
  shards = {}
20
20
  shard_info_configs.each_value { |shard_info_config|
21
21
  options = {}
22
22
  shard_info_config.each { |k,v|
23
23
  options[k.to_sym] = v
24
24
  }
25
+ options[:driver] = driver if driver
25
26
  shards[options[:name]] = ShardInfo.new(options)
26
27
  }
27
28
  caches = {}
@@ -51,6 +51,7 @@ module Xunch
51
51
  @shard_redis.lremove(new_key,*sub_keys)
52
52
  end
53
53
 
54
+
54
55
  def size(key)
55
56
  raise "key can not be nil." unless key != nil
56
57
  new_key = assembleKey(key)
@@ -0,0 +1,95 @@
1
+ module Xunch
2
+ class FiberRedisPool
3
+
4
+ def initialize(options)
5
+ @reserved = {} # map of in-progress connections
6
+ @available = [] # pool of free connections
7
+ @pending = [] # pending reservations (FIFO)
8
+ @pool_timeout = options[:pool_timeout]
9
+
10
+ options[:size].times do
11
+ @available.push(redis = Redis.new(options))
12
+ end
13
+
14
+ @closed = false
15
+ end
16
+
17
+
18
+
19
+ def with
20
+ f = Fiber.current
21
+ begin
22
+ conn = checkout_redis(f)
23
+ yield conn
24
+ ensure
25
+ checkin_redis(f)
26
+ end
27
+ end
28
+
29
+ def destroy
30
+ if !@closed
31
+ @closed = true
32
+ @available.each {|redis| redis.quit if redis and redis.connected?}
33
+ @reserved.each {|redis| redis.quit if redis and redis.connected?}
34
+ end
35
+ end
36
+
37
+ # Returns current pool utilization.
38
+ #
39
+ # @return [Hash] Current utilization.
40
+ def pool_status
41
+ {
42
+ close: @closed,
43
+ available: @available.size,
44
+ reserved: @reserved.size,
45
+ pending: @pending.size
46
+ }
47
+ end
48
+
49
+ private
50
+
51
+ def check_close
52
+ if @closed
53
+ raise "Pool is closed, please re initialized"
54
+ end
55
+ end
56
+
57
+ # Acquire a lock on a connection and assign it to executing fiber
58
+ # - if connection is available, pass it back to the calling block
59
+ # - if pool is full, yield the current fiber until connection is available
60
+ def checkout_redis(fiber)
61
+ check_close
62
+ deadline = Time.now + @pool_timeout
63
+ loop do
64
+ conn = checkout_redis_internal(fiber)
65
+ if conn
66
+ return conn
67
+ elsif @pool_timeout > 0 && to_wait = deadline - Time.now <= 0
68
+ raise Timeout::Error, "Timeout, Waited #{@pool_timeout} seconds"
69
+ end
70
+ end
71
+ end
72
+
73
+ def checkout_redis_internal(fiber)
74
+ check_close
75
+ if conn = @available.pop
76
+ @reserved[fiber.object_id] = conn
77
+ conn
78
+ else
79
+ Fiber.yield @pending.push fiber
80
+ end
81
+ end
82
+
83
+ # Release connection assigned to the supplied fiber and
84
+ # resume any other pending connections (which will
85
+ # immediately try to run acquire on the pool)
86
+ def checkin_redis(fiber)
87
+ check_close
88
+ @available.push(@reserved.delete(fiber.object_id))
89
+
90
+ if pending = @pending.shift
91
+ pending.resume
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,85 @@
1
+ module Xunch
2
+ class ThreadedRedisPool
3
+ def initialize(options)
4
+ @reserved = {} # map of in-progress connections
5
+ @pending = 0 # pending reservations (FIFO)
6
+ @size = options[:size]
7
+ @available = Array.new(@size) { redis = Redis.new(options) }
8
+ @pool_timeout = options[:pool_timeout]
9
+ @mutex = Mutex.new
10
+ @resource = ConditionVariable.new
11
+ @closed = false
12
+ end
13
+
14
+ def with
15
+ redis = checkout_redis
16
+ begin
17
+ yield redis
18
+ ensure
19
+ checkin_redis(redis)
20
+ end
21
+ end
22
+
23
+ def destroy
24
+ if !@closed
25
+ @mutex.synchronize do
26
+ if !@closed
27
+ @closed = true
28
+ @available.each {|redis| redis.quit if redis and redis.connected?}
29
+ @reserved.each {|redis| redis.quit if redis and redis.connected?}
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def pool_status
36
+ {
37
+ close: @closed,
38
+ available: @available.size,
39
+ reserved: @reserved.size,
40
+ pending: @pending
41
+ }
42
+ end
43
+
44
+ private
45
+ def check_close
46
+ if @closed
47
+ raise "Pool is closed, please re initialized"
48
+ end
49
+ end
50
+
51
+ def checkout_redis
52
+ check_close
53
+ deadline = Time.now + @pool_timeout
54
+ @mutex.synchronize do
55
+ loop do
56
+ conn = @available.pop unless @available.empty?
57
+ if conn
58
+ @reserved[conn.object_id] = conn
59
+ return conn
60
+ else
61
+ to_wait = deadline - Time.now
62
+ raise Timeout::Error, "Waited #{@pool_timeout} seconds" if to_wait <= 0 and @pool_timeout > 0
63
+ @pending += 1
64
+ @resource.wait(@mutex, to_wait)
65
+ @pending -= 1
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def checkin_redis(redis)
72
+ check_close
73
+ # redis = Redis.new(@options) unless redis and redis.connected?
74
+ @mutex.synchronize do
75
+ if @available.length < @size
76
+ @reserved.delete redis.object_id
77
+ @available.push redis
78
+ @resource.broadcast
79
+ else
80
+ redis.quit
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,62 @@
1
+ module Xunch
2
+ class ThreadedRedisPool
3
+ def initialize(size, timeout)
4
+ @reserved = {} # map of in-progress connections
5
+ @pending = 0 # pending reservations (FIFO)
6
+ @available = Array.new(@options[:size]) { redis = Redis.new(@options) }
7
+ @pool_timeout = @options[:pool_timeout]
8
+ @mutex = Mutex.new
9
+ @resource = ConditionVariable.new
10
+ end
11
+
12
+ def with
13
+ redis = checkout_redis
14
+ begin
15
+ yield redis
16
+ ensure
17
+ checkin_redis(redis)
18
+ end
19
+ end
20
+
21
+ def pool_status
22
+ {
23
+ available: @available.size,
24
+ reserved: @reserved.size,
25
+ pending: @pending
26
+ }
27
+ end
28
+
29
+ private
30
+ def checkout_redis
31
+ deadline = Time.now + @pool_timeout
32
+ @mutex.synchronize do
33
+ loop do
34
+ conn = @pool.pop unless @pool.empty?
35
+ if conn
36
+ @reserved[conn.object_id] = conn
37
+ return conn
38
+ else
39
+ to_wait = deadline - Time.now
40
+ raise Timeout::Error, "Waited #{@pool_timeout} seconds" if to_wait <= 0 and @pool_timeout > 0
41
+ @pending += 1
42
+ @resource.wait(@mutex, to_wait)
43
+ @pending -= 1
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def checkin_redis(redis)
50
+ # redis = Redis.new(@options) unless redis and redis.connected?
51
+ @mutex.synchronize do
52
+ if @pool.length < @options[:size]
53
+ @reserved.delete redis.object_id
54
+ @available.push redis
55
+ @resource.broadcast
56
+ else
57
+ redis.quit
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # redis client support redis pool
3
- #
3
+ #
4
4
  module Xunch
5
5
  class RedisClient
6
6
 
@@ -12,22 +12,31 @@ module Xunch
12
12
  }
13
13
 
14
14
  def initialize(options = {})
15
- @options = DEFAULTS.merge(options)
15
+ # puts options
16
+ options = DEFAULTS.merge(options)
17
+ # puts options
16
18
  if RUBY_PLATFORM =~ /mingw/
17
- @options[:driver] = nil
19
+ options[:driver] = nil
20
+ end
21
+ if(options[:pool_timeout] <= 0)
22
+ options[:pool_timeout] = 1073741823
18
23
  end
19
- if(@options[:pool_timeout] > 0)
20
- @pool_timeout = @options[:pool_timeout]
24
+ # p options[:driver]
25
+ last_driver = Redis::Connection.drivers.last
26
+ options[:driver] ||= last_driver[last_driver.rindex('.'), last_driver.length].to_sym
27
+ if options[:driver] == :synchrony
28
+ require "xunch/connection/fiber_redis_pool"
29
+ # puts "fiber pool"
30
+ @pool = FiberRedisPool.new(options)
21
31
  else
22
- @pool_timeout = 1073741823
32
+ require "xunch/connection/threaded_redis_pool"
33
+ # puts "threaded pool"
34
+ @pool = ThreadedRedisPool.new(options)
23
35
  end
24
- @pool = Array.new(@options[:size]) { redis = Redis.new(@options) }
25
- @mutex = Mutex.new
26
- @resource = ConditionVariable.new
27
36
  end
28
37
 
29
38
  def destroy
30
- @pool.each {|redis| redis.quit if redis and redis.connected?}
39
+ @pool.destroy
31
40
  end
32
41
 
33
42
  def exists(key)
@@ -55,7 +64,7 @@ module Xunch
55
64
  redis.expire(key,ttl)
56
65
  end
57
66
  end
58
-
67
+
59
68
  def ttl(key)
60
69
  with do | redis |
61
70
  redis.ttl(key)
@@ -86,10 +95,14 @@ module Xunch
86
95
  # @return `"OK"`
87
96
  def set(key, value, ttl)
88
97
  with do | redis |
89
- redis.setex(key,ttl,value)
98
+ if(ttl > 0)
99
+ redis.setex(key,ttl,value)
100
+ else
101
+ redis.set(key,value)
102
+ end
90
103
  end
91
104
  end
92
-
105
+
93
106
  # multi set key value with expire time in second
94
107
  # NOTE: use pipeline inner
95
108
  #
@@ -97,7 +110,7 @@ module Xunch
97
110
  # @param [Fixnum] ttl time to live
98
111
  def mset(hash, ttl)
99
112
  with do | redis |
100
- if(ttl != 0)
113
+ if(ttl > 0)
101
114
  redis.pipelined do
102
115
  hash.each { |key,value|
103
116
  redis.setex(key,ttl,value)
@@ -142,7 +155,7 @@ module Xunch
142
155
  end
143
156
  end
144
157
  end
145
-
158
+
146
159
  # multi get hash type keys with fields
147
160
  #
148
161
  # @param keys [Array] redis hash key
@@ -244,39 +257,9 @@ module Xunch
244
257
  end
245
258
  end
246
259
 
247
- private
248
- def with
249
- redis = checkout_redis
250
- begin
251
- yield redis
252
- ensure
253
- checkin_redis(redis)
254
- end
255
- end
256
-
257
- def checkout_redis
258
- deadline = Time.now + @pool_timeout
259
- @mutex.synchronize do
260
- loop do
261
- return @pool.pop unless @pool.empty?
262
- to_wait = deadline - Time.now
263
- raise Timeout::Error, "Waited #{@pool_timeout} seconds" if to_wait <= 0 and @pool_timeout > 0
264
- @resource.wait(@mutex, to_wait)
265
- end
266
- end
267
- end
268
-
269
- def checkin_redis(redis)
270
- redis = Redis.new(@options) unless redis and redis.connected?
271
- @mutex.synchronize do
272
- if @pool.length < @options[:size]
273
- @pool.push redis
274
- @resource.broadcast
275
- else
276
- redis.quit
277
- end
278
- end
260
+ private
261
+ def with(&block)
262
+ @pool.with(&block)
279
263
  end
280
-
281
264
  end
282
265
  end
@@ -4,7 +4,7 @@ module Xunch
4
4
  class Sharded
5
5
  include Murmurhash
6
6
 
7
- def initialize(regex,shard_infos)
7
+ def initialize(regex, shard_infos)
8
8
  @regexp = Regexp.new(regex)
9
9
  @nodes = RBTree.new
10
10
  @resources = Hash.new
@@ -0,0 +1,66 @@
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 'test_helper'
7
+
8
+ class EMCacheTest < Test::Unit::TestCase
9
+ include Test::Unit::Assertions
10
+ def setup
11
+ root = File.expand_path("../..", __FILE__)
12
+ file = File.join(root, 'test/xunch_em.yaml')
13
+ caches = Xunch::CacheBuilder.build(file)
14
+ @object_cache = caches["track"]
15
+ hash = TestHelper.build_objects
16
+ @cache_object = hash["object"]
17
+ @cache_objects = hash["objects"]
18
+ @key = hash["key"]
19
+ puts "setup"
20
+ end
21
+
22
+ def test_evict
23
+ EM.synchrony do
24
+ puts "CacheTest test_evict method start"
25
+ @object_cache.putex(@cache_object,3000)
26
+ @object_cache.get(@cache_object.id)
27
+ @object_cache.evict(@cache_object.id)
28
+ object = @object_cache.get(@cache_object.id)
29
+ assert_equal(nil,object)
30
+ puts "CacheTest test_evict method stop"
31
+ EventMachine.stop
32
+ end
33
+ end
34
+
35
+ def test_batch_evict
36
+ EM.synchrony do
37
+ puts "CacheTest test_batch_evict method start"
38
+ @object_cache.putex(@cache_object,3000)
39
+ @object_cache.get(@cache_object.id)
40
+ @object_cache.evict(@cache_object.id)
41
+ object = @object_cache.get(@cache_object.id)
42
+ assert_equal(nil,object)
43
+ puts "CacheTest test_batch_evict method stop"
44
+ EventMachine.stop
45
+ end
46
+ end
47
+
48
+ def test_ttl
49
+ EM.synchrony do
50
+ puts "CacheTest test_ttl method start"
51
+ @object_cache.putex(@cache_object,3000)
52
+ ttl = @object_cache.ttl(@cache_object.id)
53
+ @object_cache.evict(@cache_object.id)
54
+ assert_equal(3000,ttl)
55
+ ttl = @object_cache.ttl(@cache_object.id)
56
+ assert_equal(-1,ttl)
57
+ puts "CacheTest test_ttl method stop"
58
+ EventMachine.stop
59
+ end
60
+ end
61
+
62
+ def teardown
63
+ super
64
+ puts "CacheTest teardown"
65
+ end
66
+ end
@@ -0,0 +1,411 @@
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 'test_helper'
7
+
8
+ class FieldObjectCacheTest < Test::Unit::TestCase
9
+ include Test::Unit::Assertions
10
+ def setup
11
+ super
12
+ root = File.expand_path("../..", __FILE__)
13
+ file = File.join(root, 'test/xunch_em.yaml')
14
+ caches = Xunch::CacheBuilder.build(file)
15
+ @field_object_cache = caches["trackfield"]
16
+ @fields = ["createdAt","updatedAt","approvedAt","isCrawler","isPublic","mp3size","longitude","trackId","playPath"]
17
+ hash = TestHelper.build_objects
18
+ @cache_object = hash["object"]
19
+ @cache_objects = hash["objects"]
20
+ @keys = hash["keys"]
21
+ puts "setup"
22
+ end
23
+
24
+ def test_get_set
25
+ EM.synchrony do
26
+ puts "FieldObjectCacheTest test_get_set method start"
27
+ @field_object_cache.evict(1)
28
+ object = @field_object_cache.get(1)
29
+ assert_equal(nil,object)
30
+ assert_equal(["OK",true],@field_object_cache.put(@cache_object))
31
+ object = @field_object_cache.get(1)
32
+ # type assert
33
+ assert_equal(Time.name,object.created_at.class.name)
34
+ assert_equal(Time.name,object.updated_at.class.name)
35
+ assert_equal(Time.name,object.approved_at.class.name)
36
+ assert_equal(FalseClass.name,object.is_crawler.class.name)
37
+ assert_equal(TrueClass.name,object.is_public.class.name)
38
+ assert_equal(Fixnum.name,object.mp3size.class.name)
39
+ assert_equal(BigDecimal.name,object.longitude.class.name)
40
+ assert_equal(Bignum.name,object.track_id.class.name)
41
+ assert_equal(String.name,object.play_path.class.name)
42
+
43
+ #value assert
44
+ assert_equal(@cache_object.track_id,object.track_id)
45
+ assert_equal(@cache_object.track_uid,object.track_uid)
46
+ assert_equal(@cache_object.track_upload_source,object.track_upload_source)
47
+ assert_equal(@cache_object.op_type,object.op_type)
48
+ assert_equal(@cache_object.is_public,object.is_public)
49
+ assert_equal(@cache_object.upload_source,object.upload_source)
50
+ assert_equal(@cache_object.uid,object.uid)
51
+ assert_equal(@cache_object.nickname,object.nickname)
52
+ assert_equal(@cache_object.title,object.title)
53
+ assert_equal(@cache_object.intro,object.intro)
54
+ assert_equal(@cache_object.play_path,object.play_path)
55
+ assert_equal(@cache_object.is_crawler,object.is_crawler)
56
+ assert_equal(@cache_object.approved_at,object.approved_at)
57
+ assert_equal(@cache_object.mp3size,object.mp3size)
58
+ assert_equal(@cache_object.updated_at,object.updated_at)
59
+ assert_equal(@cache_object.created_at,object.created_at)
60
+ assert_equal(@cache_object.id,object.id)
61
+ assert_equal(@cache_object.longitude,object.longitude)
62
+ assert_equal(@cache_object.duration,object.duration)
63
+ # assert_equal(@cache_object.is_deleted,object.is_deleted)
64
+ # assert_equal(@cache_object.is_publish,object.is_publish)
65
+ # assert_equal(@cache_object.avatar_path,object.avatar_path)
66
+ # assert_equal(@cache_object.is_v,object.is_v)
67
+ # assert_equal(@cache_object.human_category_id,object.human_category_id)
68
+ # assert_equal(@cache_object.user_source,object.user_source)
69
+ # assert_equal(@cache_object.category_id,object.category_id)
70
+ # assert_equal(@cache_object.play_path_32,object.play_path_32)
71
+ # assert_equal(@cache_object.play_path_64,object.play_path_64)
72
+ # assert_equal(@cache_object.play_path_128,object.play_path_128)
73
+ # assert_equal(@cache_object.transcode_state,object.transcode_state)
74
+ # assert_equal(@cache_object.download_path,object.download_path)
75
+ # assert_equal(@cache_object.cover_path,object.cover_path)
76
+ # assert_equal(@cache_object.album_id,object.album_id)
77
+ # assert_equal(@cache_object.album_title,object.album_title)
78
+ # assert_equal(@cache_object.album_cover_path,object.album_cover_path)
79
+ # assert_equal(@cache_object.tags,object.tags)
80
+ # assert_equal(@cache_object.ignore_tags,object.ignore_tags)
81
+ # assert_equal(@cache_object.extra_tags,object.extra_tags)
82
+ # assert_equal(@cache_object.singer,object.singer)
83
+ # assert_equal(@cache_object.singer_category,object.singer_category)
84
+ # assert_equal(@cache_object.author,object.author)
85
+ # assert_equal(@cache_object.composer,object.composer)
86
+ # assert_equal(@cache_object.arrangement,object.arrangement)
87
+ # assert_equal(@cache_object.post_production,object.post_production)
88
+ # assert_equal(@cache_object.lyric_path,object.lyric_path)
89
+ # assert_equal(@cache_object.language,object.language)
90
+ # assert_equal(@cache_object.lyric,object.lyric)
91
+ # assert_equal(@cache_object.resinger,object.resinger)
92
+ # assert_equal(@cache_object.announcer,object.announcer)
93
+ # assert_equal(@cache_object.access_password,object.access_password)
94
+ # assert_equal(@cache_object.allow_download,object.allow_download)
95
+ # assert_equal(@cache_object.allow_comment,object.allow_comment)
96
+ # assert_equal(@cache_object.inet_aton_ip,object.inet_aton_ip)
97
+ # assert_equal(@cache_object.latitude,object.latitude)
98
+ # assert_equal(@cache_object.music_category,object.music_category)
99
+ # assert_equal(@cache_object.order_num,object.order_num)
100
+ # assert_equal(@cache_object.is_pick,object.is_pick)
101
+ # assert_equal(@cache_object.rich_intro,object.rich_intro)
102
+ # assert_equal(@cache_object.short_intro,object.short_intro)
103
+ # assert_equal(@cache_object.comment_content,object.comment_content)
104
+ # assert_equal(@cache_object.comment_id,object.comment_id)
105
+ # assert_equal(@cache_object.dig_status,object.dig_status)
106
+ # assert_equal(@cache_object.mp3size_32,object.mp3size_32)
107
+ # assert_equal(@cache_object.mp3size_64,object.mp3size_64)
108
+ # assert_equal(@cache_object.waveform,object.waveform)
109
+ # assert_equal(@cache_object.upload_id,object.upload_id)
110
+ # assert_equal(@cache_object.source_url,object.source_url)
111
+ # assert_equal(@cache_object.status,object.status)
112
+ # assert_equal(@cache_object.explore_height,object.explore_height)
113
+ puts "FieldObjectCacheTest test_get_set method stop"
114
+
115
+ EventMachine.stop
116
+ end
117
+ end
118
+
119
+ def test_get_set_benchmark
120
+ EM.synchrony do
121
+ puts "FieldObjectCacheTest test_get_set_benchmark method start"
122
+ @field_object_cache.evict(1)
123
+ times = TestHelper::TIMES
124
+ start = Time.now
125
+ for i in 1 .. times do
126
+ @field_object_cache.put(@cache_object)
127
+ end
128
+ stop = Time.now
129
+ puts "#{times} times put operation total use #{stop-start} seconds"
130
+
131
+ start = Time.now
132
+ for i in 1 .. times do
133
+ @field_object_cache.get(1)
134
+ end
135
+ stop = Time.now
136
+ puts "#{times} times get operation total use #{stop-start} seconds"
137
+ puts "FieldObjectCacheTest test_get_set_benchmark method stop"
138
+
139
+ EventMachine.stop
140
+ end
141
+ end
142
+
143
+ def test_mget_mset
144
+ EM.synchrony do
145
+ puts "FieldObjectCacheTest test_mget_mset method start"
146
+ @field_object_cache.batch_evict @keys
147
+ result = @field_object_cache.multi_put(@cache_objects)
148
+ for i in 0 .. result.length / 2 - 1 do
149
+ k = i * 2
150
+ assert_equal("OK",result[k])
151
+ assert_equal(true,result[k+1])
152
+ end
153
+
154
+ objects = @field_object_cache.multi_get(@keys)
155
+ assert_equal(@cache_objects.length, objects.length)
156
+ for i in 0 .. @cache_objects.length - 1 do
157
+ assert_equal(Time.name,objects[i].created_at.class.name)
158
+ assert_equal(Time.name,objects[i].updated_at.class.name)
159
+ assert_equal(Time.name,objects[i].approved_at.class.name)
160
+ assert_equal(FalseClass.name,objects[i].is_crawler.class.name)
161
+ assert_equal(TrueClass.name,objects[i].is_public.class.name)
162
+ assert_equal(Fixnum.name,objects[i].mp3size.class.name)
163
+ assert_equal(BigDecimal.name,objects[i].longitude.class.name)
164
+ assert_equal(Bignum.name,objects[i].track_id.class.name)
165
+ assert_equal(String.name,objects[i].play_path.class.name)
166
+
167
+ #VALUE assert
168
+ assert_equal(@cache_objects[i].track_id,objects[i].track_id)
169
+ assert_equal(@cache_objects[i].track_uid,objects[i].track_uid)
170
+ assert_equal(@cache_objects[i].track_upload_source,objects[i].track_upload_source)
171
+ assert_equal(@cache_objects[i].op_type,objects[i].op_type)
172
+ assert_equal(@cache_objects[i].is_publish,objects[i].is_publish)
173
+ assert_equal(@cache_objects[i].upload_source,objects[i].upload_source)
174
+ assert_equal(@cache_objects[i].uid,objects[i].uid)
175
+ assert_equal(@cache_objects[i].nickname,objects[i].nickname)
176
+ assert_equal(@cache_objects[i].title,objects[i].title)
177
+ assert_equal(@cache_objects[i].intro,objects[i].intro)
178
+ assert_equal(@cache_objects[i].duration,objects[i].duration)
179
+ assert_equal(@cache_objects[i].play_path,objects[i].play_path)
180
+ assert_equal(@cache_objects[i].is_public,objects[i].is_public)
181
+ assert_equal(@cache_objects[i].is_crawler,objects[i].is_crawler)
182
+ assert_equal(@cache_objects[i].longitude,objects[i].longitude)
183
+ assert_equal(@cache_objects[i].approved_at,objects[i].approved_at)
184
+ assert_equal(@cache_objects[i].mp3size,objects[i].mp3size)
185
+ assert_equal(@cache_objects[i].updated_at,objects[i].updated_at)
186
+ assert_equal(@cache_objects[i].created_at,objects[i].created_at)
187
+ assert_equal(@cache_objects[i].id,objects[i].id)
188
+ # assert_equal(@cache_objects[i].avatar_path,objects[i].avatar_path)
189
+ # assert_equal(@cache_objects[i].is_v,objects[i].is_v)
190
+ # assert_equal(@cache_objects[i].human_category_id,objects[i].human_category_id)
191
+ # assert_equal(@cache_objects[i].user_source,objects[i].user_source)
192
+ # assert_equal(@cache_objects[i].category_id,objects[i].category_id)
193
+ # assert_equal(@cache_objects[i].play_path_32,objects[i].play_path_32)
194
+ # assert_equal(@cache_objects[i].play_path_64,objects[i].play_path_64)
195
+ # assert_equal(@cache_objects[i].play_path_128,objects[i].play_path_128)
196
+ # assert_equal(@cache_objects[i].transcode_state,objects[i].transcode_state)
197
+ # assert_equal(@cache_objects[i].download_path,objects[i].download_path)
198
+ # assert_equal(@cache_objects[i].cover_path,objects[i].cover_path)
199
+ # assert_equal(@cache_objects[i].album_id,objects[i].album_id)
200
+ # assert_equal(@cache_objects[i].album_title,objects[i].album_title)
201
+ # assert_equal(@cache_objects[i].album_cover_path,objects[i].album_cover_path)
202
+ # assert_equal(@cache_objects[i].tags,objects[i].tags)
203
+ # assert_equal(@cache_objects[i].ignore_tags,objects[i].ignore_tags)
204
+ # assert_equal(@cache_objects[i].extra_tags,objects[i].extra_tags)
205
+ # assert_equal(@cache_objects[i].singer,objects[i].singer)
206
+ # assert_equal(@cache_objects[i].singer_category,objects[i].singer_category)
207
+ # assert_equal(@cache_objects[i].author,objects[i].author)
208
+ # assert_equal(@cache_objects[i].composer,objects[i].composer)
209
+ # assert_equal(@cache_objects[i].arrangement,objects[i].arrangement)
210
+ # assert_equal(@cache_objects[i].post_production,objects[i].post_production)
211
+ # assert_equal(@cache_objects[i].lyric_path,objects[i].lyric_path)
212
+ # assert_equal(@cache_objects[i].language,objects[i].language)
213
+ # assert_equal(@cache_objects[i].lyric,objects[i].lyric)
214
+ # assert_equal(@cache_objects[i].resinger,objects[i].resinger)
215
+ # assert_equal(@cache_objects[i].announcer,objects[i].announcer)
216
+ # assert_equal(@cache_objects[i].access_password,objects[i].access_password)
217
+ # assert_equal(@cache_objects[i].allow_download,objects[i].allow_download)
218
+ # assert_equal(@cache_objects[i].allow_comment,objects[i].allow_comment)
219
+ # assert_equal(@cache_objects[i].inet_aton_ip,objects[i].inet_aton_ip)
220
+ # assert_equal(@cache_objects[i].latitude,objects[i].latitude)
221
+ # assert_equal(@cache_objects[i].music_category,objects[i].music_category)
222
+ # assert_equal(@cache_objects[i].order_num,objects[i].order_num)
223
+ # assert_equal(@cache_objects[i].is_pick,objects[i].is_pick)
224
+ # assert_equal(@cache_objects[i].rich_intro,objects[i].rich_intro)
225
+ # assert_equal(@cache_objects[i].short_intro,objects[i].short_intro)
226
+ # assert_equal(@cache_objects[i].comment_content,objects[i].comment_content)
227
+ # assert_equal(@cache_objects[i].comment_id,objects[i].comment_id)
228
+ # assert_equal(@cache_objects[i].dig_status,objects[i].dig_status)
229
+ # assert_equal(@cache_objects[i].is_deleted,objects[i].is_deleted)
230
+ # assert_equal(@cache_objects[i].mp3size_32,objects[i].mp3size_32)
231
+ # assert_equal(@cache_objects[i].mp3size_64,objects[i].mp3size_64)
232
+ # assert_equal(@cache_objects[i].waveform,objects[i].waveform)
233
+ # assert_equal(@cache_objects[i].upload_id,objects[i].upload_id)
234
+ # assert_equal(@cache_objects[i].source_url,objects[i].source_url)
235
+ # assert_equal(@cache_objects[i].status,objects[i].status)
236
+ # assert_equal(@cache_objects[i].explore_height,objects[i].explore_height)
237
+ end
238
+ puts "FieldObjectCacheTest test_mget_mset method stop"
239
+
240
+ EventMachine.stop
241
+ end
242
+ end
243
+
244
+ def test_mget_mset_benchmark
245
+ EM.synchrony do
246
+ puts "FieldObjectCacheTest test_mget_mset_benchmark method start"
247
+ @field_object_cache.batch_evict @keys
248
+
249
+ times = TestHelper::TIMES
250
+ start = Time.now
251
+ for i in 1 .. times do
252
+ @field_object_cache.multi_put(@cache_objects)
253
+ end
254
+ stop = Time.now
255
+ puts "#{times} times multi_put operation total use #{stop-start} seconds"
256
+
257
+ start = Time.now
258
+ for i in 1 .. times do
259
+ @field_object_cache.multi_get(@keys)
260
+ end
261
+ stop = Time.now
262
+ puts "#{times} times multi_get operation total use #{stop-start} seconds"
263
+ puts "FieldObjectCacheTest test_mget_mset_benchmark method stop"
264
+
265
+ EventMachine.stop
266
+ end
267
+ end
268
+
269
+ def test_evict
270
+ EM.synchrony do
271
+ puts "FieldObjectCacheTest test_evict method start"
272
+ @field_object_cache.batch_evict(@keys)
273
+ puts "FieldObjectCacheTest test_evict method stop"
274
+
275
+ EventMachine.stop
276
+ end
277
+ end
278
+
279
+ def test_get_set_with_field
280
+ EM.synchrony do
281
+ puts "FieldObjectCacheTest test_get_set_with_field method start"
282
+ # you must convert fields first
283
+
284
+ @field_object_cache.evict(1)
285
+ object = @field_object_cache.get_with_field(1,@fields)
286
+ assert_equal(nil,object)
287
+ assert_equal(["OK",true],@field_object_cache.put_with_field(@cache_object,@fields))
288
+ object = @field_object_cache.get_with_field(1,@fields)
289
+ assert_equal(Time.name,object.created_at.class.name)
290
+ assert_equal(Time.name,object.updated_at.class.name)
291
+ assert_equal(Time.name,object.approved_at.class.name)
292
+ assert_equal(FalseClass.name,object.is_crawler.class.name)
293
+ assert_equal(TrueClass.name,object.is_public.class.name)
294
+ assert_equal(Fixnum.name,object.mp3size.class.name)
295
+ assert_equal(BigDecimal.name,object.longitude.class.name)
296
+ assert_equal(Bignum.name,object.track_id.class.name)
297
+ assert_equal(String.name,object.play_path.class.name)
298
+
299
+ #value assert
300
+ assert_equal(@cache_object.track_id,object.track_id)
301
+ assert_equal(@cache_object.play_path,object.play_path)
302
+ assert_equal(@cache_object.is_public,object.is_public)
303
+ assert_equal(@cache_object.is_crawler,object.is_crawler)
304
+ assert_equal(@cache_object.longitude,object.longitude)
305
+ assert_equal(@cache_object.approved_at,object.approved_at)
306
+ assert_equal(@cache_object.mp3size,object.mp3size)
307
+ assert_equal(@cache_object.updated_at,object.updated_at)
308
+ assert_equal(@cache_object.created_at,object.created_at)
309
+ puts "FieldObjectCacheTest test_get_set_with_field method stop"
310
+
311
+ EventMachine.stop
312
+ end
313
+ end
314
+
315
+ def test_get_set_with_field_benchmark
316
+
317
+ EM.synchrony do
318
+ puts "FieldObjectCacheTest test_get_set_with_field_benchmark method start"
319
+ @field_object_cache.evict(1)
320
+ times = TestHelper::TIMES
321
+ start = Time.now
322
+ for i in 1 .. times do
323
+ @field_object_cache.put_with_field(@cache_object,@fields)
324
+ end
325
+ stop = Time.now
326
+ puts "#{times} times put_with_field operation total use #{stop-start} seconds"
327
+
328
+ start = Time.now
329
+ for i in 1 .. times do
330
+ @field_object_cache.get_with_field(1,@fields)
331
+ end
332
+ stop = Time.now
333
+ puts "#{times} times get_with_field operation total use #{stop-start} seconds"
334
+ puts "FieldObjectCacheTest test_get_set_with_field_benchmark method stop"
335
+ EventMachine.stop
336
+ end
337
+ end
338
+
339
+ def test_mget_mset_with_field
340
+
341
+ EM.synchrony do
342
+ puts "FieldObjectCacheTest test_mget_mset_with_field method start"
343
+ @field_object_cache.batch_evict @keys
344
+ result = @field_object_cache.multi_put_with_field(@cache_objects,@fields)
345
+ for i in 0 .. result.length / 2 - 1 do
346
+ k = i * 2
347
+ assert_equal("OK",result[k])
348
+ assert_equal(true,result[k+1])
349
+ end
350
+
351
+ objects = @field_object_cache.multi_get_with_field(@keys,@fields)
352
+ assert_equal(@cache_objects.length, objects.length)
353
+ for i in 0 .. @cache_objects.length - 1 do
354
+ assert_equal(Time.name,objects[i].created_at.class.name)
355
+ assert_equal(Time.name,objects[i].updated_at.class.name)
356
+ assert_equal(Time.name,objects[i].approved_at.class.name)
357
+ assert_equal(FalseClass.name,objects[i].is_crawler.class.name)
358
+ assert_equal(TrueClass.name,objects[i].is_public.class.name)
359
+ assert_equal(Fixnum.name,objects[i].mp3size.class.name)
360
+ assert_equal(BigDecimal.name,objects[i].longitude.class.name)
361
+ assert_equal(Bignum.name,objects[i].track_id.class.name)
362
+ assert_equal(String.name,objects[i].play_path.class.name)
363
+
364
+ #VALUE assert
365
+ assert_equal(@cache_objects[i].track_id,objects[i].track_id)
366
+ assert_equal(@cache_objects[i].play_path,objects[i].play_path)
367
+ assert_equal(@cache_objects[i].is_public,objects[i].is_public)
368
+ assert_equal(@cache_objects[i].is_crawler,objects[i].is_crawler)
369
+ assert_equal(@cache_objects[i].longitude,objects[i].longitude)
370
+ assert_equal(@cache_objects[i].approved_at,objects[i].approved_at)
371
+ assert_equal(@cache_objects[i].mp3size,objects[i].mp3size)
372
+ assert_equal(@cache_objects[i].updated_at,objects[i].updated_at)
373
+ assert_equal(@cache_objects[i].created_at,objects[i].created_at)
374
+ end
375
+ puts "FieldObjectCacheTest test_mget_mset_with_field method stop"
376
+
377
+ EventMachine.stop
378
+ end
379
+ end
380
+
381
+ def test_mget_mset_with_field_benchmark
382
+ EM.synchrony do
383
+ puts "FieldObjectCacheTest test_mget_mset_with_field_benchmark method start"
384
+ @field_object_cache.batch_evict @keys
385
+ times = TestHelper::TIMES
386
+ start = Time.now
387
+ for i in 1 .. times do
388
+ @field_object_cache.multi_put_with_field(@cache_objects,@fields)
389
+ end
390
+ stop = Time.now
391
+ puts "#{times} times multi_put_with_field operation total use #{stop-start} seconds"
392
+
393
+ start = Time.now
394
+ for i in 1 .. times do
395
+ @field_object_cache.multi_get_with_field(@keys,@fields)
396
+ end
397
+ stop = Time.now
398
+ puts "#{times} times multi_get_with_field operation total use #{stop-start} seconds"
399
+ puts "FieldObjectCacheTest test_mget_mset_with_field_benchmark method stop"
400
+
401
+ EventMachine.stop
402
+ end
403
+ end
404
+
405
+ def teardown
406
+ super
407
+ @field_object_cache.destroy
408
+ puts "teardown"
409
+ end
410
+ end
411
+
@@ -0,0 +1,271 @@
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 'test_helper'
7
+ require 'em-synchrony'
8
+
9
+ class EMObjectCacheTest < 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_em.yaml')
15
+ caches = Xunch::CacheBuilder.build(file)
16
+ @object_cache = caches["track"]
17
+ hash = TestHelper.build_objects
18
+ @cache_object = hash["object"]
19
+ @cache_objects = hash["objects"]
20
+ @keys = hash["keys"]
21
+ puts "setup"
22
+ end
23
+
24
+ def test_get_set
25
+ EM.synchrony do
26
+ puts "ObjectCacheTest test_get_set method start"
27
+ assert_equal('OK',@object_cache.put(@cache_object))
28
+ object = @object_cache.get(1)
29
+
30
+ # type assert
31
+ assert_equal(Time.name,object.created_at.class.name)
32
+ assert_equal(Time.name,object.updated_at.class.name)
33
+ assert_equal(Time.name,object.approved_at.class.name)
34
+ assert_equal(FalseClass.name,object.is_crawler.class.name)
35
+ assert_equal(TrueClass.name,object.is_public.class.name)
36
+ assert_equal(Fixnum.name,object.mp3size.class.name)
37
+ assert_equal(BigDecimal.name,object.longitude.class.name)
38
+ assert_equal(Bignum.name,object.track_id.class.name)
39
+ assert_equal(String.name,object.play_path.class.name)
40
+
41
+ #value assert
42
+ assert_equal(@cache_object.track_id,object.track_id)
43
+ assert_equal(@cache_object.track_uid,object.track_uid)
44
+ assert_equal(@cache_object.track_upload_source,object.track_upload_source)
45
+ assert_equal(@cache_object.op_type,object.op_type)
46
+ assert_equal(@cache_object.is_publish,object.is_publish)
47
+ assert_equal(@cache_object.upload_source,object.upload_source)
48
+ assert_equal(@cache_object.uid,object.uid)
49
+ assert_equal(@cache_object.nickname,object.nickname)
50
+ assert_equal(@cache_object.avatar_path,object.avatar_path)
51
+ assert_equal(@cache_object.is_v,object.is_v)
52
+ assert_equal(@cache_object.human_category_id,object.human_category_id)
53
+ assert_equal(@cache_object.title,object.title)
54
+ assert_equal(@cache_object.intro,object.intro)
55
+ assert_equal(@cache_object.user_source,object.user_source)
56
+ assert_equal(@cache_object.category_id,object.category_id)
57
+ assert_equal(@cache_object.duration,object.duration)
58
+ assert_equal(@cache_object.play_path,object.play_path)
59
+ assert_equal(@cache_object.play_path_32,object.play_path_32)
60
+ assert_equal(@cache_object.play_path_64,object.play_path_64)
61
+ assert_equal(@cache_object.play_path_128,object.play_path_128)
62
+ assert_equal(@cache_object.transcode_state,object.transcode_state)
63
+ assert_equal(@cache_object.download_path,object.download_path)
64
+ assert_equal(@cache_object.cover_path,object.cover_path)
65
+ assert_equal(@cache_object.album_id,object.album_id)
66
+ assert_equal(@cache_object.album_title,object.album_title)
67
+ assert_equal(@cache_object.album_cover_path,object.album_cover_path)
68
+ assert_equal(@cache_object.tags,object.tags)
69
+ assert_equal(@cache_object.ignore_tags,object.ignore_tags)
70
+ assert_equal(@cache_object.extra_tags,object.extra_tags)
71
+ assert_equal(@cache_object.singer,object.singer)
72
+ assert_equal(@cache_object.singer_category,object.singer_category)
73
+ assert_equal(@cache_object.author,object.author)
74
+ assert_equal(@cache_object.composer,object.composer)
75
+ assert_equal(@cache_object.arrangement,object.arrangement)
76
+ assert_equal(@cache_object.post_production,object.post_production)
77
+ assert_equal(@cache_object.lyric_path,object.lyric_path)
78
+ assert_equal(@cache_object.language,object.language)
79
+ assert_equal(@cache_object.lyric,object.lyric)
80
+ assert_equal(@cache_object.resinger,object.resinger)
81
+ assert_equal(@cache_object.announcer,object.announcer)
82
+ assert_equal(@cache_object.is_public,object.is_public)
83
+ assert_equal(@cache_object.access_password,object.access_password)
84
+ assert_equal(@cache_object.allow_download,object.allow_download)
85
+ assert_equal(@cache_object.allow_comment,object.allow_comment)
86
+ assert_equal(@cache_object.is_crawler,object.is_crawler)
87
+ assert_equal(@cache_object.inet_aton_ip,object.inet_aton_ip)
88
+ assert_equal(@cache_object.longitude,object.longitude)
89
+ assert_equal(@cache_object.latitude,object.latitude)
90
+ assert_equal(@cache_object.music_category,object.music_category)
91
+ assert_equal(@cache_object.order_num,object.order_num)
92
+ assert_equal(@cache_object.is_pick,object.is_pick)
93
+ assert_equal(@cache_object.rich_intro,object.rich_intro)
94
+ assert_equal(@cache_object.short_intro,object.short_intro)
95
+ assert_equal(@cache_object.comment_content,object.comment_content)
96
+ assert_equal(@cache_object.comment_id,object.comment_id)
97
+ assert_equal(@cache_object.dig_status,object.dig_status)
98
+ assert_equal(@cache_object.approved_at,object.approved_at)
99
+ assert_equal(@cache_object.is_deleted,object.is_deleted)
100
+ assert_equal(@cache_object.mp3size,object.mp3size)
101
+ assert_equal(@cache_object.mp3size_32,object.mp3size_32)
102
+ assert_equal(@cache_object.mp3size_64,object.mp3size_64)
103
+ assert_equal(@cache_object.waveform,object.waveform)
104
+ assert_equal(@cache_object.upload_id,object.upload_id)
105
+ assert_equal(@cache_object.updated_at,object.updated_at)
106
+ assert_equal(@cache_object.created_at,object.created_at)
107
+ assert_equal(@cache_object.source_url,object.source_url)
108
+ assert_equal(@cache_object.status,object.status)
109
+ assert_equal(@cache_object.explore_height,object.explore_height)
110
+ assert_equal(@cache_object.id,object.id)
111
+ puts "ObjectCacheTest test_get_set method stop"
112
+ EventMachine.stop
113
+ end
114
+ end
115
+
116
+ def test_get_set_benchmark
117
+ EM.synchrony do
118
+ puts "ObjectCacheTest test_get_set_benchmark method start"
119
+ @object_cache.evict(1)
120
+ times = TestHelper::TIMES
121
+ start = Time.now
122
+ for i in 1 .. times do
123
+ @object_cache.put(@cache_object)
124
+ end
125
+ stop = Time.now
126
+ puts "#{times} times put operation total use #{stop-start} seconds"
127
+
128
+ start = Time.now
129
+ for i in 1 .. times do
130
+ @object_cache.get(1)
131
+ end
132
+ stop = Time.now
133
+ puts "#{times} times get operation total use #{stop-start} seconds"
134
+ puts "ObjectCacheTest test_get_set_benchmark method stop"
135
+
136
+ EventMachine.stop
137
+ end
138
+ end
139
+
140
+ def test_mget_mset
141
+ EM.synchrony do
142
+ puts "ObjectCacheTest test_mget_mset method start"
143
+ result = @object_cache.multi_put(@cache_objects)
144
+ for i in 0 .. result.length - 1 do
145
+ success = false
146
+ if result[i] == "OK" or result[i] == true
147
+ success = true
148
+ end
149
+ assert_equal(true,success)
150
+ end
151
+ objects = @object_cache.multi_get(@keys)
152
+ assert_equal(@cache_objects.length, objects.length)
153
+ for i in 0 .. @cache_objects.length - 1 do
154
+ assert_equal(Time.name,objects[i].created_at.class.name)
155
+ assert_equal(Time.name,objects[i].updated_at.class.name)
156
+ assert_equal(Time.name,objects[i].approved_at.class.name)
157
+ assert_equal(FalseClass.name,objects[i].is_crawler.class.name)
158
+ assert_equal(TrueClass.name,objects[i].is_public.class.name)
159
+ assert_equal(Fixnum.name,objects[i].mp3size.class.name)
160
+ assert_equal(BigDecimal.name,objects[i].longitude.class.name)
161
+ assert_equal(Bignum.name,objects[i].track_id.class.name)
162
+ assert_equal(String.name,objects[i].play_path.class.name)
163
+
164
+ #VALUE assert
165
+ assert_equal(@cache_objects[i].track_id,objects[i].track_id)
166
+ assert_equal(@cache_objects[i].track_uid,objects[i].track_uid)
167
+ assert_equal(@cache_objects[i].track_upload_source,objects[i].track_upload_source)
168
+ assert_equal(@cache_objects[i].op_type,objects[i].op_type)
169
+ assert_equal(@cache_objects[i].is_publish,objects[i].is_publish)
170
+ assert_equal(@cache_objects[i].upload_source,objects[i].upload_source)
171
+ assert_equal(@cache_objects[i].uid,objects[i].uid)
172
+ assert_equal(@cache_objects[i].nickname,objects[i].nickname)
173
+ assert_equal(@cache_objects[i].avatar_path,objects[i].avatar_path)
174
+ assert_equal(@cache_objects[i].is_v,objects[i].is_v)
175
+ assert_equal(@cache_objects[i].human_category_id,objects[i].human_category_id)
176
+ assert_equal(@cache_objects[i].title,objects[i].title)
177
+ assert_equal(@cache_objects[i].intro,objects[i].intro)
178
+ assert_equal(@cache_objects[i].user_source,objects[i].user_source)
179
+ assert_equal(@cache_objects[i].category_id,objects[i].category_id)
180
+ assert_equal(@cache_objects[i].duration,objects[i].duration)
181
+ assert_equal(@cache_objects[i].play_path,objects[i].play_path)
182
+ assert_equal(@cache_objects[i].play_path_32,objects[i].play_path_32)
183
+ assert_equal(@cache_objects[i].play_path_64,objects[i].play_path_64)
184
+ assert_equal(@cache_objects[i].play_path_128,objects[i].play_path_128)
185
+ assert_equal(@cache_objects[i].transcode_state,objects[i].transcode_state)
186
+ assert_equal(@cache_objects[i].download_path,objects[i].download_path)
187
+ assert_equal(@cache_objects[i].cover_path,objects[i].cover_path)
188
+ assert_equal(@cache_objects[i].album_id,objects[i].album_id)
189
+ assert_equal(@cache_objects[i].album_title,objects[i].album_title)
190
+ assert_equal(@cache_objects[i].album_cover_path,objects[i].album_cover_path)
191
+ assert_equal(@cache_objects[i].tags,objects[i].tags)
192
+ assert_equal(@cache_objects[i].ignore_tags,objects[i].ignore_tags)
193
+ assert_equal(@cache_objects[i].extra_tags,objects[i].extra_tags)
194
+ assert_equal(@cache_objects[i].singer,objects[i].singer)
195
+ assert_equal(@cache_objects[i].singer_category,objects[i].singer_category)
196
+ assert_equal(@cache_objects[i].author,objects[i].author)
197
+ assert_equal(@cache_objects[i].composer,objects[i].composer)
198
+ assert_equal(@cache_objects[i].arrangement,objects[i].arrangement)
199
+ assert_equal(@cache_objects[i].post_production,objects[i].post_production)
200
+ assert_equal(@cache_objects[i].lyric_path,objects[i].lyric_path)
201
+ assert_equal(@cache_objects[i].language,objects[i].language)
202
+ assert_equal(@cache_objects[i].lyric,objects[i].lyric)
203
+ assert_equal(@cache_objects[i].resinger,objects[i].resinger)
204
+ assert_equal(@cache_objects[i].announcer,objects[i].announcer)
205
+ assert_equal(@cache_objects[i].is_public,objects[i].is_public)
206
+ assert_equal(@cache_objects[i].access_password,objects[i].access_password)
207
+ assert_equal(@cache_objects[i].allow_download,objects[i].allow_download)
208
+ assert_equal(@cache_objects[i].allow_comment,objects[i].allow_comment)
209
+ assert_equal(@cache_objects[i].is_crawler,objects[i].is_crawler)
210
+ assert_equal(@cache_objects[i].inet_aton_ip,objects[i].inet_aton_ip)
211
+ assert_equal(@cache_objects[i].longitude,objects[i].longitude)
212
+ assert_equal(@cache_objects[i].latitude,objects[i].latitude)
213
+ assert_equal(@cache_objects[i].music_category,objects[i].music_category)
214
+ assert_equal(@cache_objects[i].order_num,objects[i].order_num)
215
+ assert_equal(@cache_objects[i].is_pick,objects[i].is_pick)
216
+ assert_equal(@cache_objects[i].rich_intro,objects[i].rich_intro)
217
+ assert_equal(@cache_objects[i].short_intro,objects[i].short_intro)
218
+ assert_equal(@cache_objects[i].comment_content,objects[i].comment_content)
219
+ assert_equal(@cache_objects[i].comment_id,objects[i].comment_id)
220
+ assert_equal(@cache_objects[i].dig_status,objects[i].dig_status)
221
+ assert_equal(@cache_objects[i].approved_at,objects[i].approved_at)
222
+ assert_equal(@cache_objects[i].is_deleted,objects[i].is_deleted)
223
+ assert_equal(@cache_objects[i].mp3size,objects[i].mp3size)
224
+ assert_equal(@cache_objects[i].mp3size_32,objects[i].mp3size_32)
225
+ assert_equal(@cache_objects[i].mp3size_64,objects[i].mp3size_64)
226
+ assert_equal(@cache_objects[i].waveform,objects[i].waveform)
227
+ assert_equal(@cache_objects[i].upload_id,objects[i].upload_id)
228
+ assert_equal(@cache_objects[i].updated_at,objects[i].updated_at)
229
+ assert_equal(@cache_objects[i].created_at,objects[i].created_at)
230
+ assert_equal(@cache_objects[i].source_url,objects[i].source_url)
231
+ assert_equal(@cache_objects[i].status,objects[i].status)
232
+ assert_equal(@cache_objects[i].explore_height,objects[i].explore_height)
233
+ assert_equal(@cache_objects[i].id,objects[i].id)
234
+ end
235
+ puts "ObjectCacheTest test_mget_mset method stop"
236
+
237
+ EventMachine.stop
238
+ end
239
+ end
240
+
241
+ def test_mget_mset_benchmark
242
+ EM.synchrony do
243
+ puts "ObjectCacheTest test_mget_mset_benchmark method start"
244
+ @object_cache.batch_evict @keys
245
+
246
+ times = TestHelper::TIMES
247
+ start = Time.now
248
+ for i in 1 .. times do
249
+ @object_cache.multi_put(@cache_objects)
250
+ end
251
+ stop = Time.now
252
+ puts "#{times} times multi_put operation total use #{stop-start} seconds"
253
+
254
+ start = Time.now
255
+ for i in 1 .. times do
256
+ @object_cache.multi_get(@keys)
257
+ end
258
+ stop = Time.now
259
+ puts "#{times} times multi_get operation total use #{stop-start} seconds"
260
+ puts "ObjectCacheTest test_mget_mset_benchmark method stop"
261
+
262
+ EventMachine.stop
263
+ end
264
+ end
265
+
266
+ def teardown
267
+ super
268
+ puts "teardown"
269
+ end
270
+ end
271
+
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.9
4
+ version: 0.0.9.1
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-12-05 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -48,6 +48,7 @@ files:
48
48
  - lib/xunch/shard/redis.rb
49
49
  - lib/xunch/shard/shard_info.rb
50
50
  - lib/xunch/shard/shard_redis.rb
51
+ - lib/xunch/shard/ThreadedRedisPool.rb
51
52
  - lib/xunch/cache/cache_builder.rb
52
53
  - lib/xunch/cache/list_field_object_cache.rb
53
54
  - lib/xunch/cache/list_object_cache.rb
@@ -55,6 +56,8 @@ files:
55
56
  - lib/xunch/cache/cache.rb
56
57
  - lib/xunch/cache/field_object_cache.rb
57
58
  - lib/xunch/cache/list_id_cache.rb
59
+ - lib/xunch/connection/fiber_redis_pool.rb
60
+ - lib/xunch/connection/threaded_redis_pool.rb
58
61
  - lib/xunch/utils/rb_tree.rb
59
62
  - lib/xunch/utils/utils.rb
60
63
  - lib/xunch/utils/types.rb
@@ -70,8 +73,11 @@ files:
70
73
  - test/cache_builder_test.rb
71
74
  - test/rb_tree_test.rb
72
75
  - test/redis_client_test.rb
76
+ - test/em_object_cache_test.rb
73
77
  - test/list_field_object_cache_test.rb
78
+ - test/em_field_object_cache_test.rb
74
79
  - test/list_id_cache_test.rb
80
+ - test/em_cache_test.rb
75
81
  - test/hash_codec_test.rb
76
82
  - test/nginx_cache_helper_test.rb
77
83
  - test/object_cache_test.rb
@@ -107,8 +113,11 @@ test_files:
107
113
  - test/cache_builder_test.rb
108
114
  - test/rb_tree_test.rb
109
115
  - test/redis_client_test.rb
116
+ - test/em_object_cache_test.rb
110
117
  - test/list_field_object_cache_test.rb
118
+ - test/em_field_object_cache_test.rb
111
119
  - test/list_id_cache_test.rb
120
+ - test/em_cache_test.rb
112
121
  - test/hash_codec_test.rb
113
122
  - test/nginx_cache_helper_test.rb
114
123
  - test/object_cache_test.rb