stat-count-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stat-count-client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stat-count-client (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ x86-mingw32
12
+
13
+ DEPENDENCIES
14
+ stat-count-client!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Stat::Count::Client
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stat-count-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stat-count-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ #encoding: UTF-8
2
+
3
+ #Example
4
+ #stat.count:
5
+ # hessian.domain: http://localhost:8080/stat-count-runtime/hessian/remoteSimpleCountCollecter
6
+ # hessian.java.package: com.ximalaya.stat.count.data
7
+ # log.file: D:/log/stat/stat-count-ruby.log
8
+ # log.level: info
9
+
10
+ module ConfigLoader
11
+ begin
12
+ LOADER = YAML.load_file("../config/stat-count-client.yaml");
13
+ CONFIG = LOADER['stat.count']
14
+ rescue => err
15
+ CONFIG = {}
16
+ puts "can't load config file stat-count-client.yaml, you need to init statcountclient with config hash"
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ #encoding: UTF-8
2
+
3
+ module Hessian
4
+ module Data
5
+ module Utils
6
+ def to_hash_unit
7
+ hash = {}
8
+ instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
9
+ hash
10
+ end
11
+
12
+ def to_hash_map
13
+ hash = {}
14
+ instance_variables.each {|var|
15
+ internal_hash = {}
16
+ map = instance_variable_get(var)
17
+ map.each { |key, list|
18
+ newList = nil
19
+ list.each { |unit|
20
+ if (newList.nil?)
21
+ newList = Array.new
22
+ end
23
+ newList << unit.to_hessian
24
+ }
25
+ internal_hash[key] = newList
26
+ }
27
+ hash[var.to_s.delete("@")] = internal_hash
28
+ }
29
+ hash
30
+ end
31
+
32
+ def java_class_name(java_package)
33
+ index = self.class.name.rindex "::"
34
+ index = (index.nil?) ? 0 : index+2
35
+ simple_name = self.class.name[index..-1]
36
+ java_package.nil? ? simple_name : java_package + "." + simple_name
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ #encoding: UTF-8
2
+
3
+ require "logger"
4
+ require "config_loader"
5
+ require "monitor"
6
+
7
+ class LoggerFactory
8
+ include ConfigLoader
9
+ @@logger = nil
10
+ def self.getLogger(name, log_path=nil, log_level=nil)
11
+ if @@logger.nil?
12
+ @monitor = Monitor.new
13
+ @monitor.synchronize do
14
+ if @@logger.nil?
15
+ if(log_path.nil?)
16
+ log_path = CONFIG['log.file.'+name];
17
+ if(log_path.nil?)
18
+ log_path = "../log"
19
+ end
20
+ end
21
+
22
+ if log_level.nil?
23
+ log_level = CONFIG['log.level.'+name]
24
+ if(log_level.nil?)
25
+ log_level = "error";
26
+ end
27
+ end
28
+
29
+ logger = Logger.new(log_path,'daily')
30
+ logger.level = Logger::const_get(log_level.upcase)
31
+ @@logger = logger;
32
+ end
33
+ end
34
+ end
35
+ @@logger
36
+ end
37
+ end
@@ -0,0 +1,335 @@
1
+ #encoding: UTF-8
2
+
3
+ require "stat-count-client/version"
4
+ require "yaml"
5
+ require "config_loader"
6
+ require "logger_factory"
7
+ require "singleton"
8
+ require "hessian_data_utils"
9
+
10
+
11
+ module Stat
12
+ module Count
13
+ module Data
14
+ class QueryUnit
15
+ include Hessian::Data::Utils
16
+ include ConfigLoader
17
+
18
+ attr :id, true
19
+ attr :limit, true
20
+
21
+ def to_hash
22
+ to_hash_unit
23
+ end
24
+
25
+ def to_hessian
26
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
27
+ end
28
+ end
29
+
30
+ class CountUnit
31
+ include Hessian::Data::Utils
32
+ include ConfigLoader
33
+
34
+ attr :id, true
35
+ attr :count, true
36
+
37
+ def to_hash
38
+ to_hash_unit
39
+ end
40
+
41
+ def to_hessian
42
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
43
+ end
44
+ end
45
+
46
+ class DateQueryUnit < QueryUnit
47
+ attr :fromDate, true
48
+ attr :toDate, true
49
+ end
50
+
51
+ class DateCountUnit < CountUnit
52
+ attr :date, true
53
+
54
+ def to_hessian
55
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
56
+ end
57
+ end
58
+
59
+ class SimpleCount
60
+ include Hessian::Data::Utils
61
+ include ConfigLoader
62
+
63
+ attr_accessor :counts
64
+
65
+ def initialize
66
+ @counts = Hash.new
67
+ end
68
+
69
+ def addCount(name, id, count=1, countUnit=nil)
70
+ countUnitList = @counts[name]
71
+ if (countUnitList.nil?)
72
+ countUnitList = Array.new
73
+ @counts[name] = countUnitList
74
+ end
75
+
76
+ if (countUnit.nil?)
77
+ countUnit = CountUnit.new
78
+ end
79
+ countUnit.id = id
80
+ countUnit.count = count
81
+ countUnitList << countUnit
82
+ self
83
+ end
84
+
85
+ def getCounts
86
+ @counts
87
+ end
88
+
89
+ def getCountsSize
90
+ @counts.length
91
+ end
92
+
93
+ def to_hash
94
+ to_hash_map
95
+ end
96
+
97
+ def to_hessian
98
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
99
+ end
100
+ end
101
+
102
+ class DateCount < SimpleCount
103
+ def addCountWithDate(name, id, count=1, date=Time.now)
104
+ dateCountUnit = DateCountUnit.new
105
+ dateCountUnit.date = date
106
+ addCount(name, id, count, dateCountUnit)
107
+ self
108
+ end
109
+
110
+ def to_hessian
111
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
112
+ end
113
+ end
114
+
115
+ class SimpleCountQuery
116
+ include Hessian::Data::Utils
117
+ include ConfigLoader
118
+
119
+ attr_accessor :queries
120
+
121
+ def initialize
122
+ @queries = Hash.new
123
+ end
124
+
125
+ def addQuery(name, id, limit=1, queryUnit=nil)
126
+ queryUnitList = @queries[name]
127
+
128
+ if(queryUnitList.nil?)
129
+ queryUnitList = Array.new
130
+ @queries[name] = queryUnitList
131
+ end
132
+
133
+ if(queryUnit.nil?)
134
+ queryUnit = QueryUnit.new
135
+ end
136
+
137
+ queryUnit.id = id
138
+ queryUnit.limit = limit
139
+ queryUnitList << queryUnit
140
+ self
141
+ end
142
+
143
+ def getQueries
144
+ @queries
145
+ end
146
+
147
+ def to_hash
148
+ to_hash_map
149
+ end
150
+
151
+ def to_hessian
152
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
153
+ end
154
+ end
155
+
156
+ class DateCountQuery < SimpleCountQuery
157
+ def addQueryWithDate(name, id, fromDate, toDate, limit=1)
158
+ queryUnit = DateQueryUnit.new
159
+ addQuery(name, id, limit, queryUnit)
160
+ self
161
+ end
162
+
163
+ def to_hessian
164
+ Hessian2::TypeWrapper.new(java_class_name("com.ximalaya.stat.count.data"), to_hash)
165
+ end
166
+ end
167
+
168
+ class CountResult
169
+ attr_accessor :countResults
170
+
171
+ def initialize(hash)
172
+ @countResults = hash['countResults']
173
+ end
174
+
175
+ def getResult(name=nil, id=nil)
176
+ if(name.nil?)
177
+ return @countResults
178
+ end
179
+
180
+ countHash = @countResults[name]
181
+ if(countHash.nil?)
182
+ raise ArgumentError,"服务的名称: " + name + " 不存在!"
183
+ end
184
+
185
+ if (id.nil?)
186
+ return countHash
187
+ end
188
+
189
+ count = countHash[id]
190
+ if(count.nil?)
191
+ railse ArgumentError,"业务ID: "+id +" 不存在"
192
+ end
193
+ count
194
+ end
195
+ end
196
+
197
+ end
198
+
199
+ module Client
200
+ class StatCountClient
201
+ include Stat::Count::Data
202
+ include ConfigLoader
203
+
204
+ def initialize(config={})
205
+ @hessian_url = config['hessian.domain'];
206
+ if (@hessian_url.nil?)
207
+ @hessian_url ||= ENV['stat.count.domain']
208
+ @hessian_url ||= CONFIG['hessian.domain']
209
+ end
210
+ @logger = LoggerFactory.getLogger("StatCountClient", config['log.file.StatCountClient'], config['log.level.StatCountClient'])
211
+
212
+ init(@hessian_url)
213
+ end
214
+
215
+ def incrByCountWithDate(dateCount)
216
+ wrapper = dateCount.to_hessian
217
+ @client.incrByCountWithDate(wrapper)
218
+ end
219
+
220
+ def incrByCount(count)
221
+ wrapper = count.to_hessian
222
+ countResult = @client.incrByCount(wrapper)
223
+ CountResult.new(countResult)
224
+ end
225
+
226
+ def incr(name, id, count=1, date=nil)
227
+ if(date.nil?)
228
+ @client.incrBy(name,id, count)
229
+ else
230
+ @client.incrByWithDate(name, id, count, date)
231
+ end
232
+ end
233
+
234
+ def decr(name, id, count=1, date=nil)
235
+ if(date.nil?)
236
+ @client.decrBy(name, id, count)
237
+ else
238
+ @client.decrByWithDate(name, id, count, date)
239
+ end
240
+ end
241
+
242
+ def decrByCount(count)
243
+ wrapper = count.to_hessian
244
+ count_result = @client.decrByCount(wrapper)
245
+ CountResult.new(count_result)
246
+ end
247
+
248
+ def decrByCountWithDate(dateCount)
249
+ wrapper = dateCount.to_hessian
250
+ @client.decrByCountWithDate(wrapper)
251
+ end
252
+
253
+ def setByCountWithDate(dateCount)
254
+ wrapper = dateCount.to_hessian
255
+ @client.setByCountWithDate(wrapper)
256
+ end
257
+
258
+ def setByCount(count)
259
+ wrapper = count.to_hessian
260
+ @client.setByCount(wrapper)
261
+ end
262
+
263
+ def set(name,id, value, date=nil)
264
+ if(date.nil?)
265
+ @client.set(name, id, value)
266
+ else
267
+ @client.setWithDate(name,id, value,date)
268
+ end
269
+ end
270
+
271
+ def reset(name, id, limit=1)
272
+ @client.resetByLimit(name, id, limit)
273
+ end
274
+
275
+ def get(name, id, limit=1)
276
+ @client.getByLimit(name, id, limit)
277
+ end
278
+
279
+ def getByNames(name, id, limit=1)
280
+ @client.getByNamesAndLimit(name, id, limit)
281
+ end
282
+
283
+ def getByIds(name, ids, limit=1)
284
+ @client.getByIdsAndLimit(name, ids, limit)
285
+ end
286
+
287
+ def getByQuery(query)
288
+ wrapper = query.to_hessian
289
+ countResult = @client.getByQuery(wrapper)
290
+ CountResult.new(countResult)
291
+ end
292
+
293
+ def getByDateQuery(dateQuery)
294
+ wrapper = dateQuery.to_hessian
295
+ countResult = @client.getByDateQuery(wrapper)
296
+ CountResult.new(countResult)
297
+ end
298
+
299
+ def delByQuery(query)
300
+ wrapper = query.to_hessian
301
+ @client.delByQuery(wrapper)
302
+ end
303
+
304
+ def delByDateQuery(dateQuery)
305
+ wrapper = dateQuery.to_hessian
306
+ @client.delByDateQuery(wrapper)
307
+ end
308
+
309
+ def getHello
310
+ @client.getHello()
311
+ end
312
+
313
+ def getHello1
314
+ @client.getHello1()
315
+ end
316
+
317
+ private
318
+ def init(hessian_url)
319
+ if(hessian_url.nil?)
320
+ raise ArgumentError.new("hessian url is null or empty")
321
+ end
322
+
323
+ @logger.info("Init Stat count client connect to hessian url: #{hessian_url}")
324
+ begin
325
+ @client = Hessian2::HessianClient.new(@hessian_url)
326
+ rescue => err
327
+ @logger.error("init hessian service fails!", err)
328
+ raise err
329
+ end
330
+ end
331
+
332
+ end
333
+ end
334
+ end
335
+ end
@@ -0,0 +1,7 @@
1
+ module Stat
2
+ module Count
3
+ module Client
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "rake"
4
+ require File.expand_path('../lib/stat-count-client/version', __FILE__)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["gavin"]
8
+ gem.email = ["gavin@ximalya.com"]
9
+ gem.description = %q{ruby client for stat count server}
10
+ gem.summary = %q{stat count client}
11
+ gem.homepage = "http://www.ximalaya.com"
12
+ gem.platform = Gem::Platform::RUBY
13
+ gem.files = Dir['[A-Z]*'] + Dir['test/**/*'] + Dir['lib/**/*']
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "stat-count-client"
17
+ gem.require_paths = ["lib", "test"]
18
+ gem.version = Stat::Count::Client::VERSION
19
+
20
+ gem.add_dependency "hessian2"
21
+ end
@@ -0,0 +1,80 @@
1
+ #encoding: UTF-8
2
+
3
+ require "rubygems"
4
+ require "stat-count-client"
5
+
6
+ class CountMother
7
+ include Stat::Count::Data
8
+
9
+ def self.createIncrCount
10
+ SimpleCount.new.addCount("test", "1", 1).addCount("test", "1", 2).addCount("testHour", "2", 4).addCount("testDay", "3", 8)
11
+ end
12
+
13
+ def self.createIncrCountWithDate
14
+ dateCount = DateCount.new
15
+ now = Time.new
16
+
17
+ 1.upto(5) do |j|
18
+ 0.upto(9) do |i|
19
+ now_second = Time.now.to_i
20
+ time = now - 60* 60 * i
21
+ dateCount.addCountWithDate("testHour", j.to_s, j, time)
22
+ end
23
+ end
24
+
25
+ 1.upto(5) do |j|
26
+ 0.upto(9) do |i|
27
+ now_second = Time.now.to_i
28
+ time = now - 86400 * i
29
+ dateCount.addCountWithDate("testDay", j.to_s, j, time);
30
+ end
31
+ end
32
+
33
+ dateCount
34
+ end
35
+
36
+ def self.createDecrCountWithDate
37
+ dateCount = DateCount.new
38
+ now = Time.new
39
+
40
+ 1.upto(5) do |j|
41
+ 0.upto(9) do |i|
42
+ count.addCount("testHour", j.to_s, 1, Time.now - i.day)
43
+ end
44
+ end
45
+
46
+ 1.upto(5) do |j|
47
+ 0.upto(9) do |i|
48
+ count.addCount("testDay", j.to_s, j, Time.now - i.day);
49
+ end
50
+ end
51
+ end
52
+
53
+ def self.initCount
54
+ SimpleCount.new.addCount("test", "1", 10).addCount("test", "1", 10).addCount("testHour", "2", 10).addCount("testDay", "3", 10)
55
+ end
56
+
57
+ def self.createDecrCount
58
+ SimpleCount.new.addCount("test", "1", 4).addCount("test", "1", 5).addCount("testHour", "2", 8).addCount("testDay", "3", 7)
59
+ end
60
+
61
+ def self.createCountQuery
62
+ SimpleCountQuery.new.addQuery("test", "1").addQuery("testHour", "2").addQuery("testDay", "3")
63
+ end
64
+
65
+ def self.createCountQueryWithDate
66
+ countQuery = SimpleCountQuery.new
67
+
68
+ 1.upto(5) do |i|
69
+ countQuery.addQuery("testHour", i.to_s, 10)
70
+ end
71
+
72
+ 1.upto(5) do |i|
73
+ countQuery.addQuery "testDay", i.to_s, 10
74
+ end
75
+
76
+ countQuery
77
+ end
78
+
79
+
80
+ end
@@ -0,0 +1,192 @@
1
+ #encoding: UTF-8
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
4
+ $:.unshift File.join(File.dirname(__FILE__),"..")
5
+
6
+ require "rubygems"
7
+ require "hessian2"
8
+ require "stat-count-client"
9
+ require_relative "count_mother"
10
+ require "test/unit"
11
+
12
+ class TC_StatCountClientTest < Test::Unit::TestCase
13
+ include Stat::Count::Client
14
+ # Called before every test method runs. Can be used
15
+ # to set up fixture information.
16
+ def setup
17
+ @client = StatCountClient.new({'hessian.domain'=>'http://localhost:8080/stat-count-runtime/hessian/remoteSimpleCountCollecter', 'log.file.StatCountClient'=>'D:/log/stat/stat-count-ruby.log'});
18
+ puts @client
19
+ end
20
+
21
+ # Called after every test method runs. Can be used to tear
22
+ # down fixture information.
23
+
24
+ def teardown
25
+ # Do nothing
26
+ end
27
+
28
+ # Fake test
29
+ #def test_incr
30
+ # @client.set("testDay", "1", 1)
31
+ # value = @client.incr("testDay", "1", 2)
32
+ # assert_equal(3, value)
33
+ #end
34
+ #
35
+ #def test_incrByCount
36
+ # reset()
37
+ # count = CountMother.createIncrCount
38
+ # countResult = @client.incrByCount(count)
39
+ # puts countResult.getResult()
40
+ # assertCorrect(countResult)
41
+ #end
42
+ #
43
+ #def test_incrByCountWithDate
44
+ # resetWithDate()
45
+ # dateCount = CountMother.createIncrCountWithDate
46
+ # @client.incrByCountWithDate(dateCount)
47
+ # dateQuery = CountMother.createCountQueryWithDate
48
+ # countResult = @client.getByQuery(dateQuery)
49
+ # assertIncrCorrectWithDate(countResult)
50
+ #end
51
+
52
+ def testDecr
53
+ #@client.set("user.tracks.count", "1", 0)
54
+ #begin
55
+ # val = @client.decr("user.tracks.count", "1", 7)
56
+ # assert_equal(0,val)
57
+ #rescue => err
58
+ # puts err
59
+ #end
60
+ #
61
+ #getVal = @client.get("user.tracks.count", "1")
62
+ #assert_equal(0,getVal)
63
+
64
+ puts @client.getHello()
65
+ puts @client.getHello1()
66
+ end
67
+
68
+ #def testDecrByCount
69
+ # count = CountMother.initCount
70
+ # @client.setByCount(count)
71
+ # count = CountMother.createDecrCount
72
+ # countResult = @client.decrByCount(count)
73
+ # assertDecrCorrect(countResult)
74
+ # reset()
75
+ #end
76
+ #
77
+ #def test_set
78
+ # @client.reset("test", "1")
79
+ # @client.set("test", "1", 100000000000000000)
80
+ # val = @client.get("test", "1");
81
+ # assert_equal(100000000000000000, val)
82
+ #end
83
+ #
84
+ #def test_setByCount
85
+ # reset()
86
+ # count = CountMother.initCount
87
+ # @client.setByCount(count)
88
+ # query = CountMother.createCountQuery();
89
+ # countResult = @client.getByQuery(query)
90
+ # assertInitCorrect(countResult)
91
+ #end
92
+ #
93
+ #def test_del
94
+ # count = CountMother.initCount
95
+ # @client.setByCount(count)
96
+ # query = CountMother.createCountQuery()
97
+ # @client.delByQuery(query)
98
+ # countResult = @client.getByQuery(query)
99
+ # assertDel(countResult)
100
+ #end
101
+ #
102
+ #private
103
+ #def resetWithDate
104
+ # 1.upto(5) do |i|
105
+ # @client.reset("testHour", i.to_s, 10)
106
+ # end
107
+ #
108
+ # 1.upto(5) do |i|
109
+ # @client.reset "testDay", i.to_s, 10
110
+ # end
111
+ #end
112
+ #
113
+ #def reset
114
+ # @client.reset("test", "1")
115
+ # @client.reset("testHour", "2")
116
+ # @client.reset("testDay", "3")
117
+ #end
118
+
119
+ def assertCorrect(countResult)
120
+ count = countResult.getResult("test", "1")
121
+ assert_equal(3, count)
122
+
123
+ count = countResult.getResult("testHour", "2")
124
+ assert_equal(4, count)
125
+
126
+ count = countResult.getResult("testDay", "3")
127
+ assert_equal(8, count)
128
+ end
129
+
130
+ def assertIncrCorrectWithDate(countResult)
131
+ resultMap = countResult.getResult("testHour")
132
+
133
+ resultMap.each { |key, value|
134
+ id_val = key.to_i
135
+ assert_equal(id_val * 10, value)
136
+ }
137
+
138
+ resultMap = countResult.getResult("testDay");
139
+
140
+ resultMap.each { |key, value|
141
+ id_val = key.to_i
142
+ assert_equal(id_val * 10, value)
143
+ }
144
+ end
145
+
146
+ def assertDecrCorrectWithDate(countResult)
147
+ resultMap = countResult.getResult("testHour")
148
+ resultMap.each { |key, value|
149
+ id_val = new Integer(key)
150
+ assert_equal(id_val * 10 - 10, value)
151
+ }
152
+
153
+ resultMap = countResult.getResult("testDay")
154
+ resultMap.each { |key, value|
155
+ id_val = new Integer(key)
156
+ assert_equal(id_val * 10 - 10 ,value)
157
+ }
158
+ end
159
+
160
+ def assertDecrCorrect(countResult)
161
+ count = countResult.getResult("test", "1")
162
+ assert_equal(1, count)
163
+
164
+ count = countResult.getResult("testHour", "2")
165
+ assert_equal(2, count)
166
+
167
+ count = countResult.getResult("testDay", "3")
168
+ assert_equal(3, count)
169
+ end
170
+
171
+ def assertInitCorrect(countResult)
172
+ count = countResult.getResult("test", "1")
173
+ assert_equal(10, count)
174
+
175
+ count = countResult.getResult("testHour", "2")
176
+ assert_equal(10, count)
177
+
178
+ count = countResult.getResult("testDay", "3")
179
+ assert_equal(10, count);
180
+ end
181
+
182
+ def assertDel(countResult)
183
+ count = countResult.getResult("test", "1")
184
+ assert_equal(0, count)
185
+
186
+ count = countResult.getResult("testHour", "2")
187
+ assert_equal(0, count)
188
+
189
+ count = countResult.getResult("testDay", "3")
190
+ assert_equal(0, count);
191
+ end
192
+ end
data/test/test.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "hessian2"
3
+ require "stat-count-client"
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
6
+
7
+ class Test
8
+ include Stat::Count::Data
9
+ def testHessian
10
+ count = SimpleCount.new
11
+ count = Test.new
12
+ index = count.class.name.rindex "::"
13
+ index = (index.nil?) ? 0 : index+2
14
+ puts count.class.name[index..-1]
15
+ end
16
+ end
17
+ test = Test.new
18
+ test.testHessian
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stat-count-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - gavin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hessian2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ruby client for stat count server
31
+ email:
32
+ - gavin@ximalya.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - Rakefile
41
+ - README.md
42
+ - stat-count-client.gemspec
43
+ - test/count_mother.rb
44
+ - test/stat_ccount_client_test.rb
45
+ - test/test.rb
46
+ - lib/config_loader.rb
47
+ - lib/hessian_data_utils.rb
48
+ - lib/logger_factory.rb
49
+ - lib/stat-count-client/version.rb
50
+ - lib/stat-count-client.rb
51
+ homepage: http://www.ximalaya.com
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ - test
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: stat count client
76
+ test_files:
77
+ - test/count_mother.rb
78
+ - test/stat_ccount_client_test.rb
79
+ - test/test.rb