56
58
from bzrlib.tests.http_utils import TestCaseWithWebserver
57
59
from bzrlib.trace import mutter
58
from bzrlib.transport import get_transport
59
60
from bzrlib.transport.memory import MemoryTransport
60
61
from bzrlib.tsort import topo_sort
61
62
from bzrlib.tuned_gzip import GzipFile
733
734
# the ordering here is to make a tree so that dumb searches have
734
735
# more changes to muck up.
736
class InstrumentedProgress(progress.DummyProgress):
737
class InstrumentedProgress(progress.ProgressTask):
738
739
def __init__(self):
740
progress.DummyProgress.__init__(self)
740
progress.ProgressTask.__init__(self)
741
741
self.updates = []
743
743
def update(self, msg=None, current=None, total=None):
849
849
self.assertEquals(('references_ghost', 'line_c\n'), origins[2])
851
851
def test_readonly_mode(self):
852
transport = get_transport(self.get_url('.'))
852
t = transport.get_transport(self.get_url('.'))
853
853
factory = self.get_factory()
854
vf = factory('id', transport, 0777, create=True, access_mode='w')
855
vf = factory('id', transport, access_mode='r')
854
vf = factory('id', t, 0777, create=True, access_mode='w')
855
vf = factory('id', t, access_mode='r')
856
856
self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
857
857
self.assertRaises(errors.ReadOnlyError,
858
858
vf.add_lines_with_ghosts,
880
880
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
882
882
def get_file(self, name='foo'):
883
return WeaveFile(name, get_transport(self.get_url('.')), create=True,
884
get_scope=self.get_transaction)
883
return WeaveFile(name, transport.get_transport(self.get_url('.')),
885
get_scope=self.get_transaction)
886
887
def get_file_corrupted_text(self):
887
w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
888
get_scope=self.get_transaction)
888
w = WeaveFile('foo', transport.get_transport(self.get_url('.')),
890
get_scope=self.get_transaction)
889
891
w.add_lines('v1', [], ['hello\n'])
890
892
w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
921
923
def reopen_file(self, name='foo', create=False):
922
return WeaveFile(name, get_transport(self.get_url('.')), create=create,
923
get_scope=self.get_transaction)
924
return WeaveFile(name, transport.get_transport(self.get_url('.')),
926
get_scope=self.get_transaction)
925
928
def test_no_implicit_create(self):
926
929
self.assertRaises(errors.NoSuchFile,
929
get_transport(self.get_url('.')),
932
transport.get_transport(self.get_url('.')),
930
933
get_scope=self.get_transaction)
932
935
def get_factory(self):
999
1002
# we should be able to read from http with a versioned file.
1000
1003
vf = self.get_file()
1001
1004
# try an empty file access
1002
readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1005
readonly_vf = self.get_factory()('foo', transport.get_transport(
1006
self.get_readonly_url('.')))
1003
1007
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()
1004
1012
# now with feeling.
1005
1013
vf.add_lines('1', [], ['a\n'])
1006
1014
vf.add_lines('2', ['1'], ['b\n', 'a\n'])
1007
readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1015
readonly_vf = self.get_factory()('foo', transport.get_transport(
1016
self.get_readonly_url('.')))
1008
1017
self.assertEqual(['1', '2'], vf.versions())
1018
self.assertEqual(['1', '2'], readonly_vf.versions())
1009
1019
for version in readonly_vf.versions():
1010
1020
readonly_vf.get_lines(version)
1013
1023
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1015
1025
def get_file(self):
1016
return WeaveFile('foo', get_transport(self.get_url('.')), create=True,
1017
get_scope=self.get_transaction)
1026
return WeaveFile('foo', transport.get_transport(self.get_url('.')),
1028
get_scope=self.get_transaction)
1019
1030
def get_factory(self):
1020
1031
return WeaveFile
1264
1275
class TestWeaveMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1266
1277
def get_file(self, name='foo'):
1267
return WeaveFile(name, get_transport(self.get_url('.')), create=True)
1278
return WeaveFile(name, transport.get_transport(self.get_url('.')),
1269
1281
def log_contents(self, w):
1270
1282
self.log('weave is:')
1469
1481
transport.mkdir('.')
1470
1482
files = self.factory(transport)
1471
1483
if self.cleanup is not None:
1472
self.addCleanup(lambda:self.cleanup(files))
1484
self.addCleanup(self.cleanup, files)
1475
1487
def get_simple_key(self, suffix):
1580
1592
# All texts should be output.
1581
1593
self.assertEqual(set(keys), seen)
1595
def test_clear_cache(self):
1596
files = self.get_versionedfiles()
1583
1599
def test_construct(self):
1584
1600
"""Each parameterised test can be constructed on a transport."""
1585
1601
files = self.get_versionedfiles()
1737
1753
f.get_record_stream([key_b], 'unordered', True
1738
1754
).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()))
1740
1798
def test_get_record_stream_empty(self):
1741
1799
"""An empty stream can be requested without error."""
1742
1800
f = self.get_versionedfiles()
2392
2450
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)
2394
2489
def get_knit_delta_source(self):
2395
2490
"""Get a source that can produce a stream with knit delta records,
2396
2491
regardless of this test's scenario.
2464
2559
# the ordering here is to make a tree so that dumb searches have
2465
2560
# more changes to muck up.
2467
class InstrumentedProgress(progress.DummyProgress):
2562
class InstrumentedProgress(progress.ProgressTask):
2469
2564
def __init__(self):
2471
progress.DummyProgress.__init__(self)
2565
progress.ProgressTask.__init__(self)
2472
2566
self.updates = []
2474
2568
def update(self, msg=None, current=None, total=None):