コード例 #1
0
    def test_blockmap_cleaning(self):
        """ tests that a blockmap cleans up aborted operations correctly """
        # create an aborted blockmap
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 8)
        blockmap.init_blockmap()
        blockmap.change_block_range_status(1024 * 1024 * 0, 4,
                                           Blockmap.DOWNLOADED)
        blockmap.change_block_range_status(1024 * 1024 * 2, 4, '1')
        self._verify_blockmap(blockmap, '**1111..')

        # load the blockmap in again to check it is cleaned
        blockmap = create_blockmap(self._results_dir,
                                   1024 * 1024 * 8,
                                   delete_if_exists=False)
        blockmap.init_blockmap()
        self._verify_blockmap(blockmap, '**......')
コード例 #2
0
    def test_display_compact(self):
        """ test _display_compact function """
        # create a FtpFileDownloader for the test
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        # create a blockmap for the test
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()
        blockmap.change_block_range_status(1024 * 1024 * 15, 2,
                                           Blockmap.DOWNLOADED)
        blockmap.change_block_range_status(1024 * 1024 * 6, 2,
                                           Blockmap.PENDING)
        blockmap.change_block_range_status(1024 * 1024 * 1, 2, Blockmap.SAVING)

        # check the display_compact
        with captured_output() as (out, err):
            superftp._display_compact(ftp, blockmap, '\remote\test')
        s = err.getvalue()
        self.assertEqual(s, '')
        s = out.getvalue()
        truth = (
            '\rETA:infinite        3.2%  0.000MB/sec  \remote\test                              '
        )
        self.assertEqual(s, truth)
コード例 #3
0
    def test_pretty_dl_speed_fifo(self):
        """ test pretty summary line function """
        # create a FtpFileDownloader for the test
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        # create a blockmap for the test
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()

        # set a download speed below the kill speed and another equal to the kill speed, and one above the kill speed
        ftp._download_threads['0'].private_dl_speed_fifo[0] = 1024 * 1024 * 2
        ftp._download_threads['0'].private_dl_speed_fifo[1] = 1024 * 1024
        ftp._download_threads['0'].private_dl_speed_fifo[2] = 1024 * 512

        # check
        s = superftp._pretty_dl_speed_fifo(ftp, 1.0)
        truth = (
            '\x1b[37m[0.000][0.000][0.000][0.000]\x1b[K\n\x1b[91m[0.500]\x1b[37m[0.000][0.000][0.000]\x1b[K\n'
            +
            '\x1b[92m[1.000]\x1b[37m[0.000][0.000][0.000]\x1b[K\n\x1b[92m[2.000]\x1b[37m[0.000][0.000][0.000]'
            + '\x1b[K\n')
        self.assertEqual(s, truth)
コード例 #4
0
 def test_blockmap_string(self):
     """ tests that a blockmap string representation works """
     # create an aborted blockmap
     blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 8)
     blockmap.init_blockmap()
     blockmap.change_block_range_status(1024 * 1024 * 0, 4,
                                        Blockmap.DOWNLOADED)
     blockmap.change_block_range_status(1024 * 1024 * 2, 4, '1')
     self._verify_blockmap(blockmap, '**1111..')
コード例 #5
0
 def test_blockmap_bad_status(self):
     """ tests that blockmap raises exception if a directory is passed in as local dir """
     blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 8)
     blockmap.init_blockmap()
     try:
         blockmap.change_block_range_status(1024 * 1024 * 0, 4, 'Z')
     except BlockmapException as _:
         pass
     else:
         self.fail('Expected exception')
コード例 #6
0
    def test_blockmap_saving_complete(self):
        """ tests that blockmap is_blockmap_complete works """
        # create a new blockmap
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 8)
        blockmap.init_blockmap()

        # it is not complete
        self.assertFalse(blockmap.is_blockmap_complete())

        # it has available blocks
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertTrue(available_blocks > 0)

        # mark first 7 blocks pending
        blockmap.change_block_range_status(0, 7, '0')
        self.assertFalse(blockmap.is_blockmap_complete())
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertTrue(available_blocks > 0)
        self._verify_blockmap(blockmap, '0000000.')

        # mark last block pending
        blockmap.change_block_range_status(1024 * 1024 * 7, 1, '1')
        self.assertFalse(blockmap.is_blockmap_complete())
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertFalse(available_blocks > 0)
        self._verify_blockmap(blockmap, '00000001')

        # set pending to saving
        blockmap.change_block_range_status(1024 * 1024 * 7, 1, '_')
        self._verify_blockmap(blockmap, '0000000_')

        # save the 4th and 5th block
        blockmap.change_block_range_status(1024 * 1024 * 4, 2,
                                           Blockmap.DOWNLOADED)
        self.assertFalse(blockmap.is_blockmap_complete())
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertFalse(available_blocks > 0)
        self._verify_blockmap(blockmap, '0000**0_')

        # save the rest of the blocks
        blockmap.change_block_range_status(1024 * 1024 * 0, 4,
                                           Blockmap.DOWNLOADED)
        self.assertFalse(blockmap.is_blockmap_complete())
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertFalse(available_blocks > 0)
        self._verify_blockmap(blockmap, '******0_')
        blockmap.change_block_range_status(1024 * 1024 * 6, 2,
                                           Blockmap.DOWNLOADED)
        self.assertTrue(blockmap.is_blockmap_complete())
        _, available_blocks, _, _, _ = blockmap.get_statistics()
        self.assertFalse(available_blocks > 0)
        self._verify_blockmap(blockmap, '********')

        # delete the blockmap
        blockmap.delete_blockmap()
