roma 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,10 @@ class MapCountPluginTest < Test::Unit::TestCase
15
15
  def setup
16
16
  start_roma
17
17
  @rc=Roma::Client::RomaClient.new(["localhost_11211","localhost_11212"], [Roma::Client::Plugin::MapCount])
18
+ @k = "key1"
19
+ @sk = "subkey1"
20
+ @lt = Time.parse(Time.now.strftime(DATE_FORMAT))
21
+ @ret = {"last_updated_date"=>@lt, @sk=>1}
18
22
  end
19
23
 
20
24
  def teardown
@@ -23,209 +27,258 @@ class MapCountPluginTest < Test::Unit::TestCase
23
27
 
24
28
  def test_mapcount_get(n = 5)
25
29
  n.times do |i|
26
- k = "subkey#{i}"
30
+ @sk = "subkey#{i}"
27
31
  expt = i
28
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
29
-
30
- retc = {"last_updated_date"=>lt}
32
+
33
+ retc = {"last_updated_date"=>@lt}
31
34
  (i+1).times do |j|
32
35
  retc["subkey#{j}"] = 1
33
36
  end
34
- assert_equal retc, @rc.mapcount_countup('key1', k, 0)
35
-
36
- retg = {"last_updated_date"=>lt}
37
+ assert_equal retc, @rc.mapcount_countup(@k, @sk, 0)
38
+
39
+ retg = {"last_updated_date"=>@lt}
37
40
  retg["subkey#{i}"] = 1
38
- assert_equal retg, @rc.mapcount_get('key1', k)
39
- assert_equal retc, @rc.mapcount_get('key1')
40
- end
41
+ assert_equal retg, @rc.mapcount_get(@k, @sk)
42
+ assert_equal retc, @rc.mapcount_get(@k)
43
+ end
41
44
 
42
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
43
- ret = {"last_updated_date"=>lt, "subkey0"=>1, "subkey1"=>1}
44
- assert_equal ret, @rc.mapcount_get('key1', 'subkey0,subkey1')
45
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
46
+ assert_equal ret2, @rc.mapcount_get(@k, 'subkey0,subkey1')
45
47
  end
46
48
 
47
- def test_mapcount_countup_expt
48
- k = "subkey1"
49
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
50
- ret = {"last_updated_date"=>lt, k=>1}
49
+ def test_mapcount_countup_array
50
+ assert_equal @ret, @rc.mapcount_countup(@k, [@sk])
51
+ end
52
+
53
+ def test_mapcount_countup_array_multi
54
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
55
+ assert_equal ret2, @rc.mapcount_countup(@k, ["subkey0", "subkey1"])
56
+
57
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>2}
58
+ @rc.mapcount_countup(@k, ["subkey1"])
59
+ assert_equal ret2, @rc.mapcount_get(@k)
60
+ end
61
+
62
+ def test_mapcount_countup_hash
63
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
64
+ assert_equal ret2, @rc.mapcount_countup(@k, ["subkey0", "subkey1"])
51
65
 
52
- assert_nil @rc.mapcount_get('key1', k)
53
- assert_equal ret, @rc.mapcount_countup('key1', k, 1)
54
- assert_equal ret, @rc.mapcount_get('key1', k)
66
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>4, "subkey1"=>1}
67
+ @rc.mapcount_countup(@k, {"subkey0" => 3})
68
+ assert_equal ret2, @rc.mapcount_get(@k)
69
+
70
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>4, "subkey1"=>11}
71
+ @rc.mapcount_countup(@k, {"subkey1" => 10})
72
+ assert_equal ret2, @rc.mapcount_get(@k)
73
+ end
74
+
75
+ def test_mapcount_countup_degits
76
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>125, "subkey1"=>30}
77
+ @rc.mapcount_countup(@k, {"subkey0" => 125, "subkey1" => 30})
78
+ assert_equal ret2, @rc.mapcount_get(@k)
79
+ end
80
+
81
+ def test_mapcount_countup_expt
82
+ assert_nil @rc.mapcount_get(@k, @sk)
83
+ assert_equal @ret, @rc.mapcount_countup(@k, @sk, 1)
84
+ assert_equal @ret, @rc.mapcount_get(@k, @sk)
55
85
  sleep 2
56
- assert_nil @rc.mapcount_get('key1', k)
86
+ assert_nil @rc.mapcount_get(@k, @sk)
57
87
  end
58
88
 
59
89
  def test_mapcount_update
60
- k = "subkey1"
61
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
62
- ret_time = {"last_updated_date"=>lt}
63
- ret_all = {"last_updated_date"=>lt, k=>1}
64
-
65
- assert_nil @rc.mapcount_update('key1')
66
- assert_equal ret_all, @rc.mapcount_countup('key1', k, 0)
67
- assert_equal ret_all, @rc.mapcount_update('key1')
68
- assert_equal ret_time, @rc.mapcount_update('key1', 'subkey2')
90
+ ret_time = {"last_updated_date"=>@lt}
69
91
 
