class TestCommandTranscoder(TestCase):
    def setUp(self):
        self.base_command = BaseCommand()
        self.command_transcoder = CommandTranscoder()

    def test_encode_command(self):
        self.assertDictEqual(self.base_command.as_dict(), self.command_transcoder.encode_command(self.base_command))

    def test_decode_command(self):
        dictionary = self.base_command.__dict__
        self.assertEqual(self.base_command, self.command_transcoder.decode_command(dictionary))
Ejemplo n.º 2
0
 def _dequeue_command(self) -> BaseCommand:
     """
     Pops a command from the incoming message queue.
     :return: None
     """
     in_full.acquire()
     in_mutex.acquire()
     print(self._in_queue)
     command = CommandTranscoder.decode_command(
         self._in_queue.pop(0)
     )
     in_mutex.release()
     in_free.release()
     return command
Ejemplo n.º 3
0
 def _send_command(self, command):
     socket = JSONSocket(
         self._server_address,
         self._server_port
     )
     try:
         socket.send_dict(
             CommandTranscoder.encode_command(
                 command
             )
         )
     except Exception:
         return False
     return True
Ejemplo n.º 4
0
 def _enqueue_command(self, command: BaseCommand):
     """
     Puts a command that should be sent to the client into
     the outgoing message queue.
     :param command: The command to enqueue
     :return: None
     """
     out_free.acquire()
     out_mutex.acquire()
     self._out_queue.append(
         CommandTranscoder.encode_command(
             command
         )
     )
     out_mutex.release()
     out_full.release()
Ejemplo n.º 5
0
    def _receive_result(self):
        socket = JSONSocket(
            self._server_address,
            self._server_port + 1
        )
        try:
            dictionary = socket.receive_dict()
        except Exception as e:
            print(e)
            return None

        if "_type" in dictionary.keys():
            if dictionary["_type"] in CommandTranscoder.type_class_map.keys():
                response = CommandTranscoder.decode_command(dictionary)
                return response
        return dictionary
 def setUp(self):
     self.base_command = BaseCommand()
     self.command_transcoder = CommandTranscoder()