~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-09 00:35:35 UTC
  • mfrom: (5757.5.4 move-direct-pack-access)
  • Revision ID: pqm@pqm.ubuntu.com-20110409003535-lu3d1bkltkbqul3x
(jelmer) Move _DirectPackAccess to bzrlib.repofmt.pack_repo. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

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