382
398
self.assertEqual(['1234567890'], list(access.get_raw_records(memos)))
384
400
def test_missing_index_raises_retry(self):
385
access, writer = self._get_access(packname='packname', index='foo')
387
memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
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)
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)
401
423
def test_missing_file_raises_retry(self):
402
access, writer = self._get_access(packname='packname', index='foo')
404
memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
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)
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)
418
447
def test_failing_readv_raises_retry(self):
419
access, writer = self._get_access(packname='packname', index='foo')
421
memos.extend(access.add_raw_records([('key', 10)], '1234567890'))
422
memos.extend(access.add_raw_records([('key', 5)], '12345'))
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)
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)
444
487
class LowLevelKnitDataTests(TestCase):