MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test06_multiple_streams

Method test06_multiple_streams

tests/flow/test_graph_info.py:268–322  ·  view source on GitHub ↗

test a more realistic example for how logged-queries streams will be processed

(self)

Source from the content-addressed store, hash-verified

266 self.env.assertEquals(self.conn.type(StreamName(new_graph)), "stream")
267
268 def test06_multiple_streams(self):
269 """test a more realistic example for how logged-queries streams
270 will be processed"""
271
272 # shared variable, single consumer thread to exit
273 alive = True
274
275 # streams consumer thread
276 def consume_streams(conn, queue):
277 # continuously poll for new messages
278 streams = {'telemetry{g}': '0-0', 'telemetry{x}': '0-0'}
279
280 # as long as we're alive
281 while alive:
282 # read messages from the stream
283 messages = conn.xread(streams, block=0)
284
285 # process each message received
286 for stream, stream_messages in messages:
287 for message_id, message_payload in stream_messages:
288 queue.put((stream, LoggedQuery(message_payload)))
289
290 if messages:
291 # update stream last ID
292 streams[stream] = stream_messages[-1][0]
293
294 # create two graphs: 'g' and 'x'
295 g = Graph(self.conn, "g")
296 x = Graph(self.conn, "x")
297
298 # create threads communication queue
299 q = queue.Queue()
300
301 # start streams consumer thread
302 t = threading.Thread(target=consume_streams, args=(self.conn, q))
303 t.start()
304
305 # issue queries multiple times against graphs 'g' and 'x'
306 for i in range (2):
307 # issue queries
308 g.query("RETURN 1")
309 x.query("RETURN 1")
310
311 # read logged queries
312 logged_query = q.get()
313 logged_query = q.get()
314
315 # signal consumer thread to stop
316 alive = False
317
318 # issue another query to unblock consumer thread
319 g.query("RETURN 1")
320
321 # wait for stream consumer thread to exit
322 t.join()
323
324 def test07_current_queries(self):
325 """test currently running queries"""

Callers

nothing calls this directly

Calls 3

GraphClass · 0.85
startMethod · 0.80
queryMethod · 0.45

Tested by

no test coverage detected