90
88
self.assertEqual(sorted([('one',), ('two',), ('three',)]),
91
89
sorted(gen.needed_keys))
92
90
stream = vf.get_record_stream(gen.needed_keys, 'topological', True)
91
record = stream.next()
94
92
self.assertEqual(('one',), record.key)
95
93
# one is not needed in the output, but it is needed by children. As
96
94
# such, it should end up in the various caches
97
95
gen._process_one_record(record.key, record.get_bytes_as('chunked'))
98
96
# The chunks should be cached, the refcount untouched
99
self.assertEqual({('one',)}, set(gen.chunks))
97
self.assertEqual([('one',)], gen.chunks.keys())
100
98
self.assertEqual({('one',): 2, ('two',): 1}, gen.refcounts)
101
self.assertEqual(set(), set(gen.diffs))
99
self.assertEqual([], gen.diffs.keys())
102
100
# Next we get 'two', which is something we output, but also needed for
104
record = next(stream)
102
record = stream.next()
105
103
self.assertEqual(('two',), record.key)
106
104
gen._process_one_record(record.key, record.get_bytes_as('chunked'))
107
105
# Both are now cached, and the diff for two has been extracted, and
108
106
# one's refcount has been updated. two has been removed from the
110
self.assertEqual({('one',), ('two',)}, set(gen.chunks))
108
self.assertEqual(sorted([('one',), ('two',)]),
109
sorted(gen.chunks.keys()))
111
110
self.assertEqual({('one',): 1, ('two',): 1}, gen.refcounts)
112
self.assertEqual({('two',)}, set(gen.diffs))
111
self.assertEqual([('two',)], gen.diffs.keys())
113
112
self.assertEqual({('three',): (('one',), ('two',))},
115
114
# Finally 'three', which allows us to remove all parents from the
117
record = next(stream)
116
record = stream.next()
118
117
self.assertEqual(('three',), record.key)
119
118
gen._process_one_record(record.key, record.get_bytes_as('chunked'))
120
119
# Both are now cached, and the diff for two has been extracted, and
121
120
# one's refcount has been updated
122
self.assertEqual(set(), set(gen.chunks))
121
self.assertEqual([], gen.chunks.keys())
123
122
self.assertEqual({}, gen.refcounts)
124
self.assertEqual({('two',), ('three',)}, set(gen.diffs))
123
self.assertEqual(sorted([('two',), ('three',)]),
124
sorted(gen.diffs.keys()))
126
126
def test_compute_diffs(self):
127
127
vf = self.make_three_vf()