Debian Codegraph @

tests/unittests/command_parse/test_stream.py

raw
1 def test_xrange(judge_command):
2 judge_command(
3 "XRANGE somestream - +",
4 {"command": "XRANGE", "key": "somestream", "stream_id": ["-", "+"]},
5 )
6 judge_command(
7 "XRANGE somestream 1526985054069 1526985055069",
8 {
9 "command": "XRANGE",
10 "key": "somestream",
11 "stream_id": ["1526985054069", "1526985055069"],
12 },
13 )
14 judge_command(
15 "XRANGE somestream 1526985054069 1526985055069-10",
16 {
17 "command": "XRANGE",
18 "key": "somestream",
19 "stream_id": ["1526985054069", "1526985055069-10"],
20 },
21 )
22 judge_command(
23 "XRANGE somestream 1526985054069 1526985055069-10 count 10",
24 {
25 "command": "XRANGE",
26 "key": "somestream",
27 "stream_id": ["1526985054069", "1526985055069-10"],
28 "count_const": "count",
29 "count": "10",
30 },
31 )
32
33
34 def test_xgroup_create(judge_command):
35 judge_command(
36 "XGROUP CREATE mykey mygroup 123",
37 {
38 "command": "XGROUP",
39 "stream_create": "CREATE",
40 "key": "mykey",
41 "group": "mygroup",
42 "stream_id": "123",
43 },
44 )
45 judge_command(
46 "XGROUP CREATE mykey mygroup $",
47 {
48 "command": "XGROUP",
49 "stream_create": "CREATE",
50 "key": "mykey",
51 "group": "mygroup",
52 "stream_id": "$",
53 },
54 )
55 # short of a parameter
56 judge_command("XGROUP CREATE mykey mygroup", None)
57 judge_command("XGROUP CREATE mykey", None)
58
59
60 def test_xgroup_setid(judge_command):
61 judge_command(
62 "XGROUP SETID mykey mygroup 123",
63 {
64 "command": "XGROUP",
65 "stream_setid": "SETID",
66 "key": "mykey",
67 "group": "mygroup",
68 "stream_id": "123",
69 },
70 )
71 judge_command(
72 "XGROUP SETID mykey mygroup $",
73 {
74 "command": "XGROUP",
75 "stream_setid": "SETID",
76 "key": "mykey",
77 "group": "mygroup",
78 "stream_id": "$",
79 },
80 )
81 # two subcommand together shouldn't match
82 judge_command("XGROUP CREATE mykey mygroup 123 SETID mykey mygroup $", None)
83
84
85 def test_xgroup_destroy(judge_command):
86 judge_command(
87 "XGROUP destroy mykey mygroup",
88 {
89 "command": "XGROUP",
90 "stream_destroy": "destroy",
91 "key": "mykey",
92 "group": "mygroup",
93 },
94 )
95 judge_command("XGROUP destroy mykey", None)
96 judge_command("XGROUP DESTROY mykey mygroup $", None)
97
98
99 def test_xgroup_delconsumer(judge_command):
100 judge_command(
101 "XGROUP delconsumer mykey mygroup myconsumer",
102 {
103 "command": "XGROUP",
104 "stream_delconsumer": "delconsumer",
105 "key": "mykey",
106 "group": "mygroup",
107 "consumer": "myconsumer",
108 },
109 )
110 judge_command(
111 "XGROUP delconsumer mykey mygroup $",
112 {
113 "command": "XGROUP",
114 "stream_delconsumer": "delconsumer",
115 "key": "mykey",
116 "group": "mygroup",
117 "consumer": "$",
118 },
119 )
120 judge_command("XGROUP delconsumer mykey mygroup", None)
121
122
123 def test_xgroup_stream(judge_command):
124 judge_command(
125 "XACK mystream group1 123123",
126 {
127 "command": "XACK",
128 "key": "mystream",
129 "group": "group1",
130 "stream_id": "123123",
131 },
132 )
133 judge_command(
134 "XACK mystream group1 123123 111",
135 {"command": "XACK", "key": "mystream", "group": "group1", "stream_id": "111"},
136 )
137
138
139 def test_xinfo(judge_command):
140 judge_command(
141 "XINFO consumers mystream mygroup",
142 {
143 "command": "XINFO",
144 "stream_consumers": "consumers",
145 "key": "mystream",
146 "group": "mygroup",
147 },
148 )
149 judge_command(
150 "XINFO GROUPS mystream",
151 {"command": "XINFO", "stream_groups": "GROUPS", "key": "mystream"},
152 )
153 judge_command(
154 "XINFO STREAM mystream",
155 {"command": "XINFO", "stream": "STREAM", "key": "mystream"},
156 )
157 judge_command("XINFO HELP", {"command": "XINFO", "help": "HELP"})
158 judge_command("XINFO consumers mystream mygroup GROUPS mystream", None)
159 judge_command("XINFO groups mystream mygroup", None)
160
161
162 def test_xinfo_with_full(judge_command):
163 judge_command(
164 "XINFO STREAM mystream FULL",
165 {
166 "command": "XINFO",
167 "stream": "STREAM",
168 "key": "mystream",
169 "full_const": "FULL",
170 },
171 )
172 judge_command(
173 "XINFO STREAM mystream FULL count 10",
174 {
175 "command": "XINFO",
176 "stream": "STREAM",
177 "key": "mystream",
178 "full_const": "FULL",
179 "count_const": "count",
180 "count": "10",
181 },
182 )
183
184
185 def test_xpending(judge_command):
186 judge_command(
187 "XPENDING mystream group55",
188 {"command": "XPENDING", "key": "mystream", "group": "group55"},
189 )
190 judge_command(
191 "XPENDING mystream group55 myconsumer",
192 {
193 "command": "XPENDING",
194 "key": "mystream",
195 "group": "group55",
196 "consumer": "myconsumer",
197 },
198 )
199 judge_command(
200 "XPENDING mystream group55 - + 10",
201 {
202 "command": "XPENDING",
203 "key": "mystream",
204 "group": "group55",
205 "stream_id": ["-", "+"],
206 "count": "10",
207 },
208 )
209 judge_command(
210 "XPENDING mystream group55 - + 10 myconsumer",
211 {
212 "command": "XPENDING",
213 "key": "mystream",
214 "group": "group55",
215 "stream_id": ["-", "+"],
216 "count": "10",
217 "consumer": "myconsumer",
218 },
219 )
220 judge_command("XPENDING mystream group55 - + ", None)
221
222
223 def test_xadd(judge_command):
224 judge_command(
225 "xadd mystream MAXLEN ~ 1000 * key value",
226 {
227 "command": "xadd",
228 "key": "mystream",
229 "maxlen": "MAXLEN",
230 "approximately": "~",
231 "count": "1000",
232 "sfield": "key",
233 "svalue": "value",
234 "stream_id": "*",
235 },
236 )
237 # test for MAXLEN option
238 judge_command(
239 "xadd mystream MAXLEN 1000 * key value",
240 {
241 "command": "xadd",
242 "key": "mystream",
243 "maxlen": "MAXLEN",
244 "count": "1000",
245 "sfield": "key",
246 "svalue": "value",
247 "stream_id": "*",
248 },
249 )
250 judge_command(
251 "xadd mystream * key value",
252 {
253 "command": "xadd",
254 "key": "mystream",
255 "sfield": "key",
256 "svalue": "value",
257 "stream_id": "*",
258 },
259 )
260 # spcify stream id
261 judge_command(
262 "xadd mystream 123-123 key value",
263 {
264 "command": "xadd",
265 "key": "mystream",
266 "sfield": "key",
267 "svalue": "value",
268 "stream_id": "123-123",
269 },
270 )
271 judge_command(
272 "xadd mystream 123-123 key value foo bar hello world",
273 {
274 "command": "xadd",
275 "key": "mystream",
276 "sfield": "hello",
277 "svalue": "world",
278 "stream_id": "123-123",
279 },
280 )
281
282
283 def test_xtrim(judge_command):
284 judge_command(
285 " XTRIM mystream MAXLEN 2",
286 {"command": "XTRIM", "key": "mystream", "maxlen": "MAXLEN", "count": "2"},
287 )
288 judge_command(
289 " XTRIM mystream MAXLEN ~ 2",
290 {
291 "command": "XTRIM",
292 "key": "mystream",
293 "maxlen": "MAXLEN",
294 "count": "2",
295 "approximately": "~",
296 },
297 )
298 judge_command(" XTRIM mystream", None)
299
300
301 def test_xdel(judge_command):
302 judge_command(
303 "XDEL mystream 1581165000000 1549611229000 1581060831000",
304 {"command": "XDEL", "key": "mystream", "stream_id": "1581060831000"},
305 )
306 judge_command(
307 "XDEL mystream 1581165000000",
308 {"command": "XDEL", "key": "mystream", "stream_id": "1581165000000"},
309 )
310
311
312 def test_xclaim(judge_command):
313 judge_command(
314 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0",
315 {
316 "command": "XCLAIM",
317 "key": "mystream",
318 "group": "mygroup",
319 "consumer": "Alice",
320 "millisecond": "3600000",
321 "stream_id": "1526569498055-0",
322 },
323 )
324 judge_command(
325 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 123 456 789",
326 {
327 "command": "XCLAIM",
328 "key": "mystream",
329 "group": "mygroup",
330 "consumer": "Alice",
331 "millisecond": "3600000",
332 "stream_id": "789",
333 },
334 )
335 judge_command(
336 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 IDLE 300",
337 {
338 "command": "XCLAIM",
339 "key": "mystream",
340 "group": "mygroup",
341 "consumer": "Alice",
342 "millisecond": ["3600000", "300"],
343 "stream_id": "1526569498055-0",
344 "idle": "IDLE",
345 },
346 )
347 judge_command(
348 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 retrycount 7",
349 {
350 "command": "XCLAIM",
351 "key": "mystream",
352 "group": "mygroup",
353 "consumer": "Alice",
354 "millisecond": "3600000",
355 "stream_id": "1526569498055-0",
356 "retrycount": "retrycount",
357 "count": "7",
358 },
359 )
360 judge_command(
361 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 TIME 123456789",
362 {
363 "command": "XCLAIM",
364 "key": "mystream",
365 "group": "mygroup",
366 "consumer": "Alice",
367 "millisecond": "3600000",
368 "stream_id": "1526569498055-0",
369 "time": "TIME",
370 "timestamp": "123456789",
371 },
372 )
373 judge_command(
374 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 FORCE",
375 {
376 "command": "XCLAIM",
377 "key": "mystream",
378 "group": "mygroup",
379 "consumer": "Alice",
380 "millisecond": "3600000",
381 "stream_id": "1526569498055-0",
382 "force": "FORCE",
383 },
384 )
385 judge_command(
386 "XCLAIM mystream mygroup Alice 3600000 1526569498055-0 JUSTID",
387 {
388 "command": "XCLAIM",
389 "key": "mystream",
390 "group": "mygroup",
391 "consumer": "Alice",
392 "millisecond": "3600000",
393 "stream_id": "1526569498055-0",
394 "justid": "JUSTID",
395 },
396 )
397
398
399 def test_xread(judge_command):
400 judge_command(
401 "XREAD COUNT 2 STREAMS mystream writers 0-0 0-0",
402 {
403 "command": "XREAD",
404 "count_const": "COUNT",
405 "count": "2",
406 "streams": "STREAMS",
407 # FIXME current grammar can't support multiple tokens
408 # so the ids will be recognized to keys.
409 "keys": "mystream writers 0-0",
410 "stream_id": "0-0",
411 },
412 )
413 judge_command(
414 "XREAD COUNT 2 BLOCK 1000 STREAMS mystream writers 0-0 0-0",
415 {
416 "command": "XREAD",
417 "count_const": "COUNT",
418 "count": "2",
419 "streams": "STREAMS",
420 "keys": "mystream writers 0-0",
421 "block": "BLOCK",
422 "millisecond": "1000",
423 "stream_id": "0-0",
424 },
425 )
426
427
428 def test_xreadgroup(judge_command):
429 judge_command(
430 "XREADGROUP GROUP mygroup1 Bob COUNT 1 BLOCK 100 NOACK STREAMS key1 1 key2 2",
431 {
432 "command": "XREADGROUP",
433 "stream_group": "GROUP",
434 "group": "mygroup1",
435 "consumer": "Bob",
436 "count_const": "COUNT",
437 "count": "1",
438 "block": "BLOCK",
439 "millisecond": "100",
440 "noack": "NOACK",
441 "streams": "STREAMS",
442 "keys": "key1 1 key2",
443 "stream_id": "2",
444 },
445 )
446 judge_command(
447 "XREADGROUP GROUP mygroup1 Bob STREAMS key1 1 key2 2",
448 {
449 "command": "XREADGROUP",
450 "stream_group": "GROUP",
451 "group": "mygroup1",
452 "consumer": "Bob",
453 "streams": "STREAMS",
454 "keys": "key1 1 key2",
455 "stream_id": "2",
456 },
457 )
458
459 judge_command("XREADGROUP GROUP group consumer", None)