70
- assert_equal ret_all, @rc.mapcount_update('key1', nil, 1)
92
+ assert_nil @rc.mapcount_update(@k)
93
+ assert_equal @ret, @rc.mapcount_countup(@k, @sk, 0)
94
+ assert_equal @ret, @rc.mapcount_update(@k)
95
+ assert_equal ret_time, @rc.mapcount_update(@k, 'subkey2')
96
+ assert_equal @ret, @rc.mapcount_update(@k, nil, 1)
71
97
  sleep 2
72
- assert_nil @rc.mapcount_get('key1')
98
+ assert_nil @rc.mapcount_get(@k)
99
+ end
73
100
 
74
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
75
- ret_all = {"last_updated_date"=>lt, k=>1}
76
- assert_equal ret_all, @rc.mapcount_countup('key1', k, 0)
77
- assert_equal ret_all, @rc.mapcount_update('key1', k, 1)
101
+ def test_mapcount_update_subkeys
102
+ ret = {"last_updated_date"=>@lt, @sk=>1}
103
+ assert_equal @ret, @rc.mapcount_countup(@k, @sk, 0)
104
+ assert_equal @ret, @rc.mapcount_update(@k, @sk, 1)
78
105
  sleep 2
79
- assert_nil @rc.mapcount_get('key1')
106
+ assert_nil @rc.mapcount_get(@k)
107
+ end
80
108
 
81
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
82
- ret_all = {"last_updated_date"=>lt, k=>1}
83
- assert_equal ret_all, @rc.mapcount_countup('key1', k, 0)
109
+ def test_mapcount_update_time
110
+ ret = {"last_updated_date"=>@lt, @sk=>1}
111
+ assert_equal @ret, @rc.mapcount_countup(@k, @sk, 0)
84
112
  sleep 2
85
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
86
- ret_all = {"last_updated_date"=>lt, k=>1}
87
- assert_equal ret_all, @rc.mapcount_update('key1')
113
+ lt2 = Time.parse(Time.now.strftime(DATE_FORMAT))
114
+ ret2 = {"last_updated_date"=>lt2, @sk=>1}
115
+ assert_equal ret2, @rc.mapcount_update(@k)
88
116
  end
89
117
 
90
118
  def test_counts
91
- conn = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
92
- if conn
93
- conn.write "stat read_count\n"
94
- r = conn.gets.split(" ")
95
- assert_equal 0, r[1].to_i
96
- conn.gets
119
+ conn1 = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
120
+ conn2 = Roma::Messaging::ConPool.instance.get_connection("localhost_11212")
97
121
 
98
- @rc.mapcount_get('key')
99
- sleep 10
100
- conn.write "stat read_count\n"
101
- r = conn.gets.split(" ")
102
- assert_equal 1, r[1].to_i
103
- conn.gets
122
+ if conn1 && conn2
123
+ conns = [conn1, conn2]
104
124
 
105
- conn.write "stat write_count\n"
106
- r = conn.gets.split(" ")
107
- assert_equal 0, r[1].to_i
108
- conn.gets
125
+ ret = get_stat_sum(conns, "stat read_count\n")
126
+ assert_equal 0, ret
127
+
128
+ ret = get_stat_sum(conns, "stat write_count\n")
129
+ assert_equal 0, ret
130
+
131
+ @rc.mapcount_get('key')
132
+ ret = get_stat_sum(conns, "stat read_count\n")
133
+ assert_equal 1, ret
109
134
 
110
135
  @rc.mapcount_countup('key', 'subkey', 0)
111
- sleep 10
112
- conn.write "stat write_count\n"
113
- r = conn.gets.split(" ")
114
- assert_equal 1, r[1].to_i
115
- conn.gets
136
+ ret = get_stat_sum(conns, "stat write_count\n")
137
+ assert_equal 1, ret
116
138
 
117
139
  @rc.mapcount_update('key')
118
- sleep 10
119
- conn.write "stat write_count\n"
120
- r = conn.gets.split(" ")
121
- assert_equal 2, r[1].to_i
122
- conn.gets
123
-
124
- conn.close
140
+ ret = get_stat_sum(conns, "stat write_count\n")
141
+ assert_equal 2, ret
142
+ else
143
+ flunk(message="Fail to get connection")
125
144
  end
145
+
146
+ conn1.close
147
+ conn2.close
126
148
  end
127
149
 
128
150
  def test_mapcount_get_ms(n = 5)
129
151
  n.times do |i|
130
- k = "subkey#{i}"
152
+ @sk = "subkey#{i}"
131
153
  expt = i
