927
927
size = trans.put_file(name, stream)
928
928
return GraphIndex(trans, name, size)
930
def make_index_with_missing_children(self):
931
"""Create a CombinedGraphIndex which will have missing indexes.
933
This creates a CGI which thinks it has 2 indexes, however they have
934
been deleted. If CGI._reload_func() is called, then it will repopulate
937
:return: (CombinedGraphIndex, reload_counter)
939
index1 = self.make_index('1', nodes=[(('1',), '', ())])
940
index2 = self.make_index('2', nodes=[(('2',), '', ())])
941
index3 = self.make_index('3', nodes=[
945
# total_reloads, num_changed, num_unchanged
946
reload_counter = [0, 0, 0]
948
reload_counter[0] += 1
949
new_indices = [index3]
950
if index._indices == new_indices:
951
reload_counter[2] += 1
953
reload_counter[1] += 1
954
index._indices[:] = new_indices
956
index = CombinedGraphIndex([index1, index2], reload_func=reload)
957
trans = self.get_transport()
960
return index, reload_counter
930
962
def test_open_missing_index_no_error(self):
931
963
trans = self.get_transport()
932
964
index1 = GraphIndex(trans, 'missing', 100)
1070
1102
index = CombinedGraphIndex([])
1071
1103
index.validate()
1105
def test_key_count_reloads(self):
1106
index, reload_counter = self.make_index_with_missing_children()
1107
self.assertEqual(2, index.key_count())
1108
self.assertEqual([1, 1, 0], reload_counter)
1110
def test_key_count_reloads_and_fails(self):
1111
index, reload_counter = self.make_index_with_missing_children()
1112
# We have deleted the underlying index, so we will try to reload, but
1113
# still fail. This is mostly to test we don't get stuck in an infinite
1114
# loop trying to reload
1115
self.get_transport().delete('3')
1116
self.assertRaises(errors.NoSuchFile, index.key_count)
1117
self.assertEqual([2, 1, 1], reload_counter)
1074
1120
class TestInMemoryGraphIndex(TestCaseWithMemoryTransport):