def __init__(self):
        self.module_name = 'look_ahead_handler_tester'
        self.log_type = 'INFO'
        self.log_message = 'initialize_look_ahead_handler: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler = LookAheadHandler()
        self.timetables_generator_process = None
        self.timetables_updater_process = None
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'initialize_look_ahead_handler: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)
Esempio n. 2
0
    def __init__(self):
        self.module_name = 'look_ahead_handler_tester'
        self.log_type = 'INFO'
        self.log_message = 'initialize_look_ahead_handler: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler = LookAheadHandler()
        self.timetables_generator_process = None
        self.timetables_updater_process = None
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'initialize_look_ahead_handler: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)
class LookAheadHandlerTester(object):
    def __init__(self):
        self.module_name = 'look_ahead_handler_tester'
        self.log_type = 'INFO'
        self.log_message = 'initialize_look_ahead_handler: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler = LookAheadHandler()
        self.timetables_generator_process = None
        self.timetables_updater_process = None
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'initialize_look_ahead_handler: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def start_timetables_generator_process(self):
        self.log_message = 'timetables_generator_process: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.timetables_generator_process = Process(
            target=self.test_timetables_generator_process, args=())
        self.timetables_generator_process.start()

    def start_timetables_updater_process(self):
        self.log_message = 'timetables_updater_process: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.timetables_updater_process = Process(
            target=self.test_timetables_updater_process, args=())
        self.timetables_updater_process.start()

    def terminate_timetables_generator_process(self):
        if self.timetables_generator_process is not None:
            self.timetables_generator_process.terminate()
            self.timetables_generator_process.join()
            self.timetables_generator_process = None
            self.log_message = 'timetables_generator_process: terminated'
        else:
            self.log_message = 'timetables_generator_process: None'

        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def terminate_timetables_updater_process(self):
        if self.timetables_updater_process is not None:
            self.timetables_updater_process.terminate()
            self.timetables_updater_process.join()
            self.timetables_updater_process = None
            self.log_message = 'timetables_updater_process: terminated'
        else:
            self.log_message = 'timetables_updater_process: None'

        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def test_generate_bus_line(self, bus_stop_names, bus_line_id=None):
        self.log_message = 'test_generate_bus_line: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_bus_line(
            bus_stop_names=bus_stop_names, bus_line_id=bus_line_id)
        elapsed_time = time.time() - self.start_time

        self.log_message = 'test_generate_bus_line: finished - elapsed_time = ' + str(
            elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def test_generate_timetables_for_bus_line(self,
                                              bus_line=None,
                                              bus_line_id=None):
        self.log_message = 'generate_timetables_for_bus_line: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_timetables_for_bus_line(
            timetables_starting_datetime=testing_timetables_starting_datetime,
            timetables_ending_datetime=testing_timetables_ending_datetime,
            requests_min_departure_datetime=
            testing_travel_requests_min_departure_datetime,
            requests_max_departure_datetime=
            testing_travel_requests_max_departure_datetime,
            bus_line=bus_line,
            bus_line_id=bus_line_id)
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'generate_timetables_for_bus_line: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def test_generate_timetables_for_bus_lines(self):
        self.log_message = 'generate_timetables_for_bus_lines: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_timetables_for_bus_lines(
            timetables_starting_datetime=testing_timetables_starting_datetime,
            timetables_ending_datetime=testing_timetables_ending_datetime,
            requests_min_departure_datetime=
            testing_travel_requests_min_departure_datetime,
            requests_max_departure_datetime=
            testing_travel_requests_max_departure_datetime,
        )
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'generate_timetables_for_bus_lines: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def test_timetables_generator_process(self):
        time_difference = 0
        initial_time = time.time()

        while time_difference < look_ahead_timetables_generator_max_operation_timeout:
            self.test_generate_timetables_for_bus_lines()
            time.sleep(look_ahead_timetables_generator_timeout)
            time_difference = time.time() - initial_time

    def test_timetables_updater_process(self):
        time_difference = 0
        initial_time = time.time()

        while time_difference < look_ahead_timetables_updater_max_operation_timeout:
            self.test_update_timetables_of_bus_lines()
            time.sleep(look_ahead_timetables_updater_timeout)
            time_difference = time.time() - initial_time

    def test_update_timetables_of_bus_line(self,
                                           bus_line=None,
                                           bus_line_id=None):
        self.log_message = 'test_update_timetables_of_bus_line: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.update_timetables_of_bus_line(
            bus_line=bus_line, bus_line_id=bus_line_id)
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'test_update_timetables_of_bus_line: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

    def test_update_timetables_of_bus_lines(self):
        self.log_message = 'test_update_timetables_of_bus_lines: starting'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.update_timetables_of_bus_lines()
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'test_update_timetables_of_bus_lines: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name,
            log_type=self.log_type,
            log_message=self.log_message)
Esempio n. 4
0
class LookAheadHandlerTester(object):
    def __init__(self):
        self.module_name = 'look_ahead_handler_tester'
        self.log_type = 'INFO'
        self.log_message = 'initialize_look_ahead_handler: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler = LookAheadHandler()
        self.timetables_generator_process = None
        self.timetables_updater_process = None
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'initialize_look_ahead_handler: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def start_timetables_generator_process(self):
        self.log_message = 'timetables_generator_process: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.timetables_generator_process = Process(target=self.test_timetables_generator_process, args=())
        self.timetables_generator_process.start()

    def start_timetables_updater_process(self):
        self.log_message = 'timetables_updater_process: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.timetables_updater_process = Process(target=self.test_timetables_updater_process, args=())
        self.timetables_updater_process.start()

    def terminate_timetables_generator_process(self):
        if self.timetables_generator_process is not None:
            self.timetables_generator_process.terminate()
            self.timetables_generator_process.join()
            self.timetables_generator_process = None
            self.log_message = 'timetables_generator_process: terminated'
        else:
            self.log_message = 'timetables_generator_process: None'

        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def terminate_timetables_updater_process(self):
        if self.timetables_updater_process is not None:
            self.timetables_updater_process.terminate()
            self.timetables_updater_process.join()
            self.timetables_updater_process = None
            self.log_message = 'timetables_updater_process: terminated'
        else:
            self.log_message = 'timetables_updater_process: None'

        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def test_generate_bus_line(self, line_id, bus_stop_names):
        self.log_message = 'test_generate_bus_line: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_bus_line(
            line_id=line_id,
            bus_stop_names=bus_stop_names
        )
        elapsed_time = time.time() - self.start_time

        self.log_message = 'test_generate_bus_line: finished - elapsed_time = ' + str(elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def test_generate_timetables_for_bus_line(self, bus_line=None, line_id=None):
        self.log_message = 'generate_timetables_for_bus_line: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_timetables_for_bus_line(
            timetables_starting_datetime=timetables_starting_datetime_testing_value,
            timetables_ending_datetime=timetables_ending_datetime_testing_value,
            requests_min_departure_datetime=travel_requests_min_departure_datetime_testing_value,
            requests_max_departure_datetime=travel_requests_max_departure_datetime_testing_value,
            bus_line=bus_line,
            line_id=line_id
        )
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'generate_timetables_for_bus_line: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def test_generate_timetables_for_bus_lines(self):
        self.log_message = 'generate_timetables_for_bus_lines: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.generate_timetables_for_bus_lines(
            timetables_starting_datetime=timetables_starting_datetime_testing_value,
            timetables_ending_datetime=timetables_ending_datetime_testing_value,
            requests_min_departure_datetime=travel_requests_min_departure_datetime_testing_value,
            requests_max_departure_datetime=travel_requests_max_departure_datetime_testing_value,
        )
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'generate_timetables_for_bus_lines: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def test_timetables_generator_process(self):
        time_difference = 0
        initial_time = time.time()

        while time_difference < look_ahead_timetables_generator_max_operation_timeout:
            self.test_generate_timetables_for_bus_lines()
            time.sleep(look_ahead_timetables_generator_timeout)
            time_difference = time.time() - initial_time

    def test_timetables_updater_process(self):
        time_difference = 0
        initial_time = time.time()

        while time_difference < look_ahead_timetables_updater_max_operation_timeout:
            self.test_update_timetables_of_bus_lines()
            time.sleep(look_ahead_timetables_updater_timeout)
            time_difference = time.time() - initial_time

    def test_update_timetables_of_bus_line(self, bus_line=None, line_id=None):
        self.log_message = 'test_update_timetables_of_bus_line: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.update_timetables_of_bus_line(bus_line=bus_line, line_id=line_id)
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'test_update_timetables_of_bus_line: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

    def test_update_timetables_of_bus_lines(self):
        self.log_message = 'test_update_timetables_of_bus_lines: starting'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)

        self.start_time = time.time()
        self.look_ahead_handler.update_timetables_of_bus_lines()
        self.elapsed_time = time.time() - self.start_time

        self.log_message = 'test_update_timetables_of_bus_lines: finished - elapsed_time = ' \
                           + str(self.elapsed_time) + ' sec'
        log(module_name=self.module_name, log_type=self.log_type, log_message=self.log_message)