94
95
ConstantMapper('inventory')),
98
'support_partial_insertion': False,
100
102
'factory':make_file_factory(False, ConstantMapper('revisions')),
105
'support_partial_insertion': False,
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),
112
'support_partial_insertion': False,
110
114
('named-graph-knit-pack', {
111
115
'cleanup':cleanup_pack_knit,
112
116
'factory':make_pack_factory(True, True, 1),
119
'support_partial_insertion': True,
116
121
('named-graph-nodelta-knit-pack', {
117
122
'cleanup':cleanup_pack_knit,
118
123
'factory':make_pack_factory(True, False, 1),
126
'support_partial_insertion': False,
123
129
len_two_adapter.scenarios = [
2135
2144
self.assertIdenticalVersionedFile(source, files)
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.
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)
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,
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
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')]),
2174
self.assertEqual(set(keys), set(files.get_parent_map(keys)))
2177
errors.RevisionNotPresent, files.insert_record_stream, entries)
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.
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')]),
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')
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()))
2210
[merged_key], files.get_parent_map([merged_key]).keys())
2150
self.assertEqual({}, files.get_parent_map([]))
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