def test_run_socket_to_csv(unused_tcp_port, files, shutdown_system): config = { 'verbose': True, 'stream': False, 'output': { 'test_pusher': { 'type': 'csv', 'tags': 'socket', 'model': 'PowerReport', 'name': 'pusher', 'directory': OUTPUT_PATH } }, 'input': { 'test_puller': { 'type': 'socket', 'port': unused_tcp_port, 'model': 'HWPCReport' } }, } supervisor = Supervisor(config['verbose']) launch_simple_architecture(config, supervisor) client = ClientThread(extract_rapl_reports_with_2_sockets(10), unused_tcp_port) client.start() supervisor.monitor() check_output_file2()
def test_run_socket_with_delay_between_message_to_mongo( mongo_database, unused_tcp_port, shutdown_system): config = { 'verbose': True, 'stream': False, 'output': { 'test_pusher': { 'type': 'mongodb', 'model': 'PowerReport', 'uri': MONGO_URI, 'db': MONGO_DATABASE_NAME, 'collection': MONGO_OUTPUT_COLLECTION_NAME } }, 'input': { 'test_puller': { 'type': 'socket', 'port': unused_tcp_port, 'model': 'HWPCReport' } }, } supervisor = Supervisor(config['verbose']) launch_simple_architecture(config, supervisor) client = ClientThreadDelay(extract_rapl_reports_with_2_sockets(10), unused_tcp_port) client.start() supervisor.monitor() check_db_socket()
def test_create_hwpc_report_from_json_with_datetime_timestamp_format_create_a_HWPCReport( ): json_input = extract_rapl_reports_with_2_sockets(1)[0] json_input['timestamp'] = datetime.strptime(json_input['timestamp'], "%Y-%m-%dT%H:%M:%S.%f") report = HWPCReport.from_json(json_input) assert isinstance(report, HWPCReport)
async def test_read_one_json_object_received_from_the_socket( socket_db, unused_tcp_port): json_reports = extract_rapl_reports_with_2_sockets(1) client = ClientThread(json_reports, unused_tcp_port) client.start() iterator = socket_db.iter(False) report = await iterator.__anext__() assert_report_equals(report, json_reports[0])
def check_db_socket(): json_reports = extract_rapl_reports_with_2_sockets(10) mongo = pymongo.MongoClient(MONGO_URI) c_output = mongo[MONGO_DATABASE_NAME][MONGO_OUTPUT_COLLECTION_NAME] assert c_output.count_documents({}) == 20 for report in json_reports: ts = datetime.strptime(report['timestamp'], "%Y-%m-%dT%H:%M:%S.%f") assert c_output.count_documents({ 'timestamp': ts, 'sensor': report['sensor'], 'target': report['target'] }) == 2
def check_output_file2(): input_reports = extract_rapl_reports_with_2_sockets(10) output_file = open(OUTPUT_PATH + 'test_sensor-all/PowerReport.csv', 'r') # line count l_output = -1 for _ in output_file: l_output += 1 assert len(input_reports) * 2 == l_output output_file.seek(0) output_file.readline() # split socket0 report from socket1 report output_socket0 = [] output_socket1 = [] for output_line in map(lambda x: x.split(','), output_file): if output_line[4] == '\0\n': output_socket0.append(output_line) else: output_socket1.append(output_line) # check value for report, output_line_s0, output_line_s1 in zip(input_reports, output_socket0, output_socket1): ts = datetime.strptime(report['timestamp'], "%Y-%m-%dT%H:%M:%S.%f") assert ts == output_line_s0[0] assert ts == output_line_s1[0] assert report['sensor'] == output_line_s0[1] assert report['sensor'] == output_line_s1[1] assert report['target'] == output_line_s0[2] assert report['target'] == output_line_s1[2] int(output_line_s0[3]) == 42 int(output_line_s1[3]) == 42
def mongodb_content(): return extract_rapl_reports_with_2_sockets(10)
def test_create_hwpc_report_from_json_without_groups_field_raise_BadInputData( ): json_input = extract_rapl_reports_with_2_sockets(1)[0] del json_input['groups'] with pytest.raises(BadInputData): report = HWPCReport.from_json(json_input)
def test_create_hwpc_report_from_json_with_str_timestamp_with_bad_format_raise_BadInputData( ): json_input = extract_rapl_reports_with_2_sockets(1)[0] json_input['timestamp'] = '1970-09-01T090909.543' with pytest.raises(BadInputData): report = HWPCReport.from_json(json_input)
def test_create_hwpc_report_from_json_wit_str_timestamp_create_a_HWPCReport(): json_input = extract_rapl_reports_with_2_sockets(1)[0] report = HWPCReport.from_json(json_input) assert isinstance(report, HWPCReport)
def test_create_report_from_json_with_metadata(): json_input = extract_rapl_reports_with_2_sockets(1)[0] json_input["metadata"] = {} json_input["metadata"]["tag"] = 1 report = HWPCReport.from_json(json_input) assert report.metadata["tag"] == 1