1
# Copyright (C) 2007, 2009 Canonical Ltd
1
# Copyright (C) 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
173
173
"key\x00\x00\t\x00data\n"
176
def test_clear_cache(self):
177
builder = GraphIndexBuilder(reference_lists=2)
178
# This is a no-op, but the api should exist
179
builder.clear_cache()
181
176
def test_node_references_are_byte_offsets(self):
182
177
builder = GraphIndexBuilder(reference_lists=1)
183
178
builder.add_node(('reference', ), 'data', ([], ))
235
230
builder.add_node(('2-key', ), '', (references, ))
236
231
stream = builder.finish()
237
232
contents = stream.read()
238
self.assertEqualDiff(
239
234
"Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\nlen=1\n"
240
235
"0\x00a\x00\x00\n"
241
236
"1\x00a\x00\x00\n"
388
383
size = trans.put_file('index', stream)
389
384
return GraphIndex(trans, 'index', size)
391
def test_clear_cache(self):
392
index = self.make_index()
393
# For now, we just want to make sure the api is available. As this is
394
# old code, we don't really worry if it *does* anything.
397
386
def test_open_bad_index_no_error(self):
398
387
trans = self.get_transport()
399
388
trans.put_bytes('name', "not an index\n")
1017
1006
self.assertEqual(set(), missing_keys)
1018
1007
self.assertEqual(set(), search_keys)
1020
def test_supports_unlimited_cache(self):
1021
builder = GraphIndexBuilder(0, key_elements=1)
1022
stream = builder.finish()
1023
trans = get_transport(self.get_url())
1024
size = trans.put_file('index', stream)
1025
# It doesn't matter what unlimited_cache does here, just that it can be
1027
index = GraphIndex(trans, 'index', size, unlimited_cache=True)
1030
1010
class TestCombinedGraphIndex(TestCaseWithMemoryTransport):
1082
1062
index.insert_index(0, index1)
1083
1063
self.assertEqual([(index1, ('key', ), '')], list(index.iter_all_entries()))
1085
def test_clear_cache(self):
1088
class ClearCacheProxy(object):
1090
def __init__(self, index):
1093
def __getattr__(self, name):
1094
return getattr(self._index)
1096
def clear_cache(self):
1097
log.append(self._index)
1098
return self._index.clear_cache()
1100
index = CombinedGraphIndex([])
1101
index1 = self.make_index('name', 0, nodes=[(('key', ), '', ())])
1102
index.insert_index(0, ClearCacheProxy(index1))
1103
index2 = self.make_index('name', 0, nodes=[(('key', ), '', ())])
1104
index.insert_index(1, ClearCacheProxy(index2))
1105
# CombinedGraphIndex should call 'clear_cache()' on all children
1107
self.assertEqual(sorted([index1, index2]), sorted(log))
1109
1065
def test_iter_all_entries_empty(self):
1110
1066
index = CombinedGraphIndex([])
1111
1067
self.assertEqual([], list(index.iter_all_entries()))