132
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
133
-
134
- retc = {"last_updated_date"=>lt}
154
+
155
+ retc = {"last_updated_date"=>@lt}
135
156
  (i+1).times do |j|
136
157
  retc["subkey#{j}"] = 1
137
158
  end
138
- assert_equal retc, @rc.mapcount_countup_ms('key1', k, 0)
139
-
140
- retg = {"last_updated_date"=>lt}
159
+ assert_equal retc, @rc.mapcount_countup_ms(@k, @sk, 0)
160
+
161
+ retg = {"last_updated_date"=>@lt}
141
162
  retg["subkey#{i}"] = 1
142
- assert_equal retg, @rc.mapcount_get_ms('key1', k)
143
- assert_equal retc, @rc.mapcount_get_ms('key1')
144
- end
163
+ assert_equal retg, @rc.mapcount_get_ms(@k, @sk)
164
+ assert_equal retc, @rc.mapcount_get_ms(@k)
165
+ end
145
166
 
146
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
147
- ret = {"last_updated_date"=>lt, "subkey0"=>1, "subkey1"=>1}
148
- assert_equal ret, @rc.mapcount_get_ms('key1', 'subkey0,subkey1')
167
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
168
+ assert_equal ret2, @rc.mapcount_get_ms(@k, 'subkey0,subkey1')
149
169
  end
150
170
 
151
- def test_mapcount_countup_ms_expt
152
- k = "subkey1"
153
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
154
- ret = {"last_updated_date"=>lt, k=>1}
171
+ def test_mapcount_countup_ms_array
172
+ assert_equal @ret, @rc.mapcount_countup_ms(@k, [@sk])
173
+ end
174
+
175
+ def test_mapcount_countup_ms_array_multi
176
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
177
+ assert_equal ret2, @rc.mapcount_countup_ms(@k, ["subkey0", "subkey1"])
178
+
179
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>2}
180
+ @rc.mapcount_countup_ms(@k, ["subkey1"])
181
+ assert_equal ret2, @rc.mapcount_get_ms(@k)
182
+ end
183
+
184
+ def test_mapcount_countup_ms_hash
185
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>1, "subkey1"=>1}
186
+ assert_equal ret2, @rc.mapcount_countup_ms(@k, ["subkey0", "subkey1"])
187
+
188
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>4, "subkey1"=>1}
189
+ @rc.mapcount_countup_ms(@k, {"subkey0" => 3})
190
+ assert_equal ret2, @rc.mapcount_get_ms(@k)
155
191
 
156
- assert_nil @rc.mapcount_get_ms('key1', k)
157
- assert_equal ret, @rc.mapcount_countup_ms('key1', k, 1)
158
- assert_equal ret, @rc.mapcount_get_ms('key1', k)
192
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>4, "subkey1"=>11}
193
+ @rc.mapcount_countup_ms(@k, {"subkey1" => 10})
194
+ assert_equal ret2, @rc.mapcount_get_ms(@k)
195
+ end
196
+
197
+ def test_mapcount_countup_ms_degits
198
+ ret2 = {"last_updated_date"=>@lt, "subkey0"=>125, "subkey1"=>30}
199
+ @rc.mapcount_countup_ms(@k, {"subkey0" => 125, "subkey1" => 30})
200
+ assert_equal ret2, @rc.mapcount_get_ms(@k)
201
+ end
202
+
203
+ def test_mapcount_countup_ms_expt
204
+ assert_nil @rc.mapcount_get_ms(@k, @sk)
205
+ assert_equal @ret, @rc.mapcount_countup_ms(@k, @sk, 1)
206
+ assert_equal @ret, @rc.mapcount_get_ms(@k, @sk)
159
207
  sleep 2
160
- assert_nil @rc.mapcount_get_ms('key1', k)
208
+ assert_nil @rc.mapcount_get_ms(@k, @sk)
161
209
  end
162
210
 
163
211
  def test_mapcount_update_ms
164
- k = "subkey1"
165
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
166
- ret_time = {"last_updated_date"=>lt}
167
- ret_all = {"last_updated_date"=>lt, k=>1}
212
+ ret_time = {"last_updated_date"=>@lt}
168
213
 
169
- assert_nil @rc.mapcount_update_ms('key1')
170
- assert_equal ret_all, @rc.mapcount_countup_ms('key1', k, 0)
171
- assert_equal ret_all, @rc.mapcount_update_ms('key1')
172
- assert_equal ret_time, @rc.mapcount_update_ms('key1', 'subkey2')
173
-
174
- assert_equal ret_all, @rc.mapcount_update_ms('key1', nil, 1)
214
+ assert_nil @rc.mapcount_update_ms(@k)
215
+ assert_equal @ret, @rc.mapcount_countup_ms(@k, @sk, 0)
216
+ assert_equal @ret, @rc.mapcount_update_ms(@k)
217
+ assert_equal ret_time, @rc.mapcount_update_ms(@k, 'subkey2')
218
+ assert_equal @ret, @rc.mapcount_update_ms(@k, nil, 1)
175
219
  sleep 2
