示例#1
0
def test_emit_sql_execution_end_event():
    event_name = constants.SQL_EXECUTION_END_EVENT
    session_id = 17
    language = constants.SESSION_KIND_SPARK
    success = False
    exception_type = 'ValueError'
    exception_message = 'You screwed up'

    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.SESSION_GUID, guid1),
                   (constants.LIVY_KIND, language),
                   (constants.SESSION_ID, session_id),
                   (constants.SQL_GUID, guid2),
                   (constants.STATEMENT_GUID, guid3),
                   (constants.SUCCESS, success),
                   (constants.EXCEPTION_TYPE, exception_type),
                   (constants.EXCEPTION_MESSAGE, exception_message)]

    spark_events.emit_sql_execution_end_event(guid1, language, session_id, guid2, guid3,
                                              success, exception_type, exception_message)

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#2
0
def test_emit_sql_execution_start_event():
    event_name = constants.SQL_EXECUTION_START_EVENT
    session_id = 22
    language = constants.SESSION_KIND_SPARK
    samplemethod = 'sample'
    maxrows = 12
    samplefraction = 0.5

    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.SESSION_GUID, guid1),
                   (constants.LIVY_KIND, language),
                   (constants.SESSION_ID, session_id),
                   (constants.SQL_GUID, guid2),
                   (constants.SAMPLE_METHOD, samplemethod),
                   (constants.MAX_ROWS, maxrows),
                   (constants.SAMPLE_FRACTION, samplefraction)]

    spark_events.emit_sql_execution_start_event(guid1, language, session_id, guid2, samplemethod,
                                                maxrows, samplefraction)

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#3
0
def test_emit_library_loaded_event():
    event_name = constants.LIBRARY_LOADED_EVENT
    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp)]

    spark_events.emit_library_loaded_event()

    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
 def __init__(self, **kwargs):
     # Simply invokes the behavior of the superclass, but sets the filename keyword argument if it's not already set.
     if 'filename' in kwargs:
         super(MagicsFileHandler, self).__init__(**kwargs)
     else:
         magics_home_path = get_magics_home_path()
         logs_folder_name = "logs"
         log_file_name = "log_{}.log".format(get_instance_id())
         directory = FileSystemReaderWriter(join_paths(magics_home_path, logs_folder_name))
         directory.ensure_path_exists()
         super(MagicsFileHandler, self).__init__(filename=join_paths(directory.path, log_file_name), **kwargs)
示例#5
0
def test_emit_graph_render_event():
    event_name = constants.GRAPH_RENDER_EVENT
    graph_type = 'Bar'

    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.GRAPH_TYPE, graph_type)]

    spark_events.emit_graph_render_event(graph_type)

    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#6
0
def test_emit_session_creation_start_event():
    language = constants.SESSION_KIND_SPARK
    event_name = constants.SESSION_CREATION_START_EVENT
    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.SESSION_GUID, guid1),
                   (constants.LIVY_KIND, language)]

    spark_events.emit_session_creation_start_event(guid1, language)

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#7
0
 def __init__(self, **kwargs):
     # Simply invokes the behavior of the superclass, but sets the filename keyword argument if it's not already set.
     if 'filename' in kwargs:
         super(MagicsFileHandler, self).__init__(**kwargs)
     else:
         magics_home_path = get_magics_home_path()
         logs_folder_name = "logs"
         log_file_name = "log_{}.log".format(get_instance_id())
         directory = FileSystemReaderWriter(
             join_paths(magics_home_path, logs_folder_name))
         directory.ensure_path_exists()
         super(MagicsFileHandler,
               self).__init__(filename=join_paths(directory.path,
                                                  log_file_name),
                              **kwargs)
示例#8
0
def test_emit_magic_execution_start_event():
    event_name = constants.MAGIC_EXECUTION_START_EVENT
    magic_name = 'sql'
    language = constants.SESSION_KIND_SPARKR

    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.MAGIC_NAME, magic_name),
                   (constants.LIVY_KIND, language),
                   (constants.MAGIC_GUID, guid1)]

    spark_events.emit_magic_execution_start_event(magic_name, language, guid1)

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#9
0
def test_emit_session_creation_end_event():
    language = constants.SESSION_KIND_SPARK
    event_name = constants.SESSION_CREATION_END_EVENT
    status = constants.BUSY_SESSION_STATUS
    session_id = 0
    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.SESSION_GUID, guid1),
                   (constants.LIVY_KIND, language),
                   (constants.SESSION_ID, session_id),
                   (constants.STATUS, status),
                   (constants.SUCCESS, True),
                   (constants.EXCEPTION_TYPE, ""),
                   (constants.EXCEPTION_MESSAGE, "")]

    spark_events.emit_session_creation_end_event(guid1, language, session_id, status, True, "", "")

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#10
0
def test_emit_magic_execution_end_event():
    event_name = constants.MAGIC_EXECUTION_END_EVENT
    magic_name = 'sql'
    language = constants.SESSION_KIND_SPARKR
    success = True
    exception_type = ''
    exception_message = ''

    kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id()),
                   (constants.EVENT_NAME, event_name),
                   (constants.TIMESTAMP, time_stamp),
                   (constants.MAGIC_NAME, magic_name),
                   (constants.LIVY_KIND, language),
                   (constants.MAGIC_GUID, guid1),
                   (constants.SUCCESS, success),
                   (constants.EXCEPTION_TYPE, exception_type),
                   (constants.EXCEPTION_MESSAGE, exception_message)]

    spark_events.emit_magic_execution_end_event(magic_name, language, guid1, success,
                                                exception_type, exception_message)

    spark_events._verify_language_ok.assert_called_once_with(language)
    spark_events._get_utc_date_time.assert_called_with()
    spark_events.handler.handle_event.assert_called_once_with(kwargs_list)
示例#11
0
    def _send_to_handler(self, kwargs_list):
        kwargs_list = [(constants.INSTANCE_ID, utils.get_instance_id())] + kwargs_list

        assert len(kwargs_list) <= 12

        self.handler.handle_event(kwargs_list)