430
431
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):
432
def make_test_vf(self, create_graph, keylength=1, do_cleanup=True):
433
t = self.get_transport()
433
def make_test_vf(self, create_graph, keylength=1, do_cleanup=True,
435
t = self.get_transport(dir)
434
437
vf = groupcompress.make_pack_factory(graph=create_graph,
435
438
delta=False, keylength=keylength)(t)
443
446
def test_get_record_stream_as_requested(self):
444
447
# Consider promoting 'as-requested' to general availability, and
445
448
# make this a VF interface test
446
vf = self.make_test_vf(False, do_cleanup=False)
449
vf = self.make_test_vf(False, do_cleanup=False,
447
451
vf.add_lines(('a',), (), ['lines\n'])
448
452
vf.add_lines(('b',), (), ['lines\n'])
449
453
vf.add_lines(('c',), (), ['lines\n'])
461
465
groupcompress.cleanup_pack_group(vf)
463
467
# It should work even after being repacked into another VF
464
vf2 = self.make_test_vf(False)
468
vf2 = self.make_test_vf(False, dir='target')
465
469
vf2.insert_record_stream(vf.get_record_stream(
466
470
[('b',), ('a',), ('d',), ('c',)], 'as-requested', False))
475
479
'as-requested', False)]
476
480
self.assertEqual([('b',), ('a',), ('d',), ('c',)], keys)
482
def test_get_record_stream_block(self):
483
vf = self.make_test_vf(True, do_cleanup=False, dir='source')
484
def grouped_stream(revision_ids, first_parents=()):
485
parents = first_parents
486
for revision_id in revision_ids:
488
record = versionedfile.FulltextContentFactory(
490
'some content that is\n'
491
'identical except for\n'
492
'revision_id:%s\n' % (revision_id,))
496
vf.insert_record_stream(grouped_stream(['a', 'b', 'c', 'd']))
498
vf.insert_record_stream(grouped_stream(['e', 'f', 'g', 'h'],
499
first_parents=(('d',),)))
501
stream = vf.get_record_stream([(r,) for r in 'abcdefgh'],
503
for record in stream:
504
if record.key in [('a',), ('e',)]:
505
self.assertEqual('groupcompress-block', record.storage_kind)
507
self.assertEqual('groupcompress-block-ref',
509
block_bytes[record.key] = record._manager._block._z_content
512
self.assertIs(block_bytes[key], block_bytes[('a',)])
513
self.assertNotEqual(block_bytes[key], block_bytes[('e',)])
516
self.assertIs(block_bytes[key], block_bytes[('e',)])
517
self.assertNotEqual(block_bytes[key], block_bytes[('a',)])
518
# Now copy the blocks into another vf, and ensure that the blocks are
519
# preserved without creating new entries
520
vf2 = self.make_test_vf(True, dir='target')
521
# ordering in 'groupcompress' order, should actually swap the groups in
522
# the target vf, but the groups themselves should not be disturbed.
523
vf2.insert_record_stream(vf.get_record_stream(
524
[(r,) for r in 'abcdefgh'], 'groupcompress', False))
525
groupcompress.cleanup_pack_group(vf)
526
stream = vf2.get_record_stream([(r,) for r in 'abcdefgh'],
527
'groupcompress', False)
529
for record in stream:
530
self.assertEqual(block_bytes[record.key],
531
record._manager._block._z_content)
479
533
class TestLazyGroupCompress(tests.TestCaseWithTransport):