Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.repo_tests.RepositoryClientTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_has_not_got_client_lock
def test_locks_client
def test_locking_client_twice_fails
def test_locking_nonexistent_client_fails
def test_unlock_client_releases_lock
def test_commit_client_releases_lock
def test_commit_does_not_mark_as_checkpoint_by_default
def test_commit_marks_as_checkpoint_when_requested
def test_commit_client_without_lock_fails
def test_unlock_client_without_lock_fails
def test_commit_client_when_locked_by_other_fails
def test_unlock_client_when_locked_by_other_fails
def test_opens_client_fails_if_client_does_not_exist
def test_opens_client_even_when_locked_by_other
def test_lists_no_generations_when_readonly
def test_lists_no_generations_when_locked
def test_listing_generations_fails_if_client_is_not_open
def test_not_making_new_generation
def test_starting_new_generation_without_lock_fails
def test_starting_new_generation_works
def test_starting_second_concurrent_new_generation_fails
def test_second_generation_has_different_id_from_first
def test_new_generation_has_start_time_only
def test_commited_generation_has_start_and_end_times
def test_adding_generation_without_committing_does_not_add_it
def test_removing_generation_works
def test_removing_only_second_generation_works
def test_removing_started_generation_fails
def test_removing_without_committing_does_not_remove
def test_new_generation_has_root_dir_only
def test_create_fails_unless_generation_is_started
def test_create_adds_file
def test_create_adds_two_files
def test_create_adds_lots_of_files
def test_create_adds_dir
def test_create_adds_dir_after_file_in_it
def test_gets_metadata_for_dir
def test_remove_removes_file
def test_remove_removes_directory_tree
def test_get_metadata_works
def test_get_metadata_raises_exception_if_file_does_not_exist

Public Attributes

 tempdir
 fs
 repo
 otherfs
 other
 dir_meta

Detailed Description

Definition at line 245 of file repo_tests.py.


Member Function Documentation

Definition at line 247 of file repo_tests.py.

00247 
00248     def setUp(self):
00249         self.tempdir = tempfile.mkdtemp()
00250 
00251         self.fs = obnamlib.LocalFS(self.tempdir)
00252         self.repo = obnamlib.Repository(self.fs, obnamlib.DEFAULT_NODE_SIZE,
00253                                         obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00254                                         obnamlib.DEFAULT_LRU_SIZE, None,
00255                                         obnamlib.IDPATH_DEPTH,
00256                                         obnamlib.IDPATH_BITS,
00257                                         obnamlib.IDPATH_SKIP,
00258                                         time.time, 0, '')
00259         self.repo.lock_root()
00260         self.repo.add_client('client_name')
00261         self.repo.commit_root()
00262         
00263         self.otherfs = obnamlib.LocalFS(self.tempdir)
00264         self.other = obnamlib.Repository(self.otherfs, 
00265                                          obnamlib.DEFAULT_NODE_SIZE,
00266                                          obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00267                                          obnamlib.DEFAULT_LRU_SIZE, None,
00268                                          obnamlib.IDPATH_DEPTH,
00269                                          obnamlib.IDPATH_BITS,
00270                                          obnamlib.IDPATH_SKIP,
00271                                          time.time, 0, '')
00272         
00273         self.dir_meta = obnamlib.Metadata()
00274         self.dir_meta.st_mode = stat.S_IFDIR | 0777

Definition at line 275 of file repo_tests.py.

00275 
00276     def tearDown(self):
00277         shutil.rmtree(self.tempdir)

Definition at line 406 of file repo_tests.py.

00406 
00407     def test_adding_generation_without_committing_does_not_add_it(self):
00408         self.repo.lock_client('client_name')
00409         self.repo.lock_shared()
00410         self.repo.start_generation()
00411         self.repo.unlock_client()
00412         self.repo.unlock_shared()
00413         self.repo.open_client('client_name')
00414         self.assertEqual(self.repo.list_generations(), [])

Definition at line 298 of file repo_tests.py.

00298 
00299     def test_commit_client_releases_lock(self):
00300         self.repo.lock_client('client_name')
00301         self.repo.lock_shared()
00302         self.repo.commit_client()
00303         self.repo.commit_shared()
00304         self.assertFalse(self.repo.got_client_lock)

Definition at line 332 of file repo_tests.py.

00332 
00333     def test_commit_client_when_locked_by_other_fails(self):
00334         self.other.lock_client('client_name')
00335         self.assertRaises(obnamlib.LockFail, self.repo.commit_client)

Definition at line 326 of file repo_tests.py.

00326 
00327     def test_commit_client_without_lock_fails(self):
00328         self.assertRaises(obnamlib.LockFail, self.repo.commit_client)
        

Definition at line 305 of file repo_tests.py.

