def test_messages(): s = stats.UtilizationStats(track_messages=True) s.transmitted(0, '', cmd='SomeCommand') s.transmitted(0, '', cmd='SomeCommand') assert s.stats['num_messages'] == 2 assert not set(s.stats['messages_types'].items()) - \ set([('SomeCommand', 2)])
def test_transmitted(): s = stats.UtilizationStats(track_bytes=True) data = {'a': 1, 'b': 'Hello'} s.transmitted(123, data) s.transmitted(234, data) assert s.stats['bytes_xmited'] == (123 + 234) assert s.stats['bytes_original'] == 2 * len(json.dumps(data).encode())
def test_track_nothing_empty(): s = stats.UtilizationStats() s.transmitted(123, 'Something') assert s.stats['num_messages'] assert not s.stats['bytes_xmited'] assert not s.stats['bytes_original'] assert not s.stats['messages_types'] assert not s.stats['unique_keys']
def start(pubsub_port, reqres_port, topic_string, **kwargs): print('Initializing zmq connection') ctx, sock_pub, sock_rep = initialize_zmq(pubsub_port, reqres_port) dc = cache.DiffCache.producer(key_name='key') print('Ctrl+C to exit') loop = aio.get_event_loop() loop.add_signal_handler(signal.SIGINT, cleanup) auctions = kwargs.get('auctions', 1) sleep_sec = kwargs.get('sleep', 1) count = kwargs.get('count', 3) fname = kwargs.get('fname', None) stat = stats.UtilizationStats(track_bytes=True, track_keys=True, track_messages=True, report_interval=100) try: loop.run_until_complete( aio.wait((process_retran_request(sock_pub, sock_rep, dc, stat), run(sock_pub, sock_rep, dc, topic_string, auctions, sleep_sec, count, stat)))) except aio.CancelledError: print('Closing zmq connection') sock_pub.close() sock_rep.close() ctx.term() finally: loop.close() if fname: with open(fname, 'wb') as p_file: pickle.dump(stat.stats_lst, p_file) print('Stats written to {}'.format(fname))
def start(host_addr, pubsub_port, reqres_port, topic_string, **kwargs): print('Connecting to server on {}'.format(host_addr)) fuzz = kwargs.get('fuzz', 0.0) fname = kwargs.get('fname', None) ctx, sock_sub, sock_req = initialize_zmq(host_addr, pubsub_port, reqres_port) my_unique_id = uuid.uuid4().hex subscribe(sock_sub, (topic_string, my_unique_id)) loop = aio.get_event_loop() loop.add_signal_handler(signal.SIGINT, cleanup) print('Ctrl+C to exit') stat = stats.UtilizationStats(track_bytes=True, track_keys=True, track_messages=True, report_interval=100) try: aio.get_event_loop().run_until_complete( run(sock_sub, sock_req, my_unique_id, fuzz, stat)) except aio.CancelledError: print('Closing zmq connection') sock_sub.close() sock_req.close() ctx.term() finally: loop.close() if fname: with open(fname, 'wb') as p_file: pickle.dump(stat.stats_lst, p_file) print('Stats written to {}'.format(fname))
def test_dummy_report(): s = stats.UtilizationStats(track_keys=True, report_interval=1) s.transmitted(0, '') assert isinstance(s.stats_lst, list)
def test_keys(): s = stats.UtilizationStats(track_keys=True) s.transmitted(0, '', '', 314159) s.transmitted(0, '', '', 314159) s.transmitted(0, '', '', 271828) assert len(s.stats['unique_keys']) == 2