546
546
self.assertEqual([((index._size // 2, ('50', )), +1)],
549
def test_lookup_key_resolves_references(self):
550
# generate a big enough index that we only read some of it on a typical
553
def make_key(number):
554
return (str(number) + 'X'*100,)
555
def make_value(number):
556
return str(number) + 'Y'*100
557
for counter in range(64):
558
nodes.append((make_key(counter), make_value(counter),
559
((make_key(counter + 20),),) ))
560
index = self.make_index(ref_lists=1, nodes=nodes)
561
# lookup a key in the middle that does not exist, so that when we can
562
# check that the referred-to-keys are not accessed automatically.
563
result =index.lookup_keys_via_location(
564
[(index._size // 2, ('40', ))])
565
# check the parse map - only the start and middle should have been
567
self.assertEqual([(0, 3890), (6444, 10274)], index._parsed_byte_map)
568
self.assertEqual([(None, make_key(25)), (make_key(37), make_key(52))],
569
index._parsed_key_map)
570
# and check the transport activity likewise.
572
[('readv', 'index', [(7906, 800), (0, 200)], True, 15813)],
573
index._transport._activity)
574
# reset the transport log for testing the reference lookup
575
del index._transport._activity[:]
576
# now looking up a key in the portion of the file already parsed should
577
# only perform IO to resolve its key references.
578
result = index.lookup_keys_via_location([(4000, make_key(40))])
580
[((4000, make_key(40)),
581
(index, make_key(40), make_value(40), ((make_key(60),),)))],
583
self.assertEqual([('readv', 'index', [(11976, 800)], True, 15813)],
584
index._transport._activity)
549
587
def test_iter_all_entries_empty(self):
550
588
index = self.make_index()
551
589
self.assertEqual([], list(index.iter_all_entries()))