~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
103
103
        self.overrideAttr(btree_index, '_PAGE_SIZE')
104
104
        btree_index._PAGE_SIZE = 2048
105
105
 
106
 
    def assertEqualsApproxCompressed(self, expected, actual, slop=6):
 
106
    def assertEqualApproxCompressed(self, expected, actual, slop=6):
107
107
        """Check a count of compressed bytes is approximately as expected
108
108
 
109
109
        Relying on compressed length being stable even with fixed inputs is
209
209
        temp_file = builder.finish()
210
210
        content = temp_file.read()
211
211
        del temp_file
212
 
        self.assertEqualsApproxCompressed(9283, len(content))
 
212
        self.assertEqualApproxCompressed(9283, len(content))
213
213
        self.assertEqual(
214
214
            "B+Tree Graph Index 2\nnode_ref_lists=0\nkey_elements=1\nlen=400\n"
215
215
            "row_lengths=1,2\n",
243
243
        temp_file = builder.finish()
244
244
        content = temp_file.read()
245
245
        del temp_file
246
 
        self.assertEqualsApproxCompressed(155, len(content))
 
246
        self.assertEqualApproxCompressed(155, len(content))
247
247
        self.assertEqual(
248
248
            "B+Tree Graph Index 2\nnode_ref_lists=0\nkey_elements=1\nlen=10\n"
249
249
            "row_lengths=1\n",
265
265
        temp_file = builder.finish()
266
266
        content = temp_file.read()
267
267
        del temp_file
268
 
        self.assertEqualsApproxCompressed(9283, len(content))
 
268
        self.assertEqualApproxCompressed(9283, len(content))
269
269
        self.assertEqual(
270
270
            "B+Tree Graph Index 2\nnode_ref_lists=0\nkey_elements=1\nlen=400\n"
271
271
            "row_lengths=1,2\n",
324
324
        temp_file = builder.finish()
325
325
        content = temp_file.read()
326
326
        del temp_file
327
 
        self.assertEqualsApproxCompressed(12643, len(content))
 
327
        self.assertEqualApproxCompressed(12643, len(content))
328
328
        self.assertEqual(
329
329
            "B+Tree Graph Index 2\nnode_ref_lists=2\nkey_elements=2\nlen=200\n"
330
330
            "row_lengths=1,3\n",
710
710
        # The entire index should have been read, as it is one page long.
711
711
        self.assertEqual([('readv', 'index', [(0, size)], False, None)],
712
712
            t._activity)
713
 
        self.assertEqualsApproxCompressed(1173, size)
 
713
        self.assertEqualApproxCompressed(1173, size)
714
714
 
715
715
    def test_with_offset_no_size(self):
716
716
        index = self.make_index_with_offset(key_elements=1, ref_lists=1,
760
760
            builder.add_node(*node)
761
761
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
762
762
        size = t.put_file('index', builder.finish())
763
 
        self.assertEqualsApproxCompressed(17692, size)
 
763
        self.assertEqualApproxCompressed(17692, size)
764
764
        index = btree_index.BTreeGraphIndex(t, 'index', size)
765
765
        del t._activity[:]
766
766
        self.assertEqual([], t._activity)
783
783
        # The entire index should have been read linearly.
784
784
        self.assertEqual([('readv', 'index', [(0, size)], False, None)],
785
785
                         t._activity)
786
 
        self.assertEqualsApproxCompressed(1488, size)
 
786
        self.assertEqualApproxCompressed(1488, size)
787
787
 
788
788
    def test_validate_two_pages(self):
789
789
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
793
793
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
794
794
        size = t.put_file('index', builder.finish())
795
795
        # Root page, 2 leaf pages
796
 
        self.assertEqualsApproxCompressed(9339, size)
 
796
        self.assertEqualApproxCompressed(9339, size)
797
797
        index = btree_index.BTreeGraphIndex(t, 'index', size)
798
798
        del t._activity[:]
799
799
        self.assertEqual([], t._activity)
892
892
        # The entire index should have been read
893
893
        total_pages = sum(index._row_lengths)
894
894
        self.assertEqual(total_pages, index._row_offsets[-1])
895
 
        self.assertEqualsApproxCompressed(1303220, size)
 
895
        self.assertEqualApproxCompressed(1303220, size)
896
896
        # The start of the leaves
897
897
        first_byte = index._row_offsets[-2] * page_size
898
898
        readv_request = []