~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Aaron Bentley
  • Date: 2009-04-23 16:02:28 UTC
  • mto: This revision was merged to the branch mainline in revision 4302.
  • Revision ID: aaron@aaronbentley.com-20090423160228-gxb9fjel30ihjqm2
Add reference_info caching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
379
379
        self.assertTrue(branch.repository.has_revision(revid))
380
380
 
381
381
 
 
382
class BzrBranch8(TestCaseWithTransport):
 
383
 
 
384
    def make_branch(self, location, format=None):
 
385
        if format is None:
 
386
            format = bzrdir.format_registry.make_bzrdir('1.9')
 
387
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
 
388
        return TestCaseWithTransport.make_branch(self, location, format=format)
 
389
 
 
390
    def create_branch_with_reference(self):
 
391
        branch = self.make_branch('branch')
 
392
        branch._set_all_reference_info({'file-id': ('path', 'location')})
 
393
        return branch
 
394
 
 
395
    @staticmethod
 
396
    def instrument_branch(branch, gets):
 
397
        old_get = branch._transport.get
 
398
        def get(*args, **kwargs):
 
399
            gets.append((args, kwargs))
 
400
            return old_get(*args, **kwargs)
 
401
        branch._transport.get = get
 
402
 
 
403
    def test_reference_info_caching_read_locked(self):
 
404
        gets = []
 
405
        branch = self.create_branch_with_reference()
 
406
        branch.lock_read()
 
407
        self.addCleanup(branch.unlock)
 
408
        self.instrument_branch(branch, gets)
 
409
        branch.get_reference_info('file-id')
 
410
        branch.get_reference_info('file-id')
 
411
        self.assertEqual(1, len(gets))
 
412
 
 
413
    def test_reference_info_caching_read_unlocked(self):
 
414
        gets = []
 
415
        branch = self.create_branch_with_reference()
 
416
        self.instrument_branch(branch, gets)
 
417
        branch.get_reference_info('file-id')
 
418
        branch.get_reference_info('file-id')
 
419
        self.assertEqual(2, len(gets))
 
420
 
 
421
    def test_reference_info_caching_write_locked(self):
 
422
        gets = []
 
423
        branch = self.make_branch('branch')
 
424
        branch.lock_write()
 
425
        self.instrument_branch(branch, gets)
 
426
        self.addCleanup(branch.unlock)
 
427
        branch._set_all_reference_info({'file-id': ('path2', 'location2')})
 
428
        path, location = branch.get_reference_info('file-id')
 
429
        self.assertEqual(0, len(gets))
 
430
        self.assertEqual('path2', path)
 
431
        self.assertEqual('location2', location)
 
432
 
 
433
    def test_reference_info_caches_cleared(self):
 
434
        branch = self.make_branch('branch')
 
435
        branch.lock_write()
 
436
        branch.set_reference_info('file-id', 'path2', 'location2')
 
437
        branch.unlock()
 
438
        doppelganger = Branch.open('branch')
 
439
        doppelganger.set_reference_info('file-id', 'path3', 'location3')
 
440
        self.assertEqual(('path3', 'location3'),
 
441
                         branch.get_reference_info('file-id'))
 
442
 
382
443
class TestBranchReference(TestCaseWithTransport):
383
444
    """Tests for the branch reference facility."""
384
445