stat-count-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -0
- data/doc/collecter.thrift +299 -0
- data/doc/gen.txt +1 -0
- data/lib/config_loader.rb +2 -7
- data/lib/hessian_data_utils.rb +0 -7
- data/lib/logger_factory.rb +7 -12
- data/lib/stat-count-client.rb +2 -332
- data/lib/stat-count-client/config_loader.rb +13 -0
- data/lib/stat-count-client/hessian/stat_data_utils.rb +16 -0
- data/lib/stat-count-client/hessian_client.rb +179 -0
- data/lib/stat-count-client/logger_factory.rb +32 -0
- data/lib/stat-count-client/stat_count_data.rb +135 -0
- data/lib/stat-count-client/thrift/collecter_constants.rb +15 -0
- data/lib/stat-count-client/thrift/collecter_types.rb +209 -0
- data/lib/stat-count-client/thrift/remote_simple_count_collecter.rb +1766 -0
- data/lib/stat-count-client/thrift_client.rb +263 -0
- data/lib/stat-count-client/version.rb +1 -1
- data/test/stat_ccount_client_test.rb +76 -87
- data/test/stat_count_client_test.rb +181 -0
- data/test/thrift_count_client_test.rb +181 -0
- metadata +39 -15
- data/Gemfile.lock +0 -14
- data/stat-count-client.gemspec +0 -21
@@ -0,0 +1,181 @@
|
|
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();
|
18
|
+
end
|
19
|
+
|
20
|
+
# Called after every test method runs. Can be used to tear
|
21
|
+
# down fixture information.
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
# Do nothing
|
25
|
+
end
|
26
|
+
|
27
|
+
# Fake test
|
28
|
+
def test_incr
|
29
|
+
@client.set("testDay", "1", 1)
|
30
|
+
value = @client.incr("testDay", "1", 2)
|
31
|
+
assert_equal(3, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_incrByCount
|
35
|
+
reset()
|
36
|
+
count = CountMother.createIncrCount
|
37
|
+
countResult = @client.incrByCount(count)
|
38
|
+
puts countResult.getResult()
|
39
|
+
assertCorrect(countResult)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_incrByCountWithDate
|
43
|
+
resetWithDate()
|
44
|
+
dateCount = CountMother.createIncrCountWithDate
|
45
|
+
@client.incrByCountWithDate(dateCount)
|
46
|
+
dateQuery = CountMother.createCountQueryWithDate
|
47
|
+
countResult = @client.getByQuery(dateQuery)
|
48
|
+
assertIncrCorrectWithDate(countResult)
|
49
|
+
end
|
50
|
+
|
51
|
+
def testDecr
|
52
|
+
@client.set("test", "1", 10)
|
53
|
+
val = @client.decr("test", "1", 7)
|
54
|
+
assert_equal(3,val)
|
55
|
+
end
|
56
|
+
|
57
|
+
def testDecrByCount
|
58
|
+
count = CountMother.initCount
|
59
|
+
@client.setByCount(count)
|
60
|
+
count = CountMother.createDecrCount
|
61
|
+
countResult = @client.decrByCount(count)
|
62
|
+
assertDecrCorrect(countResult)
|
63
|
+
reset()
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_set
|
67
|
+
@client.reset("test", "1")
|
68
|
+
@client.set("test", "1", 100000000000000000)
|
69
|
+
val = @client.get("test", "1");
|
70
|
+
assert_equal(100000000000000000, val)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_setByCount
|
74
|
+
reset()
|
75
|
+
count = CountMother.initCount
|
76
|
+
@client.setByCount(count)
|
77
|
+
query = CountMother.createCountQuery();
|
78
|
+
countResult = @client.getByQuery(query)
|
79
|
+
assertInitCorrect(countResult)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_del
|
83
|
+
count = CountMother.initCount
|
84
|
+
@client.setByCount(count)
|
85
|
+
query = CountMother.createCountQuery()
|
86
|
+
@client.delByQuery(query)
|
87
|
+
countResult = @client.getByQuery(query)
|
88
|
+
assertDel(countResult)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def resetWithDate
|
93
|
+
1.upto(5) do |i|
|
94
|
+
@client.reset("testHour", i.to_s, 10)
|
95
|
+
end
|
96
|
+
|
97
|
+
1.upto(5) do |i|
|
98
|
+
@client.reset "testDay", i.to_s, 10
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def reset
|
103
|
+
@client.reset("test", "1")
|
104
|
+
@client.reset("testHour", "2")
|
105
|
+
@client.reset("testDay", "3")
|
106
|
+
end
|
107
|
+
|
108
|
+
def assertCorrect(countResult)
|
109
|
+
count = countResult.getResult("test", "1")
|
110
|
+
assert_equal(3, count)
|
111
|
+
|
112
|
+
count = countResult.getResult("testHour", "2")
|
113
|
+
assert_equal(4, count)
|
114
|
+
|
115
|
+
count = countResult.getResult("testDay", "3")
|
116
|
+
assert_equal(8, count)
|
117
|
+
end
|
118
|
+
|
119
|
+
def assertIncrCorrectWithDate(countResult)
|
120
|
+
resultMap = countResult.getResult("testHour")
|
121
|
+
|
122
|
+
resultMap.each { |key, value|
|
123
|
+
id_val = key.to_i
|
124
|
+
assert_equal(id_val * 10, value)
|
125
|
+
}
|
126
|
+
|
127
|
+
resultMap = countResult.getResult("testDay");
|
128
|
+
|
129
|
+
resultMap.each { |key, value|
|
130
|
+
id_val = key.to_i
|
131
|
+
assert_equal(id_val * 10, value)
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
def assertDecrCorrectWithDate(countResult)
|
136
|
+
resultMap = countResult.getResult("testHour")
|
137
|
+
resultMap.each { |key, value|
|
138
|
+
id_val = new Integer(key)
|
139
|
+
assert_equal(id_val * 10 - 10, value)
|
140
|
+
}
|
141
|
+
|
142
|
+
resultMap = countResult.getResult("testDay")
|
143
|
+
resultMap.each { |key, value|
|
144
|
+
id_val = new Integer(key)
|
145
|
+
assert_equal(id_val * 10 - 10 ,value)
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
def assertDecrCorrect(countResult)
|
150
|
+
count = countResult.getResult("test", "1")
|
151
|
+
assert_equal(1, count)
|
152
|
+
|
153
|
+
count = countResult.getResult("testHour", "2")
|
154
|
+
assert_equal(2, count)
|
155
|
+
|
156
|
+
count = countResult.getResult("testDay", "3")
|
157
|
+
assert_equal(3, count)
|
158
|
+
end
|
159
|
+
|
160
|
+
def assertInitCorrect(countResult)
|
161
|
+
count = countResult.getResult("test", "1")
|
162
|
+
assert_equal(10, count)
|
163
|
+
|
164
|
+
count = countResult.getResult("testHour", "2")
|
165
|
+
assert_equal(10, count)
|
166
|
+
|
167
|
+
count = countResult.getResult("testDay", "3")
|
168
|
+
assert_equal(10, count);
|
169
|
+
end
|
170
|
+
|
171
|
+
def assertDel(countResult)
|
172
|
+
count = countResult.getResult("test", "1")
|
173
|
+
assert_equal(0, count)
|
174
|
+
|
175
|
+
count = countResult.getResult("testHour", "2")
|
176
|
+
assert_equal(0, count)
|
177
|
+
|
178
|
+
count = countResult.getResult("testDay", "3")
|
179
|
+
assert_equal(0, count);
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,181 @@
|
|
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 = ThriftStatCountClient.new("localhost:9095");
|
18
|
+
end
|
19
|
+
|
20
|
+
# Called after every test method runs. Can be used to tear
|
21
|
+
# down fixture information.
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
# Do nothing
|
25
|
+
end
|
26
|
+
|
27
|
+
# Fake test
|
28
|
+
def test_incr
|
29
|
+
@client.set("testDay", "1", 1)
|
30
|
+
value = @client.incr("testDay", "1", 2)
|
31
|
+
assert_equal(3, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_incrByCount
|
35
|
+
reset()
|
36
|
+
count = CountMother.createIncrCount
|
37
|
+
countResult = @client.incrByCount(count)
|
38
|
+
puts countResult.getResult()
|
39
|
+
assertCorrect(countResult)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_incrByCountWithDate
|
43
|
+
resetWithDate()
|
44
|
+
dateCount = CountMother.createIncrCountWithDate
|
45
|
+
@client.incrByCountWithDate(dateCount)
|
46
|
+
dateQuery = CountMother.createCountQueryWithDate
|
47
|
+
countResult = @client.getByQuery(dateQuery)
|
48
|
+
assertIncrCorrectWithDate(countResult)
|
49
|
+
end
|
50
|
+
|
51
|
+
def testDecr
|
52
|
+
@client.set("test", "1", 10)
|
53
|
+
val = @client.decr("test", "1", 7)
|
54
|
+
assert_equal(3,val)
|
55
|
+
end
|
56
|
+
|
57
|
+
def testDecrByCount
|
58
|
+
count = CountMother.initCount
|
59
|
+
@client.setByCount(count)
|
60
|
+
count = CountMother.createDecrCount
|
61
|
+
countResult = @client.decrByCount(count)
|
62
|
+
assertDecrCorrect(countResult)
|
63
|
+
reset()
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_set
|
67
|
+
@client.reset("test", "1")
|
68
|
+
@client.set("test", "1", 100000000000000000)
|
69
|
+
val = @client.get("test", "1");
|
70
|
+
assert_equal(100000000000000000, val)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_setByCount
|
74
|
+
reset()
|
75
|
+
count = CountMother.initCount
|
76
|
+
@client.setByCount(count)
|
77
|
+
query = CountMother.createCountQuery();
|
78
|
+
countResult = @client.getByQuery(query)
|
79
|
+
assertInitCorrect(countResult)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_del
|
83
|
+
count = CountMother.initCount
|
84
|
+
@client.setByCount(count)
|
85
|
+
query = CountMother.createCountQuery()
|
86
|
+
@client.delByQuery(query)
|
87
|
+
countResult = @client.getByQuery(query)
|
88
|
+
assertDel(countResult)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def resetWithDate
|
93
|
+
1.upto(5) do |i|
|
94
|
+
@client.reset("testHour", i.to_s, 10)
|
95
|
+
end
|
96
|
+
|
97
|
+
1.upto(5) do |i|
|
98
|
+
@client.reset "testDay", i.to_s, 10
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def reset
|
103
|
+
@client.reset("test", "1")
|
104
|
+
@client.reset("testHour", "2")
|
105
|
+
@client.reset("testDay", "3")
|
106
|
+
end
|
107
|
+
|
108
|
+
def assertCorrect(countResult)
|
109
|
+
count = countResult.getResult("test", "1")
|
110
|
+
assert_equal(3, count)
|
111
|
+
|
112
|
+
count = countResult.getResult("testHour", "2")
|
113
|
+
assert_equal(4, count)
|
114
|
+
|
115
|
+
count = countResult.getResult("testDay", "3")
|
116
|
+
assert_equal(8, count)
|
117
|
+
end
|
118
|
+
|
119
|
+
def assertIncrCorrectWithDate(countResult)
|
120
|
+
resultMap = countResult.getResult("testHour")
|
121
|
+
|
122
|
+
resultMap.each { |key, value|
|
123
|
+
id_val = key.to_i
|
124
|
+
assert_equal(id_val * 10, value)
|
125
|
+
}
|
126
|
+
|
127
|
+
resultMap = countResult.getResult("testDay");
|
128
|
+
|
129
|
+
resultMap.each { |key, value|
|
130
|
+
id_val = key.to_i
|
131
|
+
assert_equal(id_val * 10, value)
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
def assertDecrCorrectWithDate(countResult)
|
136
|
+
resultMap = countResult.getResult("testHour")
|
137
|
+
resultMap.each { |key, value|
|
138
|
+
id_val = new Integer(key)
|
139
|
+
assert_equal(id_val * 10 - 10, value)
|
140
|
+
}
|
141
|
+
|
142
|
+
resultMap = countResult.getResult("testDay")
|
143
|
+
resultMap.each { |key, value|
|
144
|
+
id_val = new Integer(key)
|
145
|
+
assert_equal(id_val * 10 - 10 ,value)
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
def assertDecrCorrect(countResult)
|
150
|
+
count = countResult.getResult("test", "1")
|
151
|
+
assert_equal(1, count)
|
152
|
+
|
153
|
+
count = countResult.getResult("testHour", "2")
|
154
|
+
assert_equal(2, count)
|
155
|
+
|
156
|
+
count = countResult.getResult("testDay", "3")
|
157
|
+
assert_equal(3, count)
|
158
|
+
end
|
159
|
+
|
160
|
+
def assertInitCorrect(countResult)
|
161
|
+
count = countResult.getResult("test", "1")
|
162
|
+
assert_equal(10, count)
|
163
|
+
|
164
|
+
count = countResult.getResult("testHour", "2")
|
165
|
+
assert_equal(10, count)
|
166
|
+
|
167
|
+
count = countResult.getResult("testDay", "3")
|
168
|
+
assert_equal(10, count);
|
169
|
+
end
|
170
|
+
|
171
|
+
def assertDel(countResult)
|
172
|
+
count = countResult.getResult("test", "1")
|
173
|
+
assert_equal(0, count)
|
174
|
+
|
175
|
+
count = countResult.getResult("testHour", "2")
|
176
|
+
assert_equal(0, count)
|
177
|
+
|
178
|
+
count = countResult.getResult("testDay", "3")
|
179
|
+
assert_equal(0, count);
|
180
|
+
end
|
181
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stat-count-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- gavin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hessian2
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thrift-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
description: ruby client for stat count server
|
@@ -35,45 +46,58 @@ extensions: []
|
|
35
46
|
extra_rdoc_files: []
|
36
47
|
files:
|
37
48
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
49
|
- LICENSE
|
40
50
|
- Rakefile
|
41
51
|
- README.md
|
42
|
-
- stat-count-client.gemspec
|
43
52
|
- test/count_mother.rb
|
44
53
|
- test/stat_ccount_client_test.rb
|
54
|
+
- test/stat_count_client_test.rb
|
45
55
|
- test/test.rb
|
56
|
+
- test/thrift_count_client_test.rb
|
46
57
|
- lib/config_loader.rb
|
47
58
|
- lib/hessian_data_utils.rb
|
48
59
|
- lib/logger_factory.rb
|
60
|
+
- lib/stat-count-client/config_loader.rb
|
61
|
+
- lib/stat-count-client/hessian/stat_data_utils.rb
|
62
|
+
- lib/stat-count-client/hessian_client.rb
|
63
|
+
- lib/stat-count-client/logger_factory.rb
|
64
|
+
- lib/stat-count-client/stat_count_data.rb
|
65
|
+
- lib/stat-count-client/thrift/collecter_constants.rb
|
66
|
+
- lib/stat-count-client/thrift/collecter_types.rb
|
67
|
+
- lib/stat-count-client/thrift/remote_simple_count_collecter.rb
|
68
|
+
- lib/stat-count-client/thrift_client.rb
|
49
69
|
- lib/stat-count-client/version.rb
|
50
70
|
- lib/stat-count-client.rb
|
71
|
+
- doc/collecter.thrift
|
72
|
+
- doc/gen.txt
|
51
73
|
homepage: http://www.ximalaya.com
|
52
74
|
licenses: []
|
75
|
+
metadata: {}
|
53
76
|
post_install_message:
|
54
77
|
rdoc_options: []
|
55
78
|
require_paths:
|
56
79
|
- lib
|
57
80
|
- test
|
58
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
82
|
requirements:
|
61
|
-
- -
|
83
|
+
- - '>='
|
62
84
|
- !ruby/object:Gem::Version
|
63
85
|
version: '0'
|
64
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
87
|
requirements:
|
67
|
-
- -
|
88
|
+
- - '>='
|
68
89
|
- !ruby/object:Gem::Version
|
69
90
|
version: '0'
|
70
91
|
requirements: []
|
71
92
|
rubyforge_project:
|
72
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
73
94
|
signing_key:
|
74
|
-
specification_version:
|
95
|
+
specification_version: 4
|
75
96
|
summary: stat count client
|
76
97
|
test_files:
|
77
98
|
- test/count_mother.rb
|
78
99
|
- test/stat_ccount_client_test.rb
|
100
|
+
- test/stat_count_client_test.rb
|
79
101
|
- test/test.rb
|
102
|
+
- test/thrift_count_client_test.rb
|
103
|
+
has_rdoc:
|