155
150
'support_partial_insertion': True,
158
'cleanup':groupcompress.cleanup_pack_group,
159
'factory':groupcompress.make_pack_factory(True, False, 1),
162
'support_partial_insertion':False,
165
scenarios = len_one_scenarios + len_two_scenarios
166
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))
169
159
def get_diamond_vf(f, trailing_eol=True, left_only=False):
231
217
result = [prefix + suffix for suffix in suffix_list]
238
219
# we loop over each key because that spreads the inserts across prefixes,
239
220
# which is how commit operates.
240
221
for prefix in prefixes:
241
result.append(files.add_lines(prefix + get_key('origin'), (),
222
result.append(files.add_lines(prefix + ('origin',), (),
242
223
['origin' + last_char]))
243
224
for prefix in prefixes:
244
result.append(files.add_lines(prefix + get_key('base'),
225
result.append(files.add_lines(prefix + ('base',),
245
226
get_parents([('origin',)]), ['base' + last_char]))
246
227
for prefix in prefixes:
247
result.append(files.add_lines(prefix + get_key('left'),
228
result.append(files.add_lines(prefix + ('left',),
248
229
get_parents([('base',)]),
249
230
['base\n', 'left' + last_char]))
250
231
if not left_only:
251
232
for prefix in prefixes:
252
result.append(files.add_lines(prefix + get_key('right'),
233
result.append(files.add_lines(prefix + ('right',),
253
234
get_parents([('base',)]),
254
235
['base\n', 'right' + last_char]))
255
236
for prefix in prefixes:
256
result.append(files.add_lines(prefix + get_key('merged'),
237
result.append(files.add_lines(prefix + ('merged',),
257
238
get_parents([('left',), ('right',)]),
258
239
['base\n', 'left\n', 'right\n', 'merged' + last_char]))
769
751
self.assertEqual(expected, progress.updates)
771
753
lines = iter_with_versions(['child', 'otherchild'],
772
[('Walking content', 0, 2),
773
('Walking content', 1, 2),
774
('Walking content', 2, 2)])
754
[('Walking content.', 0, 2),
755
('Walking content.', 1, 2),
756
('Walking content.', 2, 2)])
775
757
# we must see child and otherchild
776
758
self.assertTrue(lines[('child\n', 'child')] > 0)
777
759
self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
778
760
# we dont care if we got more than that.
781
lines = iter_with_versions(None, [('Walking content', 0, 5),
782
('Walking content', 1, 5),
783
('Walking content', 2, 5),
784
('Walking content', 3, 5),
785
('Walking content', 4, 5),
786
('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)])
787
769
# all lines must be seen at least once
788
770
self.assertTrue(lines[('base\n', 'base')] > 0)
789
771
self.assertTrue(lines[('lancestor\n', 'lancestor')] > 0)
849
831
self.assertEquals(('references_ghost', 'line_c\n'), origins[2])
851
833
def test_readonly_mode(self):
852
t = transport.get_transport(self.get_url('.'))
834
transport = get_transport(self.get_url('.'))
853
835
factory = self.get_factory()
854
vf = factory('id', t, 0777, create=True, access_mode='w')
855
vf = factory('id', t, access_mode='r')
836
vf = factory('id', transport, 0777, create=True, access_mode='w')
837
vf = factory('id', transport, access_mode='r')
856
838
self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
857
839
self.assertRaises(errors.ReadOnlyError,
858
840
vf.add_lines_with_ghosts,
880
862
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
882
864
def get_file(self, name='foo'):
883
return WeaveFile(name, transport.get_transport(self.get_url('.')),
885
get_scope=self.get_transaction)
865
return WeaveFile(name, get_transport(self.get_url('.')), create=True,
866
get_scope=self.get_transaction)
887
868
def get_file_corrupted_text(self):
888
w = WeaveFile('foo', transport.get_transport(self.get_url('.')),
890
get_scope=self.get_transaction)
869
w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
870
get_scope=self.get_transaction)
891
871
w.add_lines('v1', [], ['hello\n'])
892
872
w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
923
903
def reopen_file(self, name='foo', create=False):
924
return WeaveFile(name, transport.get_transport(self.get_url('.')),
926
get_scope=self.get_transaction)
904
return WeaveFile(name, get_transport(self.get_url('.')), create=create,
905
get_scope=self.get_transaction)
928
907
def test_no_implicit_create(self):
929
908
self.assertRaises(errors.NoSuchFile,
932
transport.get_transport(self.get_url('.')),
911
get_transport(self.get_url('.')),
933
912
get_scope=self.get_transaction)
935
914
def get_factory(self):
1002
981
# we should be able to read from http with a versioned file.
1003
982
vf = self.get_file()
1004
983
# try an empty file access
1005
readonly_vf = self.get_factory()('foo', transport.get_transport(
1006
self.get_readonly_url('.')))
984
readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1007
985
self.assertEqual([], readonly_vf.versions())
1009
def test_readonly_http_works_with_feeling(self):
1010
# we should be able to read from http with a versioned file.
1011
vf = self.get_file()
1012
986
# now with feeling.
1013
987
vf.add_lines('1', [], ['a\n'])
1014
988
vf.add_lines('2', ['1'], ['b\n', 'a\n'])
1015
readonly_vf = self.get_factory()('foo', transport.get_transport(
1016
self.get_readonly_url('.')))
989
readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1017
990
self.assertEqual(['1', '2'], vf.versions())
1018
self.assertEqual(['1', '2'], readonly_vf.versions())
1019
991
for version in readonly_vf.versions():
1020
992
readonly_vf.get_lines(version)
1481
1447
transport.mkdir('.')
1482
1448
files = self.factory(transport)
1483
1449
if self.cleanup is not None:
1484
self.addCleanup(self.cleanup, files)
1450
self.addCleanup(lambda:self.cleanup(files))
1487
def get_simple_key(self, suffix):
1488
"""Return a key for the object under test."""
1489
if self.key_length == 1:
1492
return ('FileA',) + (suffix,)
1494
def test_add_lines(self):
1495
f = self.get_versionedfiles()
1496
key0 = self.get_simple_key('r0')
1497
key1 = self.get_simple_key('r1')
1498
key2 = self.get_simple_key('r2')
1499
keyf = self.get_simple_key('foo')
1500
f.add_lines(key0, [], ['a\n', 'b\n'])
1502
f.add_lines(key1, [key0], ['b\n', 'c\n'])
1504
f.add_lines(key1, [], ['b\n', 'c\n'])
1506
self.assertTrue(key0 in keys)
1507
self.assertTrue(key1 in keys)
1509
for record in f.get_record_stream([key0, key1], 'unordered', True):
1510
records.append((record.key, record.get_bytes_as('fulltext')))
1512
self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
1514
def test__add_text(self):
1515
f = self.get_versionedfiles()
1516
key0 = self.get_simple_key('r0')
1517
key1 = self.get_simple_key('r1')
1518
key2 = self.get_simple_key('r2')
1519
keyf = self.get_simple_key('foo')
1520
f._add_text(key0, [], 'a\nb\n')
1522
f._add_text(key1, [key0], 'b\nc\n')
1524
f._add_text(key1, [], 'b\nc\n')
1526
self.assertTrue(key0 in keys)
1527
self.assertTrue(key1 in keys)
1529
for record in f.get_record_stream([key0, key1], 'unordered', True):
1530
records.append((record.key, record.get_bytes_as('fulltext')))
1532
self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
1534
1453
def test_annotate(self):
1535
1454
files = self.get_versionedfiles()
1536
1455
self.get_diamond_files(files)
1570
1489
self.assertRaises(RevisionNotPresent,
1571
1490
files.annotate, prefix + ('missing-key',))
1573
def test_check_no_parameters(self):
1574
files = self.get_versionedfiles()
1576
def test_check_progressbar_parameter(self):
1577
"""A progress bar can be supplied because check can be a generator."""
1578
pb = ui.ui_factory.nested_progress_bar()
1579
self.addCleanup(pb.finished)
1580
files = self.get_versionedfiles()
1581
files.check(progress_bar=pb)
1583
def test_check_with_keys_becomes_generator(self):
1584
files = self.get_versionedfiles()
1585
self.get_diamond_files(files)
1587
entries = files.check(keys=keys)
1589
# Texts output should be fulltexts.
1590
self.capture_stream(files, entries, seen.add,
1591
files.get_parent_map(keys), require_fulltext=True)
1592
# All texts should be output.
1593
self.assertEqual(set(keys), seen)
1595
def test_clear_cache(self):
1596
files = self.get_versionedfiles()
1599
1492
def test_construct(self):
1600
1493
"""Each parameterised test can be constructed on a transport."""
1601
1494
files = self.get_versionedfiles()
1603
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):
1605
1497
return get_diamond_files(files, self.key_length,
1606
1498
trailing_eol=trailing_eol, nograph=not self.graph,
1607
left_only=left_only, nokeys=nokeys)
1609
def _add_content_nostoresha(self, add_lines):
1610
"""When nostore_sha is supplied using old content raises."""
1611
vf = self.get_versionedfiles()
1612
empty_text = ('a', [])
1613
sample_text_nl = ('b', ["foo\n", "bar\n"])
1614
sample_text_no_nl = ('c', ["foo\n", "bar"])
1616
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
1618
sha, _, _ = vf.add_lines(self.get_simple_key(version), [],
1621
sha, _, _ = vf._add_text(self.get_simple_key(version), [],
1624
# we now have a copy of all the lines in the vf.
1625
for sha, (version, lines) in zip(
1626
shas, (empty_text, sample_text_nl, sample_text_no_nl)):
1627
new_key = self.get_simple_key(version + "2")
1628
self.assertRaises(errors.ExistingContent,
1629
vf.add_lines, new_key, [], lines,
1631
self.assertRaises(errors.ExistingContent,
1632
vf._add_text, new_key, [], ''.join(lines),
1634
# and no new version should have been added.
1635
record = vf.get_record_stream([new_key], 'unordered', True).next()
1636
self.assertEqual('absent', record.storage_kind)
1638
def test_add_lines_nostoresha(self):
1639
self._add_content_nostoresha(add_lines=True)
1641
def test__add_text_nostoresha(self):
1642
self._add_content_nostoresha(add_lines=False)
1499
left_only=left_only)
1644
1501
def test_add_lines_return(self):
1645
1502
files = self.get_versionedfiles()
1672
1529
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1675
def test_add_lines_no_key_generates_chk_key(self):
1676
files = self.get_versionedfiles()
1677
# save code by using the stock data insertion helper.
1678
adds = self.get_diamond_files(files, nokeys=True)
1680
# We can only validate the first 2 elements returned from add_lines.
1682
self.assertEqual(3, len(add))
1683
results.append(add[:2])
1684
if self.key_length == 1:
1686
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1687
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1688
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1689
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1690
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1692
# Check the added items got CHK keys.
1693
self.assertEqual(set([
1694
('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
1695
('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
1696
('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
1697
('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
1698
('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
1701
elif self.key_length == 2:
1703
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1704
('00e364d235126be43292ab09cb4686cf703ddc17', 7),
1705
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1706
('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
1707
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1708
('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
1709
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1710
('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
1711
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23),
1712
('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1714
# Check the added items got CHK keys.
1715
self.assertEqual(set([
1716
('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1717
('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1718
('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1719
('FileA', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1720
('FileA', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1721
('FileB', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1722
('FileB', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1723
('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1724
('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1725
('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1729
1532
def test_empty_lines(self):
1730
1533
"""Empty files can be stored."""
1731
1534
f = self.get_versionedfiles()
1753
1556
f.get_record_stream([key_b], 'unordered', True
1754
1557
).next().get_bytes_as('fulltext'))
1756
def test_get_known_graph_ancestry(self):
1757
f = self.get_versionedfiles()
1759
raise TestNotApplicable('ancestry info only relevant with graph.')
1760
key_a = self.get_simple_key('a')
1761
key_b = self.get_simple_key('b')
1762
key_c = self.get_simple_key('c')
1768
f.add_lines(key_a, [], ['\n'])
1769
f.add_lines(key_b, [key_a], ['\n'])
1770
f.add_lines(key_c, [key_a, key_b], ['\n'])
1771
kg = f.get_known_graph_ancestry([key_c])
1772
self.assertIsInstance(kg, _mod_graph.KnownGraph)
1773
self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
1775
def test_known_graph_with_fallbacks(self):
1776
f = self.get_versionedfiles('files')
1778
raise TestNotApplicable('ancestry info only relevant with graph.')
1779
if getattr(f, 'add_fallback_versioned_files', None) is None:
1780
raise TestNotApplicable("%s doesn't support fallbacks"
1781
% (f.__class__.__name__,))
1782
key_a = self.get_simple_key('a')
1783
key_b = self.get_simple_key('b')
1784
key_c = self.get_simple_key('c')
1785
# A only in fallback
1790
g = self.get_versionedfiles('fallback')
1791
g.add_lines(key_a, [], ['\n'])
1792
f.add_fallback_versioned_files(g)
1793
f.add_lines(key_b, [key_a], ['\n'])
1794
f.add_lines(key_c, [key_a, key_b], ['\n'])
1795
kg = f.get_known_graph_ancestry([key_c])
1796
self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
1798
1559
def test_get_record_stream_empty(self):
1799
1560
"""An empty stream can be requested without error."""
1800
1561
f = self.get_versionedfiles()
1808
1569
'knit-ft', 'knit-delta', 'chunked', 'fulltext',
1809
1570
'knit-annotated-ft-gz', 'knit-annotated-delta-gz', 'knit-ft-gz',
1810
1571
'knit-delta-gz',
1811
'knit-delta-closure', 'knit-delta-closure-ref',
1812
'groupcompress-block', 'groupcompress-block-ref'])
1572
'knit-delta-closure', 'knit-delta-closure-ref'])
1814
def capture_stream(self, f, entries, on_seen, parents,
1815
require_fulltext=False):
1574
def capture_stream(self, f, entries, on_seen, parents):
1816
1575
"""Capture a stream for testing."""
1817
1576
for factory in entries:
1818
1577
on_seen(factory.key)
1819
1578
self.assertValidStorageKind(factory.storage_kind)
1820
if factory.sha1 is not None:
1821
self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1579
self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1823
1581
self.assertEqual(parents[factory.key], factory.parents)
1824
1582
self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1826
if require_fulltext:
1827
factory.get_bytes_as('fulltext')
1829
1585
def test_get_record_stream_interface(self):
1830
1586
"""each item in a stream has to provide a regular interface."""
1858
1621
return keys, sort_order
1860
def get_keys_and_groupcompress_sort_order(self):
1861
"""Get diamond test keys list, and their groupcompress sort ordering."""
1862
if self.key_length == 1:
1863
keys = [('merged',), ('left',), ('right',), ('base',)]
1864
sort_order = {('merged',):0, ('left',):1, ('right',):1, ('base',):2}
1867
('FileA', 'merged'), ('FileA', 'left'), ('FileA', 'right'),
1869
('FileB', 'merged'), ('FileB', 'left'), ('FileB', 'right'),
1873
('FileA', 'merged'):0, ('FileA', 'left'):1, ('FileA', 'right'):1,
1874
('FileA', 'base'):2,
1875
('FileB', 'merged'):3, ('FileB', 'left'):4, ('FileB', 'right'):4,
1876
('FileB', 'base'):5,
1878
return keys, sort_order
1880
1623
def test_get_record_stream_interface_ordered(self):
1881
1624
"""each item in a stream has to provide a regular interface."""
1882
1625
files = self.get_versionedfiles()
1911
1654
self.assertStreamOrder(sort_order, seen, keys)
1913
def test_get_record_stream_interface_groupcompress(self):
1914
"""each item in a stream has to provide a regular interface."""
1915
files = self.get_versionedfiles()
1916
self.get_diamond_files(files)
1917
keys, sort_order = self.get_keys_and_groupcompress_sort_order()
1918
parent_map = files.get_parent_map(keys)
1919
entries = files.get_record_stream(keys, 'groupcompress', False)
1921
self.capture_stream(files, entries, seen.append, parent_map)
1922
self.assertStreamOrder(sort_order, seen, keys)
1924
1656
def assertStreamOrder(self, sort_order, seen, keys):
1925
1657
self.assertEqual(len(set(seen)), len(keys))
1926
1658
if self.key_length == 1:
2208
def test_get_annotator(self):
2209
files = self.get_versionedfiles()
2210
self.get_diamond_files(files)
2211
origin_key = self.get_simple_key('origin')
2212
base_key = self.get_simple_key('base')
2213
left_key = self.get_simple_key('left')
2214
right_key = self.get_simple_key('right')
2215
merged_key = self.get_simple_key('merged')
2216
# annotator = files.get_annotator()
2217
# introduced full text
2218
origins, lines = files.get_annotator().annotate(origin_key)
2219
self.assertEqual([(origin_key,)], origins)
2220
self.assertEqual(['origin\n'], lines)
2222
origins, lines = files.get_annotator().annotate(base_key)
2223
self.assertEqual([(base_key,)], origins)
2225
origins, lines = files.get_annotator().annotate(merged_key)
2234
# Without a graph everything is new.
2241
self.assertRaises(RevisionNotPresent,
2242
files.get_annotator().annotate, self.get_simple_key('missing-key'))
2244
1938
def test_get_parent_map(self):
2245
1939
files = self.get_versionedfiles()
2246
1940
if self.key_length == 1:
2450
2144
self.assertIdenticalVersionedFile(source, files)
2452
def test_insert_record_stream_long_parent_chain_out_of_order(self):
2453
"""An out of order stream can either error or work."""
2455
raise TestNotApplicable('ancestry info only relevant with graph.')
2456
# Create a reasonably long chain of records based on each other, where
2457
# most will be deltas.
2458
source = self.get_versionedfiles('source')
2461
content = [('same same %d\n' % n) for n in range(500)]
2462
for letter in 'abcdefghijklmnopqrstuvwxyz':
2463
key = ('key-' + letter,)
2464
if self.key_length == 2:
2465
key = ('prefix',) + key
2466
content.append('content for ' + letter + '\n')
2467
source.add_lines(key, parents, content)
2470
# Create a stream of these records, excluding the first record that the
2471
# rest ultimately depend upon, and insert it into a new vf.
2473
for key in reversed(keys):
2474
streams.append(source.get_record_stream([key], 'unordered', False))
2475
deltas = chain(*streams[:-1])
2476
files = self.get_versionedfiles()
2478
files.insert_record_stream(deltas)
2479
except RevisionNotPresent:
2480
# Must not have corrupted the file.
2483
# Must only report either just the first key as a missing parent,
2484
# no key as missing (for nodelta scenarios).
2485
missing = set(files.get_missing_compression_parent_keys())
2486
missing.discard(keys[0])
2487
self.assertEqual(set(), missing)
2489
2146
def get_knit_delta_source(self):
2490
2147
"""Get a source that can produce a stream with knit delta records,
2491
2148
regardless of this test's scenario.
2600
2258
lines = iter_with_keys(
2601
2259
[self.get_simple_key('child'), self.get_simple_key('otherchild')],
2602
[('Walking content', 0, 2),
2603
('Walking content', 1, 2),
2604
('Walking content', 2, 2)])
2260
[('Walking content.', 0, 2),
2261
('Walking content.', 1, 2),
2262
('Walking content.', 2, 2)])
2605
2263
# we must see child and otherchild
2606
2264
self.assertTrue(lines[('child\n', self.get_simple_key('child'))] > 0)
2607
2265
self.assertTrue(
2611
2269
# test all lines
2612
2270
lines = iter_with_keys(files.keys(),
2613
[('Walking content', 0, 5),
2614
('Walking content', 1, 5),
2615
('Walking content', 2, 5),
2616
('Walking content', 3, 5),
2617
('Walking content', 4, 5),
2618
('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)])
2619
2277
# all lines must be seen at least once
2620
2278
self.assertTrue(lines[('base\n', self.get_simple_key('base'))] > 0)
2621
2279
self.assertTrue(