00305 
00306     def test_commit_does_not_mark_as_checkpoint_by_default(self):
00307         self.repo.lock_client('client_name')
00308         self.repo.lock_shared()
00309         self.repo.start_generation()
00310         genid = self.repo.new_generation
00311         self.repo.commit_client()
00312         self.repo.commit_shared()
00313         self.repo.open_client('client_name')
00314         self.assertFalse(self.repo.get_is_checkpoint(genid))

Definition at line 315 of file repo_tests.py.

00315 
00316     def test_commit_marks_as_checkpoint_when_requested(self):
00317         self.repo.lock_client('client_name')
00318         self.repo.lock_shared()
00319         self.repo.start_generation()
00320         genid = self.repo.new_generation
00321         self.repo.commit_client(checkpoint=True)
00322         self.repo.commit_shared()
00323 
00324         self.repo.open_client('client_name')
00325         self.assert_(self.repo.get_is_checkpoint(genid))

Definition at line 393 of file repo_tests.py.

00393 
00394     def test_commited_generation_has_start_and_end_times(self):
00395         self.repo.lock_client('client_name')
00396         self.repo.lock_shared()
00397         gen = self.repo.start_generation()
00398         self.repo.commit_client()
00399         self.repo.commit_shared()
00400 
00401         self.repo.open_client('client_name')
00402         start, end = self.repo.get_generation_times(gen)
00403         self.assertNotEqual(start, None)
00404         self.assertNotEqual(end, None)
00405         self.assert_(start <= end)

Definition at line 529 of file repo_tests.py.

00529 
00530     def test_create_adds_dir(self):
00531         self.repo.lock_client('client_name')
00532         gen = self.repo.start_generation()
00533         self.repo.create('/foo', self.dir_meta)
00534         self.assertEqual(self.repo.listdir(gen, '/foo'), [])

Definition at line 535 of file repo_tests.py.

00535 
00536     def test_create_adds_dir_after_file_in_it(self):
00537         self.repo.lock_client('client_name')
00538         gen = self.repo.start_generation()
00539         self.repo.create('/foo/bar', obnamlib.Metadata())
00540         self.repo.create('/foo', self.dir_meta)
00541         self.assertEqual(self.repo.listdir(gen, '/foo'), ['bar'])

Definition at line 504 of file repo_tests.py.

00504 
00505     def test_create_adds_file(self):
00506         self.repo.lock_client('client_name')
00507         gen = self.repo.start_generation()
00508         self.repo.create('/', self.dir_meta)
00509         self.repo.create('/foo', obnamlib.Metadata())
00510         self.assertEqual(self.repo.listdir(gen, '/'), ['foo'])

Definition at line 519 of file repo_tests.py.

00519 
00520     def test_create_adds_lots_of_files(self):
00521         n = 100
00522         self.repo.lock_client('client_name')
00523         gen = self.repo.start_generation()
00524         pathnames = ['/%d' % i for i in range(n)]
00525         for pathname in pathnames:
00526             self.repo.create(pathname, obnamlib.Metadata())
00527         self.assertEqual(sorted(self.repo.listdir(gen, '/')), 
00528                          sorted(os.path.basename(x) for x in pathnames))

Definition at line 511 of file repo_tests.py.

00511 
00512     def test_create_adds_two_files(self):
00513         self.repo.lock_client('client_name')
00514         gen = self.repo.start_generation()
00515         self.repo.create('/', self.dir_meta)
00516         self.repo.create('/foo', obnamlib.Metadata())
00517         self.repo.create('/bar', obnamlib.Metadata())
00518         self.assertEqual(sorted(self.repo.listdir(gen, '/')), ['bar', 'foo'])

Definition at line 501 of file repo_tests.py.

00501 
00502     def test_create_fails_unless_generation_is_started(self):
00503         self.assertRaises(obnamlib.Error, self.repo.create, None, None)

Definition at line 572 of file repo_tests.py.

00572 
00573     def test_get_metadata_raises_exception_if_file_does_not_exist(self):
00574         self.repo.lock_client('client_name')
00575         gen = self.repo.start_generation()
00576         self.assertRaises(obnamlib.Error, self.repo.get_metadata,
00577                           gen, '/foo')
00578 

Definition at line 563 of file repo_tests.py.

00563 
00564     def test_get_metadata_works(self):
00565         metadata = obnamlib.Metadata()
00566         metadata.st_size = 123
00567         self.repo.lock_client('client_name')
00568         gen = self.repo.start_generation()
00569         self.repo.create('/foo', metadata)
00570         received = self.repo.get_metadata(gen, '/foo')
00571         self.assertEqual(metadata.st_size, received.st_size)

Definition at line 542 of file repo_tests.py.

00542 
00543     def test_gets_metadata_for_dir(self):
00544         self.repo.lock_client('client_name')
00545         gen = self.repo.start_generation()
00546         self.repo.create('/foo', self.dir_meta)
00547         self.assertEqual(self.repo.get_metadata(gen, '/foo').st_mode, 
00548                          self.dir_meta.st_mode)

