/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-20 01:26:08 UTC
  • mfrom: (4011.5.12 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090220012608-hh2rwz1cqd43mjrm
(robertc) Add the ability for KnitVersionedFiles backed by packs to
        scan a low level index for missing compression parent
        references. (Andrew Bennetts, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1237
1237
            else:
1238
1238
                raise
1239
1239
 
 
1240
    def test_scan_unvalidated_index_not_implemented(self):
 
1241
        transport = MockTransport()
 
1242
        index = self.get_knit_index(transport, 'filename', 'r')
 
1243
        self.assertRaises(
 
1244
            NotImplementedError, index.scan_unvalidated_index,
 
1245
            'dummy graph_index')
 
1246
        self.assertRaises(
 
1247
            NotImplementedError, index.get_missing_compression_parents)
 
1248
 
1240
1249
    def test_short_line(self):
1241
1250
        transport = MockTransport([
1242
1251
            _KndxIndex.HEADER,
1601
1610
             (('tip',), 'line-delta', (None, 0, 100), [('parent',)])])
1602
1611
        self.assertEqual([], self.caught_entries)
1603
1612
 
 
1613
    def make_g_index_missing_compression_parent(self):
 
1614
        graph_index = self.make_g_index('missing_comp', 2,
 
1615
            [(('tip', ), ' 100 78',
 
1616
              ([('missing-parent', ), ('ghost', )], [('missing-parent', )]))])
 
1617
        return graph_index
 
1618
    
 
1619
    def make_g_index_no_external_refs(self):
 
1620
        graph_index = self.make_g_index('no_external_refs', 2,
 
1621
            [(('rev', ), ' 100 78',
 
1622
              ([('parent', ), ('ghost', )], []))])
 
1623
        return graph_index
 
1624
 
 
1625
    def test_add_good_unvalidated_index(self):
 
1626
        unvalidated = self.make_g_index_no_external_refs()
 
1627
        combined = CombinedGraphIndex([unvalidated])
 
1628
        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
 
1629
        index.scan_unvalidated_index(unvalidated)
 
1630
        self.assertEqual(frozenset(), index.get_missing_compression_parents())
 
1631
 
 
1632
    def test_add_incomplete_unvalidated_index(self):
 
1633
        unvalidated = self.make_g_index_missing_compression_parent()
 
1634
        combined = CombinedGraphIndex([unvalidated])
 
1635
        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
 
1636
        index.scan_unvalidated_index(unvalidated)
 
1637
        # This also checks that its only the compression parent that is
 
1638
        # examined, otherwise 'ghost' would also be reported as a missing
 
1639
        # parent.
 
1640
        self.assertEqual(
 
1641
            frozenset([('missing-parent',)]),
 
1642
            index.get_missing_compression_parents())
 
1643
 
 
1644
    def test_add_unvalidated_index_with_present_external_references(self):
 
1645
        index = self.two_graph_index(deltas=True)
 
1646
        # Ugly hack to get at one of the underlying GraphIndex objects that
 
1647
        # two_graph_index built.
 
1648
        unvalidated = index._graph_index._indices[1]
 
1649
        # 'parent' is an external ref of _indices[1] (unvalidated), but is
 
1650
        # present in _indices[0].
 
1651
        index.scan_unvalidated_index(unvalidated)
 
1652
        self.assertEqual(frozenset(), index.get_missing_compression_parents())
 
1653
 
 
1654
    def make_new_missing_parent_g_index(self, name):
 
1655
        missing_parent = name + '-missing-parent'
 
1656
        graph_index = self.make_g_index(name, 2,
 
1657
            [((name + 'tip', ), ' 100 78',
 
1658
              ([(missing_parent, ), ('ghost', )], [(missing_parent, )]))])
 
1659
        return graph_index
 
1660
 
 
1661
    def test_add_mulitiple_unvalidated_indices_with_missing_parents(self):
 
1662
        g_index_1 = self.make_new_missing_parent_g_index('one')
 
1663
        g_index_2 = self.make_new_missing_parent_g_index('two')
 
1664
        combined = CombinedGraphIndex([g_index_1, g_index_2])
 
1665
        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
 
1666
        index.scan_unvalidated_index(g_index_1)
 
1667
        index.scan_unvalidated_index(g_index_2)
 
1668
        self.assertEqual(
 
1669
            frozenset([('one-missing-parent',), ('two-missing-parent',)]),
 
1670
            index.get_missing_compression_parents())
 
1671
 
 
1672
    def test_add_mulitiple_unvalidated_indices_with_mutual_dependencies(self):
 
1673
        graph_index_a = self.make_g_index('one', 2,
 
1674
            [(('parent-one', ), ' 100 78', ([('non-compression-parent',)], [])),
 
1675
             (('child-of-two', ), ' 100 78',
 
1676
              ([('parent-two',)], [('parent-two',)]))])
 
1677
        graph_index_b = self.make_g_index('two', 2,
 
1678
            [(('parent-two', ), ' 100 78', ([('non-compression-parent',)], [])),
 
1679
             (('child-of-one', ), ' 100 78',
 
1680
              ([('parent-one',)], [('parent-one',)]))])
 
1681
        combined = CombinedGraphIndex([graph_index_a, graph_index_b])
 
1682
        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
 
1683
        index.scan_unvalidated_index(graph_index_a)
 
1684
        index.scan_unvalidated_index(graph_index_b)
 
1685
        self.assertEqual(
 
1686
            frozenset([]), index.get_missing_compression_parents())
 
1687
        
1604
1688
 
1605
1689
class TestNoParentsGraphIndexKnit(KnitTests):
1606
1690
    """Tests for knits using _KnitGraphIndex with no parents."""
1614
1698
        size = trans.put_file(name, stream)
1615
1699
        return GraphIndex(trans, name, size)
1616
1700
 
 
1701
    def test_add_good_unvalidated_index(self):
 
1702
        unvalidated = self.make_g_index('unvalidated')
 
1703
        combined = CombinedGraphIndex([unvalidated])
 
1704
        index = _KnitGraphIndex(combined, lambda: True, parents=False)
 
1705
        index.scan_unvalidated_index(unvalidated)
 
1706
        self.assertEqual(frozenset(),
 
1707
            index.get_missing_compression_parents())
 
1708
 
1617
1709
    def test_parents_deltas_incompatible(self):
1618
1710
        index = CombinedGraphIndex([])
1619
1711
        self.assertRaises(errors.KnitError, _KnitGraphIndex, lambda:True,