~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-24 21:52:59 UTC
  • mto: (3860.1.1 153786-retry)
  • mto: This revision was merged to the branch mainline in revision 3865.
  • Revision ID: john@arbash-meinel.com-20081024215259-xh1qcfeu9bdy6350
Change _DirectPackAccess to only raise Retry when _reload_func is defined.

Show diffs side-by-side

added added

removed removed

Lines of Context:
340
340
        access.set_writer(writer, index, (transport, packname))
341
341
        return access, writer
342
342
 
 
343
    def make_pack_file(self):
 
344
        """Create a pack file with 2 records."""
 
345
        access, writer = self._get_access(packname='packname', index='foo')
 
346
        memos = []
 
347
        memos.extend(access.add_raw_records([('key1', 10)], '1234567890'))
 
348
        memos.extend(access.add_raw_records([('key2', 5)], '12345'))
 
349
        writer.end()
 
350
        return memos
 
351
 
 
352
    def make_reload_func(self):
 
353
        reload_called = [0]
 
354
        def reload():
 
355
            reload_called[0] += 1
 
356
            return True
 
357
        return reload_called, reload
 
358
 
343
359
    def test_read_from_several_packs(self):
344
360
        access, writer = self._get_access()
345
361
        memos = []
382
398
        self.assertEqual(['1234567890'], list(access.get_raw_records(memos)))
383
399
 
384
400
    def test_missing_index_raises_retry(self):
385
 
        access, writer = self._get_access(packname='packname', index='foo')
386
 
        memos = []
387
 
        memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
388
 
        writer.end()
 
401
        memos = self.make_pack_file()
389
402
        transport = self.get_transport()
390
 
        # Note that the 'index' key has changed
391
 
        access = _DirectPackAccess({'bar':(transport, 'packname')})
 
403
        reload_called, reload_func = self.make_reload_func()
 
404
        # Note that the index key has changed from 'foo' to 'bar'
 
405
        access = _DirectPackAccess({'bar':(transport, 'packname')},
 
406
                                   reload_func=reload_func)
392
407
        e = self.assertListRaises(errors.RetryWithNewPacks,
393
408
                                  access.get_raw_records, memos)
394
409
        # Because a key was passed in which does not match our index list, we
398
413
        self.assertIs(e.exc_info[0], KeyError)
399
414
        self.assertIsInstance(e.exc_info[1], KeyError)
400
415
 
 
416
    def test_missing_index_raises_key_error_with_no_reload(self):
 
417
        memos = self.make_pack_file()
 
418
        transport = self.get_transport()
 
419
        # Note that the index key has changed from 'foo' to 'bar'
 
420
        access = _DirectPackAccess({'bar':(transport, 'packname')})
 
421
        e = self.assertListRaises(KeyError, access.get_raw_records, memos)
 
422
 
401
423
    def test_missing_file_raises_retry(self):
402
 
        access, writer = self._get_access(packname='packname', index='foo')
403
 
        memos = []
404
 
        memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
405
 
        writer.end()
406
 
        transport = self.get_transport()
407
 
        # Note that the 'filename' has been changed
 
424
        memos = self.make_pack_file()
 
425
        transport = self.get_transport()
 
426
        reload_called, reload_func = self.make_reload_func()
 
427
        # Note that the 'filename' has been changed to 'different-packname'
 
428
        access = _DirectPackAccess({'foo':(transport, 'different-packname')},
 
429
                                   reload_func=reload_func)
 
430
        e = self.assertListRaises(errors.RetryWithNewPacks,
 
431
                                  access.get_raw_records, memos)
 
432
        # The file has gone missing, so we assume we need to reload
 
433
        self.assertFalse(e.reload_occurred)
 
434
        self.assertIsInstance(e.exc_info, tuple)
 
435
        self.assertIs(e.exc_info[0], errors.NoSuchFile)
 
436
        self.assertIsInstance(e.exc_info[1], errors.NoSuchFile)
 
437
        self.assertEqual('different-packname', e.exc_info[1].path)
 
438
 
 
439
    def test_missing_file_raises_no_such_file_with_no_reload(self):
 
440
        memos = self.make_pack_file()
 
441
        transport = self.get_transport()
 
442
        # Note that the 'filename' has been changed to 'different-packname'
408
443
        access = _DirectPackAccess({'foo':(transport, 'different-packname')})
409
 
        e = self.assertListRaises(errors.RetryWithNewPacks,
 
444
        e = self.assertListRaises(errors.NoSuchFile,
410
445
                                  access.get_raw_records, memos)
411
 
        # The file has gone missing, so we assume we need to reload
412
 
        self.assertFalse(e.reload_occurred)
413
 
        self.assertIsInstance(e.exc_info, tuple)
414
 
        self.assertIs(e.exc_info[0], errors.NoSuchFile)
415
 
        self.assertIsInstance(e.exc_info[1], errors.NoSuchFile)
416
 
        self.assertEqual('different-packname', e.exc_info[1].path)
417
446
 
418
447
    def test_failing_readv_raises_retry(self):
419
 
        access, writer = self._get_access(packname='packname', index='foo')
420
 
        memos = []
421
 
        memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
422
 
        memos.extend(access.add_raw_records([('key', 5)], '12345'))
423
 
        writer.end()
424
 
        transport = self.get_transport()
425
 
        failing_transport = MockReadvFailingTransport(
426
 
                                [transport.get_bytes('packname')])
 
448
        memos = self.make_pack_file()
 
449
        transport = self.get_transport()
 
450
        failing_transport = MockReadvFailingTransport(
 
451
                                [transport.get_bytes('packname')])
 
452
        reload_called, reload_func = self.make_reload_func()
 
453
        access = _DirectPackAccess({'foo':(failing_transport, 'packname')},
 
454
                                   reload_func=reload_func)
 
455
        # Asking for a single record will not trigger the Mock failure
 
456
        self.assertEqual(['1234567890'],
 
457
            list(access.get_raw_records(memos[:1])))
 
458
        self.assertEqual(['12345'],
 
459
            list(access.get_raw_records(memos[1:2])))
 
460
        # A multiple offset readv() will fail mid-way through
 
461
        e = self.assertListRaises(errors.RetryWithNewPacks,
 
462
                                  access.get_raw_records, memos)
 
463
        # The file has gone missing, so we assume we need to reload
 
464
        self.assertFalse(e.reload_occurred)
 
465
        self.assertIsInstance(e.exc_info, tuple)
 
466
        self.assertIs(e.exc_info[0], errors.NoSuchFile)
 
467
        self.assertIsInstance(e.exc_info[1], errors.NoSuchFile)
 
468
        self.assertEqual('packname', e.exc_info[1].path)
 
469
 
 
470
    def test_failing_readv_raises_no_such_file_with_no_reload(self):
 
471
        memos = self.make_pack_file()
 
472
        transport = self.get_transport()
 
473
        failing_transport = MockReadvFailingTransport(
 
474
                                [transport.get_bytes('packname')])
 
475
        reload_called, reload_func = self.make_reload_func()
427
476
        access = _DirectPackAccess({'foo':(failing_transport, 'packname')})
428
477
        # Asking for a single record will not trigger the Mock failure
429
478
        self.assertEqual(['1234567890'],
431
480
        self.assertEqual(['12345'],
432
481
            list(access.get_raw_records(memos[1:2])))
433
482
        # A multiple offset readv() will fail mid-way through
434
 
        e = self.assertListRaises(errors.RetryWithNewPacks,
 
483
        e = self.assertListRaises(errors.NoSuchFile,
435
484
                                  access.get_raw_records, memos)
436
 
        # The file has gone missing, so we assume we need to reload
437
 
        self.assertFalse(e.reload_occurred)
438
 
        self.assertIsInstance(e.exc_info, tuple)
439
 
        self.assertIs(e.exc_info[0], errors.NoSuchFile)
440
 
        self.assertIsInstance(e.exc_info[1], errors.NoSuchFile)
441
 
        self.assertEqual('packname', e.exc_info[1].path)
442
485
 
443
486
 
444
487
class LowLevelKnitDataTests(TestCase):