Definition at line 278 of file repo_tests.py.

00278 
00279     def test_has_not_got_client_lock(self):
00280         self.assertFalse(self.repo.got_client_lock)

Definition at line 356 of file repo_tests.py.

00356 
00357     def test_listing_generations_fails_if_client_is_not_open(self):
00358         self.assertRaises(obnamlib.Error, self.repo.list_generations)

Definition at line 352 of file repo_tests.py.

00352 
00353     def test_lists_no_generations_when_locked(self):
00354         self.repo.lock_client('client_name')
00355         self.assertEqual(self.repo.list_generations(), [])
        

Definition at line 348 of file repo_tests.py.

00348 
00349     def test_lists_no_generations_when_readonly(self):
00350         self.repo.open_client('client_name')
00351         self.assertEqual(self.repo.list_generations(), [])
        

Definition at line 285 of file repo_tests.py.

00285 
00286     def test_locking_client_twice_fails(self):
00287         self.repo.lock_client('client_name')
00288         self.assertRaises(obnamlib.Error, self.repo.lock_client, 
00289                           'client_name')

Definition at line 290 of file repo_tests.py.

00290 
00291     def test_locking_nonexistent_client_fails(self):
00292         self.assertRaises(obnamlib.LockFail, self.repo.lock_client, 'foo')

Definition at line 281 of file repo_tests.py.

00281 
00282     def test_locks_client(self):
00283         self.repo.lock_client('client_name')
00284         self.assert_(self.repo.got_client_lock)

Definition at line 496 of file repo_tests.py.

00496 
00497     def test_new_generation_has_root_dir_only(self):
00498         self.repo.lock_client('client_name')
00499         gen = self.repo.start_generation()
00500         self.assertEqual(self.repo.listdir(gen, '/'), [])

Definition at line 386 of file repo_tests.py.

00386 
00387     def test_new_generation_has_start_time_only(self):
00388         self.repo.lock_client('client_name')
00389         gen = self.repo.start_generation()
00390         start, end = self.repo.get_generation_times(gen)
00391         self.assertNotEqual(start, None)
00392         self.assertEqual(end, None)

Definition at line 359 of file repo_tests.py.

00359 
00360     def test_not_making_new_generation(self):
00361         self.assertEqual(self.repo.new_generation, None)

Definition at line 343 of file repo_tests.py.

00343 
00344     def test_opens_client_even_when_locked_by_other(self):
00345         self.other.lock_client('client_name')
00346         self.repo.open_client('client_name')
00347         self.assert_(True)
        

Definition at line 340 of file repo_tests.py.

00340 
00341     def test_opens_client_fails_if_client_does_not_exist(self):
00342         self.assertRaises(obnamlib.Error, self.repo.open_client, 'bad')

Definition at line 556 of file repo_tests.py.

00556 
00557     def test_remove_removes_directory_tree(self):
00558         self.repo.lock_client('client_name')
00559         gen = self.repo.start_generation()
00560         self.repo.create('/foo/bar', obnamlib.Metadata())
00561         self.repo.remove('/foo')
00562         self.assertEqual(self.repo.listdir(gen, '/'), [])

Definition at line 549 of file repo_tests.py.

00549 
00550     def test_remove_removes_file(self):
00551         self.repo.lock_client('client_name')
00552         gen = self.repo.start_generation()
00553         self.repo.create('/foo', obnamlib.Metadata())
00554         self.repo.remove('/foo')
00555         self.assertEqual(self.repo.listdir(gen, '/'), [])

Definition at line 415 of file repo_tests.py.

00415 
00416     def test_removing_generation_works(self):
00417         self.repo.lock_client('client_name')
00418         self.repo.lock_shared()
00419         gen = self.repo.start_generation()
00420         self.repo.commit_client()
00421         self.repo.commit_shared()
00422 
00423         self.repo.open_client('client_name')
00424         self.assertEqual(len(self.repo.list_generations()), 1)
00425 
00426         self.repo.lock_client('client_name')
00427         self.repo.lock_shared()
00428         self.repo.remove_generation(gen)
00429         self.repo.commit_client()
00430         self.repo.commit_shared()
00431 
00432         self.repo.open_client('client_name')
00433         self.assertEqual(self.repo.list_generations(), [])

Definition at line 434 of file repo_tests.py.

