180
176
transaction.map.add_weave("id", weave)
181
177
self.assertEqual(None, transaction.map.find_weave("id"))
179
def test_rollback_asserts(self):
180
transaction = transactions.PassThroughTransaction()
181
self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
183
183
def test_finish_returns(self):
184
184
transaction = transactions.PassThroughTransaction()
185
185
transaction.finish()
187
def test_finish_tells_versioned_file_finished(self):
188
# pass through transactions allow writes so they
189
# need to inform versioned files about finishing
190
weave = DummyWeave('a weave')
191
transaction = transactions.PassThroughTransaction()
192
transaction.register_dirty(weave)
194
self.assertTrue(weave.finished)
196
187
def test_cache_is_ignored(self):
197
188
transaction = transactions.PassThroughTransaction()
198
189
transaction.set_cache_size(100)
199
190
weave = "a weave"
200
191
transaction.map.add_weave("id", weave)
201
192
self.assertEqual(None, transaction.map.find_weave("id"))
203
def test_writable(self):
204
transaction = transactions.PassThroughTransaction()
205
self.assertTrue(transaction.writeable())
208
class TestWriteTransaction(TestCase):
211
self.transaction = transactions.WriteTransaction()
212
super(TestWriteTransaction, self).setUp()
214
def test_register_clean(self):
215
self.transaction.register_clean("anobject")
217
def test_register_dirty(self):
218
self.transaction.register_dirty("anobject")
221
self.assertNotEqual(None, getattr(self.transaction, "map", None))
223
def test_add_and_get(self):
225
self.transaction.map.add_weave("id", weave)
226
self.assertEqual(weave, self.transaction.map.find_weave("id"))
228
def test_finish_returns(self):
229
self.transaction.finish()
231
def test_finish_tells_versioned_file_finished(self):
232
# write transactions allow writes so they
233
# need to inform versioned files about finishing
234
weave = DummyWeave('a weave')
235
self.transaction.register_dirty(weave)
236
self.transaction.finish()
237
self.assertTrue(weave.finished)
239
def test_zero_size_cache(self):
240
self.transaction.set_cache_size(0)
241
# add an object, should fall right out if there are no references
242
weave = DummyWeave('a weave')
243
self.transaction.map.add_weave("id", weave)
244
self.assertEqual(weave, self.transaction.map.find_weave("id"))
246
self.transaction.register_clean(self.transaction.map.find_weave("id"))
247
self.assertEqual(None, self.transaction.map.find_weave("id"))
248
# but if we have a reference to a clean object it should stick around
249
weave = DummyWeave("another weave")
250
self.transaction.map.add_weave("id", weave)
251
self.transaction.register_clean(self.transaction.map.find_weave("id"))
252
self.assertEqual(weave, self.transaction.map.find_weave("id"))
254
# its not a weakref system
255
self.assertEqual(DummyWeave("another weave"),
256
self.transaction.map.find_weave("id"))
258
def test_zero_size_cache_dirty_objects(self):
259
self.transaction.set_cache_size(0)
260
# add a dirty object, which should not fall right out.
261
weave = DummyWeave('a weave')
262
self.transaction.map.add_weave("id", weave)
263
self.assertEqual(weave, self.transaction.map.find_weave("id"))
265
self.transaction.register_dirty(self.transaction.map.find_weave("id"))
266
self.assertNotEqual(None, self.transaction.map.find_weave("id"))
268
def test_clean_to_dirty(self):
269
# a clean object may become dirty.
270
weave = DummyWeave('A weave')
271
self.transaction.map.add_weave("id", weave)
272
self.transaction.register_clean(weave)
273
self.transaction.register_dirty(weave)
274
self.assertTrue(self.transaction.is_dirty(weave))
275
self.assertFalse(self.transaction.is_clean(weave))
277
def test_small_cache(self):
278
self.transaction.set_cache_size(1)
279
# add an object, should not fall right out if there are no references
280
#sys.getrefcounts(foo)
281
self.transaction.map.add_weave("id", DummyWeave("a weave"))
282
self.transaction.register_clean(self.transaction.map.find_weave("id"))
283
self.assertEqual(DummyWeave("a weave"),
284
self.transaction.map.find_weave("id"))
285
self.transaction.map.add_weave("id2", DummyWeave("a weave also"))
286
self.transaction.register_clean(self.transaction.map.find_weave("id2"))
288
self.assertEqual(None, self.transaction.map.find_weave("id"))
289
self.assertEqual(DummyWeave("a weave also"),
290
self.transaction.map.find_weave("id2"))
292
def test_small_cache_with_references(self):
293
# if we have a reference it should stick around
295
weave2 = "another weave"
296
self.transaction.map.add_weave("id", weave)
297
self.transaction.map.add_weave("id2", weave2)
298
self.assertEqual(weave, self.transaction.map.find_weave("id"))
299
self.assertEqual(weave2, self.transaction.map.find_weave("id2"))
301
# its not a weakref system
302
self.assertEqual("a weave", self.transaction.map.find_weave("id"))
304
def test_precious_with_zero_size_cache(self):
305
self.transaction.set_cache_size(0)
306
weave = DummyWeave('a weave')
307
self.transaction.map.add_weave("id", weave)
308
self.assertEqual(weave, self.transaction.map.find_weave("id"))
310
# add an object, should not fall out even with no references.
311
self.transaction.register_clean(self.transaction.map.find_weave("id"),
313
self.assertEqual(DummyWeave('a weave'),
314
self.transaction.map.find_weave("id"))
316
def test_writable(self):
317
self.assertTrue(self.transaction.writeable())