예제 #1
0
def test_get_error_no_id():
    mock_cmd_ch = Mock()
    mock_cmd_ch.get_command.return_value = None
    cmd_id = "some_command_id"
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    assert under_test.get_message() == ""
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #2
0
def test_get_state_no_id():
    mock_cmd_ch = Mock()
    mock_cmd_ch.get_command.return_value = None
    cmd_id = "some_command_id"
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    assert under_test.get_state() == CommandState.UNKNOWN
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #3
0
def test_get_state_with_id():
    mock_cmd_ch = Mock()
    job_id = "some_job_id"
    cmd_id = "some_command_id"
    stand_in_status = CommandStatus(job_id, cmd_id)
    mock_cmd_ch.get_command.return_value = stand_in_status
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    assert under_test.get_state() == stand_in_status.state
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #4
0
def test_is_done():
    mock_cmd_ch = Mock()
    job_id = "some_job_id"
    cmd_id = "some_command_id"
    stand_in_status = CommandStatus(job_id, cmd_id)
    stand_in_status.state = CommandState.SUCCESS
    mock_cmd_ch.get_command.return_value = stand_in_status
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    assert under_test.is_done()
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #5
0
def test_is_not_done():
    mock_cmd_ch = Mock()
    job_id = "some_job_id"
    cmd_id = "some_command_id"
    stand_in_status = CommandStatus(job_id, cmd_id)
    stand_in_status.state = CommandState.ERROR
    mock_cmd_ch.get_command.return_value = stand_in_status
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    with pytest.raises(RuntimeError):
        under_test.is_done()
    assert mock_cmd_ch.get_command.call_count >= 1
예제 #6
0
def test_has_timed_out():
    mock_cmd_ch = Mock()
    job_id = "some_job_id"
    cmd_id = "some_command_id"
    stand_in_status = CommandStatus(job_id, cmd_id)
    stand_in_status.state = CommandState.TIMEOUT_RESPONSE
    mock_cmd_ch.get_command.return_value = stand_in_status
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    with pytest.raises(RuntimeError):
        under_test.is_done()
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #7
0
def test_get_error_with_id():
    mock_cmd_ch = Mock()
    job_id = "some_job_id"
    cmd_id = "some_command_id"
    message_string = "some message"
    stand_in_status = CommandStatus(job_id, cmd_id)
    stand_in_status.message = message_string
    mock_cmd_ch.get_command.return_value = stand_in_status
    under_test = CommandHandler(mock_cmd_ch, cmd_id)
    assert under_test.get_message() == message_string
    mock_cmd_ch.get_command.assert_called_once_with(cmd_id)
예제 #8
0
 def try_start_job(self, job: WriteJob) -> CommandHandler:
     """
     See base class for documentation.
     """
     self.command_channel.add_job_id(job.job_id)
     self.command_channel.add_command_id(job.job_id, job.job_id)
     self.command_channel.get_command(
         job.job_id).state = CommandState.WAITING_RESPONSE
     self._send_pool_message(job.get_start_message())
     return CommandHandler(self.command_channel, job.job_id)
예제 #9
0
 def try_send_stop_time(self, service_id: str, job_id: str,
                        stop_time: datetime) -> CommandHandler:
     """
     Sends a "set stop time" message to a file-writer running a job as identified by the parameters.
     This function is not blocking. No guarantees are given that this command will be followed.
     :param service_id: The service identifier of the file-writer to receive the command.
     :param job_id: The job identifier of the currently running file-writer job.
     :param stop_time: The new stop time.
     :return: A CommandHandler instance for (more) easily checking the outcome of setting a new stop time.
     """
     command_id = str(uuid.uuid1())
     message = serialise_stop(
         job_id=job_id,
         service_id=service_id,
         command_id=command_id,
         stop_time=stop_time,
     )
     self.command_channel.add_command_id(job_id=job_id,
                                         command_id=command_id)
     self.send_command(message)
     return CommandHandler(self.command_channel, command_id)