00434 
00435     def test_removing_only_second_generation_works(self):
00436         # Create first generation. It will be empty.
00437         self.repo.lock_client('client_name')
00438         self.repo.lock_shared()
00439         gen1 = self.repo.start_generation()
00440         self.repo.commit_client()
00441         self.repo.commit_shared()
00442 
00443         # Create second generation. It will have a file with two chunks.
00444         # Only one of the chunks will be put into the shared trees.
00445         self.repo.lock_client('client_name')
00446         self.repo.lock_shared()
00447         gen2 = self.repo.start_generation()
00448         chunk_id1 = self.repo.put_chunk_only('data')
00449         self.repo.put_chunk_in_shared_trees(chunk_id1, 'checksum')
00450         chunk_id2 = self.repo.put_chunk_only('data2')
00451         self.repo.set_file_chunks('/foo', [chunk_id1, chunk_id2])
00452         self.repo.commit_client()
00453         self.repo.commit_shared()
00454 
00455         # Do we have the right generations? And the chunk2?
00456         self.repo.open_client('client_name')
00457         self.assertEqual(len(self.repo.list_generations()), 2)
00458         self.assertTrue(self.repo.chunk_exists(chunk_id1))
00459         self.assertTrue(self.repo.chunk_exists(chunk_id2))
00460 
00461         # Remove second generation. This should remove the chunk too.
00462         self.repo.lock_client('client_name')
00463         self.repo.lock_shared()
00464         self.repo.remove_generation(gen2)
00465         self.repo.commit_client()
00466         self.repo.commit_shared()
00467 
00468         # Make sure we have only the first generation, and that the
00469         # chunks are gone.
00470         self.repo.open_client('client_name')
00471         self.assertEqual(self.repo.list_generations(), [gen1])
00472         self.assertFalse(self.repo.chunk_exists(chunk_id1))
00473         self.assertFalse(self.repo.chunk_exists(chunk_id2))

Definition at line 474 of file repo_tests.py.

00474 
00475     def test_removing_started_generation_fails(self):
00476         self.repo.lock_client('client_name')
00477         gen = self.repo.start_generation()
00478         self.assertRaises(obnamlib.Error,
00479                           self.repo.remove_generation, gen)

Definition at line 480 of file repo_tests.py.

00480 
00481     def test_removing_without_committing_does_not_remove(self):
00482         self.repo.lock_client('client_name')
00483         self.repo.lock_shared()
00484         gen = self.repo.start_generation()
00485         self.repo.commit_client()
00486         self.repo.commit_shared()
00487 
00488         self.repo.lock_client('client_name')
00489         self.repo.lock_shared()
00490         self.repo.remove_generation(gen)
00491         self.repo.unlock_client()
00492         self.repo.unlock_shared()
00493 
00494         self.repo.open_client('client_name')
00495         self.assertEqual(self.repo.list_generations(), [gen])

Definition at line 377 of file repo_tests.py.

00377 
00378     def test_second_generation_has_different_id_from_first(self):
00379         self.repo.lock_client('client_name')
00380         self.repo.lock_shared()
00381         gen = self.repo.start_generation()
00382         self.repo.commit_client()
00383         self.repo.commit_shared()
00384         self.repo.lock_client('client_name')
00385         self.assertNotEqual(gen, self.repo.start_generation())

Definition at line 362 of file repo_tests.py.

00362 
00363     def test_starting_new_generation_without_lock_fails(self):
00364         self.assertRaises(obnamlib.LockFail, self.repo.start_generation)

Definition at line 365 of file repo_tests.py.

00365 
00366     def test_starting_new_generation_works(self):
00367         self.repo.lock_client('client_name')
00368         gen = self.repo.start_generation()
00369         self.assert_(self.repo.new_generation)
00370         self.assertEqual(self.repo.new_generation, gen)
00371         self.assertEqual(self.repo.list_generations(),  [gen])

Definition at line 372 of file repo_tests.py.

00372 
00373     def test_starting_second_concurrent_new_generation_fails(self):
00374         self.repo.lock_client('client_name')
00375         self.repo.start_generation()
00376         self.assertRaises(obnamlib.Error, self.repo.start_generation)

Definition at line 293 of file repo_tests.py.

00293 
00294     def test_unlock_client_releases_lock(self):
00295         self.repo.lock_client('client_name')
00296         self.repo.unlock_client()
00297         self.assertFalse(self.repo.got_client_lock)

Definition at line 336 of file repo_tests.py.

00336 
00337     def test_unlock_client_when_locked_by_other_fails(self):
00338         self.other.lock_client('client_name')
00339         self.assertRaises(obnamlib.LockFail, self.repo.unlock_client)

Definition at line 329 of file repo_tests.py.

00329 
00330     def test_unlock_client_without_lock_fails(self):
00331         self.assertRaises(obnamlib.LockFail, self.repo.unlock_client)


Member Data Documentation

Definition at line 272 of file repo_tests.py.

Definition at line 250 of file repo_tests.py.

Definition at line 263 of file repo_tests.py.

Definition at line 262 of file repo_tests.py.

Definition at line 251 of file repo_tests.py.

Definition at line 248 of file repo_tests.py.


The documentation for this class was generated from the following file: