/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_versionedfile.py

  • Committer: Robert Collins
  • Date: 2009-02-20 10:48:51 UTC
  • mfrom: (4027 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4028.
  • Revision ID: robertc@robertcollins.net-20090220104851-m0s7qwe6jzqkgj1f
Merge bzr.dev (avoids criss-cross for PQM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
from bzrlib.tests import (
48
48
    TestCase,
49
49
    TestCaseWithMemoryTransport,
 
50
    TestNotApplicable,
50
51
    TestScenarioApplier,
51
52
    TestSkipped,
52
53
    condition_isinstance,
94
95
                ConstantMapper('inventory')),
95
96
            'graph':True,
96
97
            'key_length':1,
 
98
            'support_partial_insertion': False,
97
99
            }),
98
100
        ('named-knit', {
99
101
            'cleanup':None,
100
102
            'factory':make_file_factory(False, ConstantMapper('revisions')),
101
103
            'graph':True,
102
104
            'key_length':1,
 
105
            'support_partial_insertion': False,
103
106
            }),
104
 
        ('named-nograph-knit-pack', {
 
107
        ('named-nograph-nodelta-knit-pack', {
105
108
            'cleanup':cleanup_pack_knit,
106
109
            'factory':make_pack_factory(False, False, 1),
107
110
            'graph':False,
108
111
            'key_length':1,
 
112
            'support_partial_insertion': False,
109
113
            }),
110
114
        ('named-graph-knit-pack', {
111
115
            'cleanup':cleanup_pack_knit,
112
116
            'factory':make_pack_factory(True, True, 1),
113
117
            'graph':True,
114
118
            'key_length':1,
 
119
            'support_partial_insertion': True,
115
120
            }),
116
121
        ('named-graph-nodelta-knit-pack', {
117
122
            'cleanup':cleanup_pack_knit,
118
123
            'factory':make_pack_factory(True, False, 1),
119
124
            'graph':True,
120
125
            'key_length':1,
 
126
            'support_partial_insertion': False,
121
127
            }),
122
128
        ]
123
129
    len_two_adapter.scenarios = [
127
133
                PrefixMapper()),
128
134
            'graph':True,
129
135
            'key_length':2,
 
136
            'support_partial_insertion': False,
130
137
            }),
131
138
        ('annotated-knit-escape', {
132
139
            'cleanup':None,
133
140
            'factory':make_file_factory(True, HashEscapedPrefixMapper()),
134
141
            'graph':True,
135
142
            'key_length':2,
 
143
            'support_partial_insertion': False,
136
144
            }),
137
145
        ('plain-knit-pack', {
138
146
            'cleanup':cleanup_pack_knit,
139
147
            'factory':make_pack_factory(True, True, 2),
140
148
            'graph':True,
141
149
            'key_length':2,
 
150
            'support_partial_insertion': True,
142
151
            }),
143
152
        ]
144
153
    for test in iter_suite_tests(to_adapt):
2134
2143
        else:
2135
2144
            self.assertIdenticalVersionedFile(source, files)
2136
2145
 
 
2146
    def get_knit_delta_source(self):
 
2147
        """Get a source that can produce a stream with knit delta records,
 
2148
        regardless of this test's scenario.
 
2149
        """
 
2150
        mapper = self.get_mapper()
 
2151
        source_transport = self.get_transport('source')
 
2152
        source_transport.mkdir('.')
 
2153
        source = make_file_factory(False, mapper)(source_transport)
 
2154
        get_diamond_files(source, self.key_length, trailing_eol=True,
 
2155
            nograph=False, left_only=False)
 
2156
        return source
 
2157
 
2137
2158
    def test_insert_record_stream_delta_missing_basis_no_corruption(self):
2138
 
        """Insertion where a needed basis is not included aborts safely."""
2139
 
        # We use a knit always here to be sure we are getting a binary delta.
2140
 
        mapper = self.get_mapper()
2141
 
        source_transport = self.get_transport('source')
2142
 
        source_transport.mkdir('.')
2143
 
        source = make_file_factory(False, mapper)(source_transport)
2144
 
        self.get_diamond_files(source)
2145
 
        entries = source.get_record_stream(['origin', 'merged'], 'unordered', False)
2146
 
        files = self.get_versionedfiles()
2147
 
        self.assertRaises(RevisionNotPresent, files.insert_record_stream,
2148
 
            entries)
 
2159
        """Insertion where a needed basis is not included notifies the caller
 
2160
        of the missing basis.  In the meantime a record missing its basis is
 
2161
        not added.
 
2162
        """
 
2163
        source = self.get_knit_delta_source()
 
2164
        keys = [self.get_simple_key('origin'), self.get_simple_key('merged')]
 
2165
        entries = source.get_record_stream(keys, 'unordered', False)
 
2166
        files = self.get_versionedfiles()
 
2167
        if self.support_partial_insertion:
 
2168
            self.assertEqual([],
 
2169
                list(files.get_missing_compression_parent_keys()))
 
2170
            files.insert_record_stream(entries)
 
2171
            missing_bases = files.get_missing_compression_parent_keys()
 
2172
            self.assertEqual(set([self.get_simple_key('left')]),
 
2173
                set(missing_bases))
 
2174
            self.assertEqual(set(keys), set(files.get_parent_map(keys)))
 
2175
        else:
 
2176
            self.assertRaises(
 
2177
                errors.RevisionNotPresent, files.insert_record_stream, entries)
 
2178
            files.check()
 
2179
 
 
2180
    def test_insert_record_stream_delta_missing_basis_can_be_added_later(self):
 
2181
        """Insertion where a needed basis is not included notifies the caller
 
2182
        of the missing basis.  That basis can be added in a second
 
2183
        insert_record_stream call that does not need to repeat records present
 
2184
        in the previous stream.  The record(s) that required that basis are
 
2185
        fully inserted once their basis is no longer missing.
 
2186
        """
 
2187
        if not self.support_partial_insertion:
 
2188
            raise TestNotApplicable(
 
2189
                'versioned file scenario does not support partial insertion')
 
2190
        source = self.get_knit_delta_source()
 
2191
        entries = source.get_record_stream([self.get_simple_key('origin'),
 
2192
            self.get_simple_key('merged')], 'unordered', False)
 
2193
        files = self.get_versionedfiles()
 
2194
        files.insert_record_stream(entries)
 
2195
        missing_bases = files.get_missing_compression_parent_keys()
 
2196
        self.assertEqual(set([self.get_simple_key('left')]),
 
2197
            set(missing_bases))
 
2198
        # 'merged' is inserted (although a commit of a write group involving
 
2199
        # this versionedfiles would fail).
 
2200
        merged_key = self.get_simple_key('merged')
 
2201
        self.assertEqual(
 
2202
            [merged_key], files.get_parent_map([merged_key]).keys())
 
2203
        # Add the full delta closure of the missing records
 
2204
        missing_entries = source.get_record_stream(
 
2205
            missing_bases, 'unordered', True)
 
2206
        files.insert_record_stream(missing_entries)
 
2207
        # Now 'merged' is fully inserted (and a commit would succeed).
 
2208
        self.assertEqual([], list(files.get_missing_compression_parent_keys()))
 
2209
        self.assertEqual(
 
2210
            [merged_key], files.get_parent_map([merged_key]).keys())
2149
2211
        files.check()
2150
 
        self.assertEqual({}, files.get_parent_map([]))
2151
2212
 
2152
2213
    def test_iter_lines_added_or_present_in_keys(self):
2153
2214
        # test that we get at least an equalset of the lines added by