176
- assert_nil @rc.mapcount_get_ms('key1')
220
+ assert_nil @rc.mapcount_get_ms(@k)
221
+ end
177
222
 
178
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
179
- ret_all = {"last_updated_date"=>lt, k=>1}
180
- assert_equal ret_all, @rc.mapcount_countup_ms('key1', k, 0)
181
- assert_equal ret_all, @rc.mapcount_update_ms('key1', k, 1)
223
+ def test_mapcount_update_ms_subkeys
224
+ ret = {"last_updated_date"=>@lt, @sk=>1}
225
+ assert_equal @ret, @rc.mapcount_countup_ms(@k, @sk, 0)
226
+ assert_equal @ret, @rc.mapcount_update_ms(@k, @sk, 1)
182
227
  sleep 2
183
- assert_nil @rc.mapcount_get_ms('key1')
228
+ assert_nil @rc.mapcount_get_ms(@k)
229
+ end
184
230
 
185
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
186
- ret_all = {"last_updated_date"=>lt, k=>1}
187
- assert_equal ret_all, @rc.mapcount_countup_ms('key1', k, 0)
231
+ def test_mapcount_update_ms_time
232
+ ret = {"last_updated_date"=>@lt, @sk=>1}
233
+ assert_equal @ret, @rc.mapcount_countup_ms(@k, @sk, 0)
188
234
  sleep 2
189
- lt = Time.parse(Time.now.gmtime.strftime(DATE_FORMAT))
190
- ret_all = {"last_updated_date"=>lt, k=>1}
191
- assert_equal ret_all, @rc.mapcount_update_ms('key1')
235
+ lt2 = Time.parse(Time.now.strftime(DATE_FORMAT))
236
+ ret2 = {"last_updated_date"=>lt2, @sk=>1}
237
+ assert_equal ret2, @rc.mapcount_update_ms(@k)
192
238
  end
193
239
 
194
240
  def test_counts_ms
195
- conn = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
196
- if conn
197
- conn.write "stat read_count\n"
198
- r = conn.gets.split(" ")
199
- assert_equal 0, r[1].to_i
200
- conn.gets
241
+ conn1 = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
242
+ conn2 = Roma::Messaging::ConPool.instance.get_connection("localhost_11212")
201
243
 
202
- @rc.mapcount_get_ms('key')
203
- sleep 10
204
- conn.write "stat read_count\n"
205
- r = conn.gets.split(" ")
206
- assert_equal 1, r[1].to_i
207
- conn.gets
244
+ if conn1 && conn2
245
+ conns = [conn1, conn2]
208
246
 
209
- conn.write "stat write_count\n"
210
- r = conn.gets.split(" ")
211
- assert_equal 0, r[1].to_i
212
- conn.gets
247
+ ret = get_stat_sum(conns, "stat read_count\n")
248
+ assert_equal 0, ret
249
+
250
+ ret = get_stat_sum(conns, "stat write_count\n")
251
+ assert_equal 0, ret
252
+
253
+ @rc.mapcount_get_ms('key')
254
+ ret = get_stat_sum(conns, "stat read_count\n")
255
+ assert_equal 1, ret
213
256
 
214
257
  @rc.mapcount_countup_ms('key', 'subkey', 0)
215
- sleep 10
216
- conn.write "stat write_count\n"
217
- r = conn.gets.split(" ")
218
- assert_equal 1, r[1].to_i
219
- conn.gets
258
+ ret = get_stat_sum(conns, "stat write_count\n")
259
+ assert_equal 1, ret
220
260
 
221
261
  @rc.mapcount_update_ms('key')
222
- sleep 10
223
- conn.write "stat write_count\n"
262
+ ret = get_stat_sum(conns, "stat write_count\n")
263
+ assert_equal 2, ret
264
+ else
265
+ flunk(message="Fail to get connection")
266
+ end
267
+
268
+ conn1.close
269
+ conn2.close
270
+ end
271
+
272
+ private
273
+ def get_stat_sum(conns, msg)
274
+ sum = 0
275
+ conns.each do |conn|
276
+ conn.write(msg)
224
277
  r = conn.gets.split(" ")
225
- assert_equal 2, r[1].to_i
278
+ sum += r[1].to_i
226
279
  conn.gets
227
-
228
- conn.close
229
280
  end
281
+ sum
230
282
  end
231
- end # MapCountPluginTest
283
+
284
+ end #MapCountPluginTest