388
388
size = trans.put_file('index', stream)
389
389
return GraphIndex(trans, 'index', size)
391
def make_index_with_offset(self, ref_lists=0, key_elements=1, nodes=[],
393
builder = GraphIndexBuilder(ref_lists, key_elements=key_elements)
394
for key, value, references in nodes:
395
builder.add_node(key, value, references)
396
content = builder.finish().read()
398
trans = self.get_transport()
399
trans.put_bytes('index', (' '*offset) + content)
400
return GraphIndex(trans, 'index', size, offset=offset)
391
402
def test_clear_cache(self):
392
403
index = self.make_index()
393
404
# For now, we just want to make sure the api is available. As this is
399
410
trans.put_bytes('name', "not an index\n")
400
411
index = GraphIndex(trans, 'name', 13)
413
def test_with_offset(self):
414
nodes = self.make_nodes(200)
415
index = self.make_index_with_offset(offset=1234567, nodes=nodes)
416
self.assertEqual(200, index.key_count())
418
def test_buffer_all_with_offset(self):
419
nodes = self.make_nodes(200)
420
index = self.make_index_with_offset(offset=1234567, nodes=nodes)
422
self.assertEqual(200, index.key_count())
424
def test_side_effect_buffering_with_offset(self):
425
nodes = self.make_nodes(20)
426
index = self.make_index_with_offset(offset=1234567, nodes=nodes)
427
index._transport.recommended_page_size = lambda:64*1024
428
subset_nodes = [nodes[0][0], nodes[10][0], nodes[19][0]]
429
entries = [n[1] for n in index.iter_entries(subset_nodes)]
430
self.assertEqual(sorted(subset_nodes), sorted(entries))
431
self.assertEqual(20, index.key_count())
402
433
def test_open_sets_parsed_map_empty(self):
403
434
index = self.make_index()
404
435
self.assertEqual([], index._parsed_byte_map)