1786
1786
# No duplicates on the wire thank you!
1787
1787
self.assertEqual(2, len(records) + skipped_records[0])
1788
1788
if len(records):
1789
# if any content was copied it all must have been.
1790
target_files.get_record_stream([key], 'unordered', True).next().get_bytes_as('fulltext')
1789
# if any content was copied it all must have all been.
1790
self.assertIdenticalVersionedFile(files, target_files)
1792
def test_get_record_stream_native_formats_are_wire_ready_delta(self):
1793
# copy a delta over the wire
1794
files = self.get_versionedfiles()
1795
target_files = self.get_versionedfiles('target')
1796
key = self.get_simple_key('ft')
1797
key_delta = self.get_simple_key('delta')
1798
files.add_lines(key, (), ['my text\n', 'content'])
1800
delta_parents = (key,)
1803
files.add_lines(key_delta, delta_parents, ['different\n', 'content\n'])
1804
target_files.insert_record_stream(files.get_record_stream([key],
1805
'unordered', False))
1806
local = files.get_record_stream([key_delta], 'unordered', False)
1807
ref = files.get_record_stream([key_delta], 'unordered', False)
1808
skipped_records = [0]
1809
def to_bytes(stream):
1810
for record in stream:
1811
if record.storage_kind in ('chunked', 'fulltext'):
1812
skipped_records[0] += 1
1813
# check the content is correct for direct use.
1814
self.assertRecordHasContent(record, "different\ncontent\n")
1816
yield record.get_bytes_as(record.storage_kind)
1817
byte_stream = to_bytes(local)
1818
network_stream = versionedfile.NetworkRecordStream(byte_stream).read()
1820
# We assume that the order of local and ref will be identical given the
1821
# same parameters to the same source objects.
1822
def check_stream(network_stream, reference_stream):
1823
# We make assertions during copying to catch things early for
1825
for record, ref_record in izip(network_stream, reference_stream):
1826
records.append(record)
1827
self.assertEqual(ref_record.key, record.key)
1828
self.assertEqual(ref_record.storage_kind, record.storage_kind)
1829
self.assertEqual(ref_record.parents, record.parents)
1831
# insert the stream from the network into a versioned files object so we can
1832
# check the content was carried across correctly without doing delta
1833
# inspection during check_stream.
1834
target_files.insert_record_stream(check_stream(network_stream, ref))
1835
# No duplicates on the wire thank you!
1836
self.assertEqual(1, len(records) + skipped_records[0])
1838
# if any content was copied it all must have all been
1791
1839
self.assertIdenticalVersionedFile(files, target_files)
1793
1841
def assertAbsentRecord(self, files, keys, parents, entries):