~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

  • Committer: Martin Pool
  • Date: 2006-03-09 07:14:10 UTC
  • mfrom: (1600 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1602.
  • Revision ID: mbp@sourcefrog.net-20060309071410-4ab7d54905541c75
[merge] from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        self.assertRaises(errors.ReadOnlyError, 
60
60
                          self.transaction.register_dirty,"anobject")
61
61
    
62
 
    def test_commit_raises(self):
63
 
        self.assertRaises(errors.CommitNotPossible, self.transaction.commit)
64
 
 
65
62
    def test_map(self):
66
63
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
67
64
    
70
67
        self.transaction.map.add_weave("id", weave)
71
68
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
72
69
 
73
 
    def test_rollback_returns(self):
74
 
        self.transaction.rollback()
75
 
 
76
70
    def test_finish_returns(self):
77
71
        self.transaction.finish()
78
72
 
162
156
        transaction = transactions.PassThroughTransaction()
163
157
        transaction.register_dirty("anobject")
164
158
    
165
 
    def test_commit_nothing_returns(self):
166
 
        transaction = transactions.PassThroughTransaction()
167
 
        transaction.commit()
168
 
 
169
159
    def test_map(self):
170
160
        transaction = transactions.PassThroughTransaction()
171
161
        self.assertNotEqual(None, getattr(transaction, "map", None))
176
166
        transaction.map.add_weave("id", weave)
177
167
        self.assertEqual(None, transaction.map.find_weave("id"))
178
168
        
179
 
    def test_rollback_asserts(self):
180
 
        transaction = transactions.PassThroughTransaction()
181
 
        self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
182
 
 
183
169
    def test_finish_returns(self):
184
170
        transaction = transactions.PassThroughTransaction()
185
171
        transaction.finish()
190
176
        weave = "a weave"
191
177
        transaction.map.add_weave("id", weave)
192
178
        self.assertEqual(None, transaction.map.find_weave("id"))
 
179
 
 
180
        
 
181
class TestWriteTransaction(TestCase):
 
182
 
 
183
    def setUp(self):
 
184
        self.transaction = transactions.WriteTransaction()
 
185
        super(TestWriteTransaction, self).setUp()
 
186
 
 
187
    def test_register_clean(self):
 
188
        self.transaction.register_clean("anobject")
 
189
    
 
190
    def test_register_dirty(self):
 
191
        self.transaction.register_dirty("anobject")
 
192
    
 
193
    def test_map(self):
 
194
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
 
195
    
 
196
    def test_add_and_get(self):
 
197
        weave = "a weave"
 
198
        self.transaction.map.add_weave("id", weave)
 
199
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
200
        
 
201
    def test_finish_returns(self):
 
202
        self.transaction.finish()
 
203
 
 
204
    def test_zero_size_cache(self):
 
205
        self.transaction.set_cache_size(0)
 
206
        # add an object, should fall right out if there are no references
 
207
        weave = DummyWeave('a weave')
 
208
        self.transaction.map.add_weave("id", weave)
 
209
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
210
        weave = None
 
211
        self.transaction.register_clean(self.transaction.map.find_weave("id"))
 
212
        self.assertEqual(None, self.transaction.map.find_weave("id"))
 
213
        # but if we have a reference to a clean object it should stick around
 
214
        weave = DummyWeave("another weave")
 
215
        self.transaction.map.add_weave("id", weave)
 
216
        self.transaction.register_clean(self.transaction.map.find_weave("id"))
 
217
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
218
        del weave
 
219
        # its not a weakref system
 
220
        self.assertEqual(DummyWeave("another weave"),
 
221
                         self.transaction.map.find_weave("id"))
 
222
 
 
223
    def test_zero_size_cache_dirty_objects(self):
 
224
        self.transaction.set_cache_size(0)
 
225
        # add a dirty object, which should not fall right out.
 
226
        weave = DummyWeave('a weave')
 
227
        self.transaction.map.add_weave("id", weave)
 
228
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
229
        weave = None
 
230
        self.transaction.register_dirty(self.transaction.map.find_weave("id"))
 
231
        self.assertNotEqual(None, self.transaction.map.find_weave("id"))
 
232
    
 
233
    def test_clean_to_dirty(self):
 
234
        # a clean object may become dirty.
 
235
        weave = DummyWeave('A weave')
 
236
        self.transaction.map.add_weave("id", weave)
 
237
        self.transaction.register_clean(weave)
 
238
        self.transaction.register_dirty(weave)
 
239
        self.assertTrue(self.transaction.is_dirty(weave))
 
240
        self.assertFalse(self.transaction.is_clean(weave))
 
241
 
 
242
    def test_small_cache(self):
 
243
        self.transaction.set_cache_size(1)
 
244
        # add an object, should not fall right out if there are no references
 
245
        #sys.getrefcounts(foo)
 
246
        self.transaction.map.add_weave("id", DummyWeave("a weave"))
 
247
        self.transaction.register_clean(self.transaction.map.find_weave("id"))
 
248
        self.assertEqual(DummyWeave("a weave"),
 
249
                         self.transaction.map.find_weave("id"))
 
250
        self.transaction.map.add_weave("id2", DummyWeave("a weave also"))
 
251
        self.transaction.register_clean(self.transaction.map.find_weave("id2"))
 
252
        # currently a fifo
 
253
        self.assertEqual(None, self.transaction.map.find_weave("id"))
 
254
        self.assertEqual(DummyWeave("a weave also"),
 
255
                         self.transaction.map.find_weave("id2"))
 
256
 
 
257
    def test_small_cache_with_references(self):
 
258
        # if we have a reference it should stick around
 
259
        weave = "a weave"
 
260
        weave2 = "another weave"
 
261
        self.transaction.map.add_weave("id", weave)
 
262
        self.transaction.map.add_weave("id2", weave2)
 
263
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
264
        self.assertEqual(weave2, self.transaction.map.find_weave("id2"))
 
265
        weave = None
 
266
        # its not a weakref system
 
267
        self.assertEqual("a weave", self.transaction.map.find_weave("id"))
 
268
 
 
269
    def test_precious_with_zero_size_cache(self):
 
270
        self.transaction.set_cache_size(0)
 
271
        weave = DummyWeave('a weave')
 
272
        self.transaction.map.add_weave("id", weave)
 
273
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
 
274
        weave = None
 
275
        # add an object, should not fall out even with no references.
 
276
        self.transaction.register_clean(self.transaction.map.find_weave("id"),
 
277
                                        precious=True)
 
278
        self.assertEqual(DummyWeave('a weave'),
 
279
                         self.transaction.map.find_weave("id"))