Beispiel #1
0
    def test_responding_to_file_request_message_for_huge_file(self):

        print(file_util.get_file_size('./huge_file.txt'))
        another_peer = Peer(22, "127.33.21.22", 3233, False)
        message = putils.create_file_request_message(
            self.business_layer.get_myself(),
            receiver=another_peer,
            path='./huge_file.txt')
        _run(self.lower[0].put(message))

        chunk1 = _run(self.lower[1].get())
        chunk2 = _run(self.lower[1].get())
        file_size = file_util.get_file_size('./huge_file.txt')
        binary_data1 = file_util.get_file_binary_data('./huge_file.txt', 8192)
        binary_data2 = file_util.get_file_binary_data('./huge_file.txt')[8192:]

        self.assertEqual(
            chunk1.fileChunk.fileName, './huge_file.txt' +
            '.{}'.format(self.business_layer.get_myself().id))
        self.assertEqual(chunk1.fileChunk.fileSize, file_size)
        self.assertEqual(chunk1.fileChunk.ordinal, 0)
        self.assertEqual(chunk1.fileChunk.data, binary_data1)
        self.assertEqual(
            chunk2.fileChunk.fileName, './huge_file.txt' +
            '.{}'.format(self.business_layer.get_myself().id))
        self.assertEqual(chunk2.fileChunk.fileSize, file_size)
        self.assertEqual(chunk2.fileChunk.ordinal, 1)
        self.assertEqual(chunk2.fileChunk.data, binary_data2)
        self.assertEqual(chunk1.fileChunk.uuid, chunk2.fileChunk.uuid)
Beispiel #2
0
 async def file_request(self, target_id, filepath):
     peer = await self.lower_layer.get_peer_by_id(target_id)
     if peer is None:
         return StatusMessage.FAILURE
     message = putils.create_file_request_message(sender=self.get_myself(), receiver=peer, path=filepath)
     try:
         status = await self._put_message_on_lower(message)
         return status
     except asyncio.CancelledError:
         return StatusMessage.FAILURE
Beispiel #3
0
    def test_responding_to_file_request_message(self):
        another_peer = Peer(22, "127.33.21.22", 3233, False)
        message = putils.create_file_request_message(
            self.business_layer.get_myself(),
            receiver=another_peer,
            path='./test_file.txt')
        _run(self.lower[0].put(message))

        response_message = _run(self.lower[1].get())
        file_size = file_util.get_file_size('./test_file.txt')
        binary_data = file_util.get_file_binary_data('./test_file.txt')

        self.assertEqual(
            response_message.fileChunk.fileName, './test_file.txt' +
            '.{}'.format(self.business_layer.get_myself().id))
        self.assertEqual(response_message.fileChunk.fileSize, file_size)
        self.assertEqual(response_message.fileChunk.ordinal, 0)
        self.assertEqual(response_message.fileChunk.data, binary_data)
Beispiel #4
0
    def test_handling_file_chunks_message(self):
        print(file_util.get_file_size('./huge_file.txt'))
        another_peer = Peer(22, "127.33.21.22", 3233, False)
        message = putils.create_file_request_message(
            self.business_layer.get_myself(),
            receiver=another_peer,
            path='./huge_file.txt')
        _run(self.lower[0].put(message))

        chunk1 = _run(self.lower[1].get())
        chunk2 = _run(self.lower[1].get())

        _run(self.lower[0].put(chunk1))
        _run(self.lower[0].put(chunk2))

        _run(asyncio.sleep(4))

        true_binary_data = file_util.get_file_binary_data('./huge_file.txt')
        binary_data = file_util.get_file_binary_data(
            path='./huge.file.txt.{}'.format(
                self.business_layer.get_myself().id))
        self.assertEqual(binary_data, true_binary_data)
Beispiel #5
0
    def test_creating_file_request_message(self):
        mess = putils.create_file_request_message(self.sender, self.receiver,
                                                  './test.txt')

        self.assertEqual(mess.type, mess.FILE_REQUEST)
        self.assertEqual(mess.fileRequest.path, './test.txt')