2218
2218
record = it.next()
2219
2219
self.assertEquals("absent", record.storage_kind)
2222
class TestOrderingVersionedFilesDecorator(TestCaseWithMemoryTransport):
2224
def get_ordering_vf(self, key_priority):
2225
builder = self.make_branch_builder('test')
2226
builder.start_series()
2227
builder.build_snapshot('A', None, [
2228
('add', ('', 'TREE_ROOT', 'directory', None))])
2229
builder.build_snapshot('B', ['A'], [])
2230
builder.build_snapshot('C', ['B'], [])
2231
builder.build_snapshot('D', ['C'], [])
2232
builder.finish_series()
2233
b = builder.get_branch()
2235
self.addCleanup(b.unlock)
2236
vf = b.repository.inventories
2237
return versionedfile.OrderingVersionedFilesDecorator(vf, key_priority)
2239
def test_get_empty(self):
2240
vf = self.get_ordering_vf({})
2241
self.assertEqual([], vf.calls)
2243
def test_get_record_stream_topological(self):
2244
vf = self.get_ordering_vf({('A',): 3, ('B',): 2, ('C',): 4, ('D',): 1})
2245
request_keys = [('B',), ('C',), ('D',), ('A',)]
2246
keys = [r.key for r in vf.get_record_stream(request_keys,
2247
'topological', False)]
2248
# We should have gotten the keys in topological order
2249
self.assertEqual([('A',), ('B',), ('C',), ('D',)], keys)
2250
# And recorded that the request was made
2251
self.assertEqual([('get_record_stream', request_keys, 'topological',
2254
def test_get_record_stream_ordered(self):
2255
vf = self.get_ordering_vf({('A',): 3, ('B',): 2, ('C',): 4, ('D',): 1})
2256
request_keys = [('B',), ('C',), ('D',), ('A',)]
2257
keys = [r.key for r in vf.get_record_stream(request_keys,
2258
'unordered', False)]
2259
# They should be returned based on their priority
2260
self.assertEqual([('D',), ('B',), ('A',), ('C',)], keys)
2261
# And the request recorded
2262
self.assertEqual([('get_record_stream', request_keys, 'unordered',
2265
def test_get_record_stream_implicit_order(self):
2266
vf = self.get_ordering_vf({('B',): 2, ('D',): 1})
2267
request_keys = [('B',), ('C',), ('D',), ('A',)]
2268
keys = [r.key for r in vf.get_record_stream(request_keys,
2269
'unordered', False)]
2270
# A and C are not in the map, so they get sorted to the front. A comes
2271
# before C alphabetically, so it comes back first
2272
self.assertEqual([('A',), ('C',), ('D',), ('B',)], keys)
2273
# And the request recorded
2274
self.assertEqual([('get_record_stream', request_keys, 'unordered',