153
150
'support_partial_insertion': True,
156
'cleanup':groupcompress.cleanup_pack_group,
157
'factory':groupcompress.make_pack_factory(True, False, 1),
160
'support_partial_insertion':False,
163
scenarios = len_one_scenarios + len_two_scenarios
164
return multiply_tests(to_adapt, scenarios, result)
153
for test in iter_suite_tests(to_adapt):
154
result.addTests(len_one_adapter.adapt(test))
155
result.addTests(len_two_adapter.adapt(test))
167
159
def get_diamond_vf(f, trailing_eol=True, left_only=False):
229
217
result = [prefix + suffix for suffix in suffix_list]
236
219
# we loop over each key because that spreads the inserts across prefixes,
237
220
# which is how commit operates.
238
221
for prefix in prefixes:
239
result.append(files.add_lines(prefix + get_key('origin'), (),
222
result.append(files.add_lines(prefix + ('origin',), (),
240
223
['origin' + last_char]))
241
224
for prefix in prefixes:
242
result.append(files.add_lines(prefix + get_key('base'),
225
result.append(files.add_lines(prefix + ('base',),
243
226
get_parents([('origin',)]), ['base' + last_char]))
244
227
for prefix in prefixes:
245
result.append(files.add_lines(prefix + get_key('left'),
228
result.append(files.add_lines(prefix + ('left',),
246
229
get_parents([('base',)]),
247
230
['base\n', 'left' + last_char]))
248
231
if not left_only:
249
232
for prefix in prefixes:
250
result.append(files.add_lines(prefix + get_key('right'),
233
result.append(files.add_lines(prefix + ('right',),
251
234
get_parents([('base',)]),
252
235
['base\n', 'right' + last_char]))
253
236
for prefix in prefixes:
254
result.append(files.add_lines(prefix + get_key('merged'),
237
result.append(files.add_lines(prefix + ('merged',),
255
238
get_parents([('left',), ('right',)]),
256
239
['base\n', 'left\n', 'right\n', 'merged' + last_char]))
768
751
self.assertEqual(expected, progress.updates)
770
753
lines = iter_with_versions(['child', 'otherchild'],
771
[('Walking content', 0, 2),
772
('Walking content', 1, 2),
773
('Walking content', 2, 2)])
754
[('Walking content.', 0, 2),
755
('Walking content.', 1, 2),
756
('Walking content.', 2, 2)])
774
757
# we must see child and otherchild
775
758
self.assertTrue(lines[('child\n', 'child')] > 0)
776
759
self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
777
760
# we dont care if we got more than that.
780
lines = iter_with_versions(None, [('Walking content', 0, 5),
781
('Walking content', 1, 5),
782
('Walking content', 2, 5),
783
('Walking content', 3, 5),
784
('Walking content', 4, 5),
785
('Walking content', 5, 5)])
763
lines = iter_with_versions(None, [('Walking content.', 0, 5),
764
('Walking content.', 1, 5),
765
('Walking content.', 2, 5),
766
('Walking content.', 3, 5),
767
('Walking content.', 4, 5),
768
('Walking content.', 5, 5)])
786
769
# all lines must be seen at least once
787
770
self.assertTrue(lines[('base\n', 'base')] > 0)
788
771
self.assertTrue(lines[('lancestor\n', 'lancestor')] > 0)
1510
1493
"""Each parameterised test can be constructed on a transport."""
1511
1494
files = self.get_versionedfiles()
1513
def get_diamond_files(self, files, trailing_eol=True, left_only=False,
1496
def get_diamond_files(self, files, trailing_eol=True, left_only=False):
1515
1497
return get_diamond_files(files, self.key_length,
1516
1498
trailing_eol=trailing_eol, nograph=not self.graph,
1517
left_only=left_only, nokeys=nokeys)
1519
def test_add_lines_nostoresha(self):
1520
"""When nostore_sha is supplied using old content raises."""
1521
vf = self.get_versionedfiles()
1522
empty_text = ('a', [])
1523
sample_text_nl = ('b', ["foo\n", "bar\n"])
1524
sample_text_no_nl = ('c', ["foo\n", "bar"])
1526
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
1527
sha, _, _ = vf.add_lines(self.get_simple_key(version), [], lines)
1529
# we now have a copy of all the lines in the vf.
1530
for sha, (version, lines) in zip(
1531
shas, (empty_text, sample_text_nl, sample_text_no_nl)):
1532
new_key = self.get_simple_key(version + "2")
1533
self.assertRaises(errors.ExistingContent,
1534
vf.add_lines, new_key, [], lines,
1536
# and no new version should have been added.
1537
record = vf.get_record_stream([new_key], 'unordered', True).next()
1538
self.assertEqual('absent', record.storage_kind)
1499
left_only=left_only)
1540
1501
def test_add_lines_return(self):
1541
1502
files = self.get_versionedfiles()
1568
1529
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1571
def test_add_lines_no_key_generates_chk_key(self):
1572
files = self.get_versionedfiles()
1573
# save code by using the stock data insertion helper.
1574
adds = self.get_diamond_files(files, nokeys=True)
1576
# We can only validate the first 2 elements returned from add_lines.
1578
self.assertEqual(3, len(add))
1579
results.append(add[:2])
1580
if self.key_length == 1:
1582
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1583
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1584
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1585
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1586
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1588
# Check the added items got CHK keys.
1589
self.assertEqual(set([
1590
('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
1591
('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
1592
('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
1593
('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
1594
('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
1597
elif self.key_length == 2:
1599
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1600
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1601
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1602
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1603
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1604
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1605
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1606
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1607
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23),
1608
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1610
# Check the added items got CHK keys.
1611
self.assertEqual(set([
1612
('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1613
('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1614
('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1615
('FileA', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1616
('FileA', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1617
('FileB', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1618
('FileB', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1619
('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1620
('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1621
('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1625
1532
def test_empty_lines(self):
1626
1533
"""Empty files can be stored."""
1627
1534
f = self.get_versionedfiles()
1662
1569
'knit-ft', 'knit-delta', 'chunked', 'fulltext',
1663
1570
'knit-annotated-ft-gz', 'knit-annotated-delta-gz', 'knit-ft-gz',
1664
1571
'knit-delta-gz',
1665
'knit-delta-closure', 'knit-delta-closure-ref',
1666
'groupcompress-block', 'groupcompress-block-ref'])
1572
'knit-delta-closure', 'knit-delta-closure-ref'])
1668
1574
def capture_stream(self, f, entries, on_seen, parents):
1669
1575
"""Capture a stream for testing."""
1670
1576
for factory in entries:
1671
1577
on_seen(factory.key)
1672
1578
self.assertValidStorageKind(factory.storage_kind)
1673
if factory.sha1 is not None:
1674
self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1579
self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1676
1581
self.assertEqual(parents[factory.key], factory.parents)
1677
1582
self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1716
1621
return keys, sort_order
1718
def get_keys_and_groupcompress_sort_order(self):
1719
"""Get diamond test keys list, and their groupcompress sort ordering."""
1720
if self.key_length == 1:
1721
keys = [('merged',), ('left',), ('right',), ('base',)]
1722
sort_order = {('merged',):0, ('left',):1, ('right',):1, ('base',):2}
1725
('FileA', 'merged'), ('FileA', 'left'), ('FileA', 'right'),
1727
('FileB', 'merged'), ('FileB', 'left'), ('FileB', 'right'),
1731
('FileA', 'merged'):0, ('FileA', 'left'):1, ('FileA', 'right'):1,
1732
('FileA', 'base'):2,
1733
('FileB', 'merged'):3, ('FileB', 'left'):4, ('FileB', 'right'):4,
1734
('FileB', 'base'):5,
1736
return keys, sort_order
1738
1623
def test_get_record_stream_interface_ordered(self):
1739
1624
"""each item in a stream has to provide a regular interface."""
1740
1625
files = self.get_versionedfiles()
1769
1654
self.assertStreamOrder(sort_order, seen, keys)
1771
def test_get_record_stream_interface_groupcompress(self):
1772
"""each item in a stream has to provide a regular interface."""
1773
files = self.get_versionedfiles()
1774
self.get_diamond_files(files)
1775
keys, sort_order = self.get_keys_and_groupcompress_sort_order()
1776
parent_map = files.get_parent_map(keys)
1777
entries = files.get_record_stream(keys, 'groupcompress', False)
1779
self.capture_stream(files, entries, seen.append, parent_map)
1780
self.assertStreamOrder(sort_order, seen, keys)
1782
1656
def assertStreamOrder(self, sort_order, seen, keys):
1783
1657
self.assertEqual(len(set(seen)), len(keys))
1784
1658
if self.key_length == 1:
2386
2258
lines = iter_with_keys(
2387
2259
[self.get_simple_key('child'), self.get_simple_key('otherchild')],
2388
[('Walking content', 0, 2),
2389
('Walking content', 1, 2),
2390
('Walking content', 2, 2)])
2260
[('Walking content.', 0, 2),
2261
('Walking content.', 1, 2),
2262
('Walking content.', 2, 2)])
2391
2263
# we must see child and otherchild
2392
2264
self.assertTrue(lines[('child\n', self.get_simple_key('child'))] > 0)
2393
2265
self.assertTrue(
2397
2269
# test all lines
2398
2270
lines = iter_with_keys(files.keys(),
2399
[('Walking content', 0, 5),
2400
('Walking content', 1, 5),
2401
('Walking content', 2, 5),
2402
('Walking content', 3, 5),
2403
('Walking content', 4, 5),
2404
('Walking content', 5, 5)])
2271
[('Walking content.', 0, 5),
2272
('Walking content.', 1, 5),
2273
('Walking content.', 2, 5),
2274
('Walking content.', 3, 5),
2275
('Walking content.', 4, 5),
2276
('Walking content.', 5, 5)])
2405
2277
# all lines must be seen at least once
2406
2278
self.assertTrue(lines[('base\n', self.get_simple_key('base'))] > 0)
2407
2279
self.assertTrue(