~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:23:42 UTC
  • mto: (5757.7.2 knitpackrepo-6)
  • mto: This revision was merged to the branch mainline in revision 5771.
  • Revision ID: jelmer@samba.org-20110405142342-577i2bzisi3mkjwt
Move _DirectPackAccess from bzrlib.knit to bzrlib.pack.

Show diffs side-by-side

added added

removed removed

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