コード例 #7
0
    def test_blockmap_init_delete(self):
        """ test blockmaps are initialized correctly """
        # test for a multiple of blocksize, and a non-multiple of block size
        for x in [(1024 * 1024 * 8, '........'),
                  (1024 * 1024 * 8.1, '.........')]:
            blockmap = create_blockmap(self._results_dir, x[0])
            blockmap.init_blockmap()

            # check that the blockmap looks as we expect
            self._verify_blockmap(blockmap, x[1])

            # check that the blockmap exists (it should)
            self.assertTrue(blockmap.is_blockmap_already_exists())

            # delete the blockmap
            blockmap.delete_blockmap()
            self.assertFalse(blockmap.is_blockmap_already_exists())
コード例 #8
0
    def test_pretty_blockmap(self):
        """ test pretty blockmap function """
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()
        blockmap.change_block_range_status(1024 * 1024 * 5, 2,
                                           Blockmap.DOWNLOADED)
        blockmap.change_block_range_status(1024 * 1024 * 9, 2,
                                           Blockmap.PENDING)
        blockmap.change_block_range_status(1024 * 1024 * 12, 2,
                                           Blockmap.SAVING)

        s = superftp._pretty_blockmap(blockmap, 5, 20)
        # print s.encode('string_escape')

        truth = (
            '\x1b[37m.....\x1b[92m**\x1b[37m..\x1b[93m001__456789\x1b[K\r\nABCDEF23456789ABCDEF\x1b[K\r\n\x1b[37'
            + 'm....................\x1b[K\r\n..\x1b[K\r\n\x1b[K\r\n')
        self.assertEqual(s, truth)
コード例 #9
0
    def test_allocate(self):
        """ tests that blockmap allocation works as expected """
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 8)
        blockmap.init_blockmap()
        _, _, _, blocksize, _ = blockmap.get_statistics()

        # verify a simple segment
        blockmap.allocate_segments(['0'])
        self._verify_blockmap(blockmap, '000.....')
        blockmap.allocate_segments(['1'])
        self._verify_blockmap(blockmap, '000111..')
        blockmap.change_block_range_status(blocksize * 1, 3,
                                           blockmap.AVAILABLE)
        blockmap.allocate_segments(['2'])
        self._verify_blockmap(blockmap, '022211..')

        blockmap.change_block_range_status(0, 8, blockmap.AVAILABLE)
        blockmap.allocate_segments(['0', '1', '2'])
        self._verify_blockmap(blockmap, '00011122')
コード例 #10
0
    def test_pretty_summary_line(self):
        """ test pretty summary line function """
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()

        s = superftp._pretty_summary_line(ftp, blockmap, '\remote\test')
        self.assertEqual(
            s, 'ETA:infinite        0.0%  0.000MB/sec  \remote\test')
コード例 #11
0
    def test_display_full(self):
        """ test _display_compact function """
        # create a FtpFileDownloader for the test
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        # create a blockmap for the test
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()
        blockmap.change_block_range_status(1024 * 1024 * 2, 2,
                                           Blockmap.DOWNLOADED)
        blockmap.change_block_range_status(1024 * 1024 * 24, 2,
                                           Blockmap.PENDING)
        blockmap.change_block_range_status(1024 * 1024 * 30, 2,
                                           Blockmap.SAVING)

        # check the display_compact
        with captured_output() as (out, err):
            superftp._display_full(ftp, blockmap, '\remote\test', (24, 80))
        s = err.getvalue()
        self.assertEqual(s, '')
        s = out.getvalue()
        truth = (
            '\x1b[1;0H\x1b[37mETA:infinite        3.2%  0.000MB/sec  \remote\test\x1b[K\x1b[2;0H\x1b[K\x1b[3;0H'
            +
            '\x1b[37m[0.000][0.000][0.000][0.000]\x1b[K\n[0.000][0.000][0.000][0.000]\x1b[K\n[0.000][0.000]'
            +
            '[0.000][0.000]\x1b[K\n[0.000][0.000][0.000][0.000]\x1b[K\n\x1b[7;0H\x1b[K\x1b[8;0H\x1b[37m..\x1b'
            +
            '[92m**\x1b[37m....................\x1b[93m001234__789ABCDEF23456789ABCDEF\x1b[37m.......\x1b[K\r\n'
            +
            '\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r'
            + '\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[J')
        self.assertEqual(s, truth)