~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-05 14:48:54 UTC
  • mto: (5757.7.2 knitpackrepo-6)
  • mto: This revision was merged to the branch mainline in revision 5771.
  • Revision ID: jelmer@samba.org-20110405144854-a9803ggiflk8u4zq
Revert noknit branch for the moment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    KnitVersionedFiles,
41
41
    PlainKnitContent,
42
42
    _VFContentMapGenerator,
 
43
    _DirectPackAccess,
43
44
    _KndxIndex,
44
45
    _KnitGraphIndex,
45
46
    _KnitKeyAccess,
324
325
            transport.append_bytes(packname, bytes)
325
326
        writer = pack.ContainerWriter(write_data)
326
327
        writer.begin()
327
 
        access = pack._DirectPackAccess({})
 
328
        access = _DirectPackAccess({})
328
329
        access.set_writer(writer, index, (transport, packname))
329
330
        return access, writer
330
331
 
455
456
        memos.extend(access.add_raw_records([('key', 5)], 'alpha'))
456
457
        writer.end()
457
458
        transport = self.get_transport()
458
 
        access = pack._DirectPackAccess({"FOO":(transport, 'packfile'),
 
459
        access = _DirectPackAccess({"FOO":(transport, 'packfile'),
459
460
            "FOOBAR":(transport, 'pack2'),
460
461
            "BAZ":(transport, 'pack3')})
461
462
        self.assertEqual(['1234567890', '12345', 'alpha'],
471
472
 
472
473
    def test_set_writer(self):
473
474
        """The writer should be settable post construction."""
474
 
        access = pack._DirectPackAccess({})
 
475
        access = _DirectPackAccess({})
475
476
        transport = self.get_transport()
476
477
        packname = 'packfile'
477
478
        index = 'foo'
489
490
        transport = self.get_transport()
490
491
        reload_called, reload_func = self.make_reload_func()
491
492
        # Note that the index key has changed from 'foo' to 'bar'
492
 
        access = pack._DirectPackAccess({'bar':(transport, 'packname')},
 
493
        access = _DirectPackAccess({'bar':(transport, 'packname')},
493
494
                                   reload_func=reload_func)
494
495
        e = self.assertListRaises(errors.RetryWithNewPacks,
495
496
                                  access.get_raw_records, memos)
504
505
        memos = self.make_pack_file()
505
506
        transport = self.get_transport()
506
507
        # Note that the index key has changed from 'foo' to 'bar'
507
 
        access = pack._DirectPackAccess({'bar':(transport, 'packname')})
 
508
        access = _DirectPackAccess({'bar':(transport, 'packname')})
508
509
        e = self.assertListRaises(KeyError, access.get_raw_records, memos)
509
510
 
510
511
    def test_missing_file_raises_retry(self):
512
513
        transport = self.get_transport()
513
514
        reload_called, reload_func = self.make_reload_func()
514
515
        # Note that the 'filename' has been changed to 'different-packname'
515
 
        access = pack._DirectPackAccess(
516
 
            {'foo':(transport, 'different-packname')},
517
 
            reload_func=reload_func)
 
516
        access = _DirectPackAccess({'foo':(transport, 'different-packname')},
 
517
                                   reload_func=reload_func)
518
518
        e = self.assertListRaises(errors.RetryWithNewPacks,
519
519
                                  access.get_raw_records, memos)
520
520
        # The file has gone missing, so we assume we need to reload
528
528
        memos = self.make_pack_file()
529
529
        transport = self.get_transport()
530
530
        # Note that the 'filename' has been changed to 'different-packname'
531
 
        access = pack._DirectPackAccess(
532
 
            {'foo':(transport, 'different-packname')})
 
531
        access = _DirectPackAccess({'foo':(transport, 'different-packname')})
533
532
        e = self.assertListRaises(errors.NoSuchFile,
534
533
                                  access.get_raw_records, memos)
535
534
 
539
538
        failing_transport = MockReadvFailingTransport(
540
539
                                [transport.get_bytes('packname')])
541
540
        reload_called, reload_func = self.make_reload_func()
542
 
        access = pack._DirectPackAccess(
543
 
            {'foo':(failing_transport, 'packname')},
544
 
            reload_func=reload_func)
 
541
        access = _DirectPackAccess({'foo':(failing_transport, 'packname')},
 
542
                                   reload_func=reload_func)
545
543
        # Asking for a single record will not trigger the Mock failure
546
544
        self.assertEqual(['1234567890'],
547
545
            list(access.get_raw_records(memos[:1])))
563
561
        failing_transport = MockReadvFailingTransport(
564
562
                                [transport.get_bytes('packname')])
565
563
        reload_called, reload_func = self.make_reload_func()
566
 
        access = pack._DirectPackAccess(
567
 
            {'foo':(failing_transport, 'packname')})
 
564
        access = _DirectPackAccess({'foo':(failing_transport, 'packname')})
568
565
        # Asking for a single record will not trigger the Mock failure
569
566
        self.assertEqual(['1234567890'],
570
567
            list(access.get_raw_records(memos[:1])))
575
572
                                  access.get_raw_records, memos)
576
573
 
577
574
    def test_reload_or_raise_no_reload(self):
578
 
        access = pack._DirectPackAccess({}, reload_func=None)
 
575
        access = _DirectPackAccess({}, reload_func=None)
579
576
        retry_exc = self.make_retry_exception()
580
577
        # Without a reload_func, we will just re-raise the original exception
581
578
        self.assertRaises(_TestException, access.reload_or_raise, retry_exc)
582
579
 
583
580
    def test_reload_or_raise_reload_changed(self):
584
581
        reload_called, reload_func = self.make_reload_func(return_val=True)
585
 
        access = pack._DirectPackAccess({}, reload_func=reload_func)
 
582
        access = _DirectPackAccess({}, reload_func=reload_func)
586
583
        retry_exc = self.make_retry_exception()
587
584
        access.reload_or_raise(retry_exc)
588
585
        self.assertEqual([1], reload_called)
592
589
 
593
590
    def test_reload_or_raise_reload_no_change(self):
594
591
        reload_called, reload_func = self.make_reload_func(return_val=False)
595
 
        access = pack._DirectPackAccess({}, reload_func=reload_func)
 
592
        access = _DirectPackAccess({}, reload_func=reload_func)
596
593
        retry_exc = self.make_retry_exception()
597
594
        # If reload_occurred is False, then we consider it an error to have
598
595
        # reload_func() return False (no changes).