/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_write_group.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-02 09:21:20 UTC
  • mfrom: (4396 +trunk)
  • mto: (4396.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4397.
  • Revision ID: v.ladeuil+lp@free.fr-20090602092120-xs1ikguqckiu820o
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import sys
20
20
 
21
 
from bzrlib import bzrdir, errors, graph, memorytree, remote
 
21
from bzrlib import (
 
22
    bzrdir,
 
23
    errors,
 
24
    graph,
 
25
    memorytree,
 
26
    osutils,
 
27
    remote,
 
28
    versionedfile,
 
29
    )
22
30
from bzrlib.branch import BzrBranchFormat7
23
31
from bzrlib.inventory import InventoryDirectory
24
32
from bzrlib.transport import local, memory
240
248
        inventory) in it must have all the texts in its inventory (even if not
241
249
        changed w.r.t. to the absent parent), otherwise it will report missing
242
250
        texts/parent inventory.
243
 
        
 
251
 
244
252
        The core of this test is that a file was changed in rev-1, but in a
245
 
        stacked repo that only has rev-2 
 
253
        stacked repo that only has rev-2
246
254
        """
247
255
        # Make a trunk with one commit.
248
256
        trunk_repo = self.make_stackable_repo()
284
292
            set(), reopened_repo.get_missing_parent_inventories())
285
293
        reopened_repo.abort_write_group()
286
294
 
 
295
    def test_get_missing_parent_inventories_check(self):
 
296
        builder = self.make_branch_builder('test')
 
297
        builder.build_snapshot('A-id', ['ghost-parent-id'], [
 
298
            ('add', ('', 'root-id', 'directory', None)),
 
299
            ('add', ('file', 'file-id', 'file', 'content\n'))],
 
300
            allow_leftmost_as_ghost=True)
 
301
        b = builder.get_branch()
 
302
        b.lock_read()
 
303
        self.addCleanup(b.unlock)
 
304
        repo = self.make_repository('test-repo')
 
305
        repo.lock_write()
 
306
        self.addCleanup(repo.unlock)
 
307
        repo.start_write_group()
 
308
        self.addCleanup(repo.abort_write_group)
 
309
        # Now, add the objects manually
 
310
        text_keys = [('file-id', 'A-id')]
 
311
        if repo.supports_rich_root():
 
312
            text_keys.append(('root-id', 'A-id'))
 
313
        # Directly add the texts, inventory, and revision object for 'A-id'
 
314
        repo.texts.insert_record_stream(b.repository.texts.get_record_stream(
 
315
            text_keys, 'unordered', True))
 
316
        repo.add_revision('A-id', b.repository.get_revision('A-id'),
 
317
                          b.repository.get_inventory('A-id'))
 
318
        get_missing = repo.get_missing_parent_inventories
 
319
        if repo._format.supports_external_lookups:
 
320
            self.assertEqual(set([('inventories', 'ghost-parent-id')]),
 
321
                get_missing(check_for_missing_texts=False))
 
322
            self.assertEqual(set(), get_missing(check_for_missing_texts=True))
 
323
            self.assertEqual(set(), get_missing())
 
324
        else:
 
325
            # If we don't support external lookups, we always return empty
 
326
            self.assertEqual(set(), get_missing(check_for_missing_texts=False))
 
327
            self.assertEqual(set(), get_missing(check_for_missing_texts=True))
 
328
            self.assertEqual(set(), get_missing())
 
329
 
 
330
    def test_insert_stream_passes_resume_info(self):
 
331
        repo = self.make_repository('test-repo')
 
332
        if not repo._format.supports_external_lookups:
 
333
            raise TestNotApplicable('only valid in resumable repos')
 
334
        # log calls to get_missing_parent_inventories, so that we can assert it
 
335
        # is called with the correct parameters
 
336
        call_log = []
 
337
        orig = repo.get_missing_parent_inventories
 
338
        def get_missing(check_for_missing_texts=True):
 
339
            call_log.append(check_for_missing_texts)
 
340
            return orig(check_for_missing_texts=check_for_missing_texts)
 
341
        repo.get_missing_parent_inventories = get_missing
 
342
        repo.lock_write()
 
343
        self.addCleanup(repo.unlock)
 
344
        sink = repo._get_sink()
 
345
        sink.insert_stream((), repo._format, [])
 
346
        self.assertEqual([False], call_log)
 
347
        del call_log[:]
 
348
        repo.start_write_group()
 
349
        # We need to insert something, or suspend_write_group won't actually
 
350
        # create a token
 
351
        repo.texts.insert_record_stream([versionedfile.FulltextContentFactory(
 
352
            ('file-id', 'rev-id'), (), None, 'lines\n')])
 
353
        tokens = repo.suspend_write_group()
 
354
        self.assertNotEqual([], tokens)
 
355
        sink.insert_stream((), repo._format, tokens)
 
356
        self.assertEqual([True], call_log)
 
357
 
287
358
 
288
359
class TestResumeableWriteGroup(TestCaseWithRepository):
289
360
 
518
589
        source_repo.start_write_group()
519
590
        key_base = ('file-id', 'base')
520
591
        key_delta = ('file-id', 'delta')
521
 
        source_repo.texts.add_lines(key_base, (), ['lines\n'])
522
 
        source_repo.texts.add_lines(
523
 
            key_delta, (key_base,), ['more\n', 'lines\n'])
 
592
        def text_stream():
 
593
            yield versionedfile.FulltextContentFactory(
 
594
                key_base, (), None, 'lines\n')
 
595
            yield versionedfile.FulltextContentFactory(
 
596
                key_delta, (key_base,), None, 'more\nlines\n')
 
597
        source_repo.texts.insert_record_stream(text_stream())
524
598
        source_repo.commit_write_group()
525
599
        return source_repo
526
600
 
536
610
        stream = source_repo.texts.get_record_stream(
537
611
            [key_delta], 'unordered', False)
538
612
        repo.texts.insert_record_stream(stream)
539
 
        # It's not commitable due to the missing compression parent.
540
 
        self.assertRaises(
541
 
            errors.BzrCheckError, repo.commit_write_group)
 
613
        # It's either not commitable due to the missing compression parent, or
 
614
        # the stacked location has already filled in the fulltext.
 
615
        try:
 
616
            repo.commit_write_group()
 
617
        except errors.BzrCheckError:
 
618
            # It refused to commit because we have a missing parent
 
619
            pass
 
620
        else:
 
621
            same_repo = self.reopen_repo(repo)
 
622
            same_repo.lock_read()
 
623
            record = same_repo.texts.get_record_stream([key_delta],
 
624
                                                       'unordered', True).next()
 
625
            self.assertEqual('more\nlines\n', record.get_bytes_as('fulltext'))
 
626
            return
542
627
        # Merely suspending and resuming doesn't make it commitable either.
543
628
        wg_tokens = repo.suspend_write_group()
544
629
        same_repo = self.reopen_repo(repo)
570
655
        same_repo.texts.insert_record_stream(stream)
571
656
        # Just like if we'd added that record without a suspend/resume cycle,
572
657
        # commit_write_group fails.
573
 
        self.assertRaises(
574
 
            errors.BzrCheckError, same_repo.commit_write_group)
 
658
        try:
 
659
            same_repo.commit_write_group()
 
660
        except errors.BzrCheckError:
 
661
            pass
 
662
        else:
 
663
            # If the commit_write_group didn't fail, that is because the
 
664
            # insert_record_stream already gave it a fulltext.
 
665
            same_repo = self.reopen_repo(repo)
 
666
            same_repo.lock_read()
 
667
            record = same_repo.texts.get_record_stream([key_delta],
 
668
                                                       'unordered', True).next()
 
669
            self.assertEqual('more\nlines\n', record.get_bytes_as('fulltext'))
 
670
            return
575
671
        same_repo.abort_write_group()
576
672
 
577
673
    def test_add_missing_parent_after_resume(self):