Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.clientmetadatatree_tests.ClientMetadataTreeFileOpsTests Class Reference

List of all members.

Public Member Functions

def current_time
def setUp
def tearDown
def test_has_empty_root_initially
def test_has_no_metadata_initially
def test_sets_metadata
def test_creates_file_at_root
def test_removes_file_at_root
def test_creates_directory_at_root
def test_removes_directory_at_root
def test_creates_directory_and_files_and_subdirs
def test_removes_directory_and_files_and_subdirs
def test_has_no_file_chunks_initially
def test_sets_file_chunks
def test_appends_file_chunks_to_empty_list
def test_appends_file_chunks_to_nonempty_list
def test_generation_has_no_chunk_refs_initially
def test_generation_has_no_chunk_refs_initially
def test_sets_file_chunks
def test_generation_has_no_chunk_refs_initially
def test_set_file_chunks_adds_chunk_refs
def test_set_file_chunks_removes_now_unused_chunk_refs
def test_remove_removes_chunk_refs
def test_report_chunk_not_in_use_initially
def test_report_chunk_in_use_after_it_is
def test_lists_no_chunks_in_generation_initially
def test_lists_used_chunks_in_generation
def test_lists_chunks_in_generation_only_once

Public Attributes

 now
 tempdir
 hooks
 client
 clientid
 file_metadata
 file_encoded
 dir_metadata
 dir_encoded

Detailed Description

Definition at line 267 of file clientmetadatatree_tests.py.


Member Function Documentation

Definition at line 269 of file clientmetadatatree_tests.py.

00269 
00270     def current_time(self):
00271         return time.time() if self.now is None else self.now

Definition at line 272 of file clientmetadatatree_tests.py.

00272 
00273     def setUp(self):
00274         self.now = None
00275         self.tempdir = tempfile.mkdtemp()
00276         fs = obnamlib.LocalFS(self.tempdir)
00277         self.hooks = obnamlib.HookManager()
00278         self.hooks.new('repository-toplevel-init')
00279         self.client = obnamlib.ClientMetadataTree(fs, 'clientid',
00280                                             obnamlib.DEFAULT_NODE_SIZE,
00281                                             obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00282                                             obnamlib.DEFAULT_LRU_SIZE, 
00283                                             self)
00284         # Force use of filename hash collisions.
00285         self.client.default_file_id = self.client._bad_default_file_id
00286         self.client.start_generation()
00287         self.clientid = self.client.get_generation_id(self.client.tree)
00288         self.file_metadata = obnamlib.Metadata(st_mode=stat.S_IFREG | 0666)
00289         self.file_encoded = obnamlib.encode_metadata(self.file_metadata)
00290         self.dir_metadata = obnamlib.Metadata(st_mode=stat.S_IFDIR | 0777)
00291         self.dir_encoded = obnamlib.encode_metadata(self.dir_metadata)
        

Definition at line 292 of file clientmetadatatree_tests.py.

00292 
00293     def tearDown(self):
00294         shutil.rmtree(self.tempdir)

Definition at line 377 of file clientmetadatatree_tests.py.

00377 
00378     def test_appends_file_chunks_to_empty_list(self):
00379         self.client.append_file_chunks('/foo', [1, 2, 3])
00380         self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), 
00381                          [1, 2, 3])

Definition at line 382 of file clientmetadatatree_tests.py.

00382 
00383     def test_appends_file_chunks_to_nonempty_list(self):
00384         self.client.set_file_chunks('/foo', [1, 2, 3])
00385         self.client.append_file_chunks('/foo', [4, 5, 6])
00386         self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), 
00387                          [1, 2, 3, 4, 5, 6])
                         

Definition at line 333 of file clientmetadatatree_tests.py.

00333 
00334     def test_creates_directory_and_files_and_subdirs(self):
00335         self.client.create('/foo', self.dir_encoded)
00336         self.client.create('/foo/foobar', self.file_encoded)
00337         self.client.create('/foo/bar', self.dir_encoded)
00338         self.client.create('/foo/bar/baz', self.file_encoded)
00339         self.assertEqual(self.client.listdir(self.clientid, '/'), ['foo'])
00340         self.assertEqual(sorted(self.client.listdir(self.clientid, '/foo')), 
00341                          ['bar', 'foobar'])
00342         self.assertEqual(self.client.listdir(self.clientid, '/foo/bar'), 
00343                          ['baz'])
00344         self.assertEqual(self.client.get_metadata(self.clientid, '/foo'), 
00345                          self.dir_encoded)
00346         self.assertEqual(self.client.get_metadata(self.clientid, '/foo/bar'), 
00347                          self.dir_encoded)
00348         self.assertEqual(self.client.get_metadata(self.clientid, '/foo/foobar'), 
00349                          self.file_encoded)
00350         self.assertEqual(self.client.get_metadata(self.clientid, 
00351                                                   '/foo/bar/baz'), 
00352                          self.file_encoded)

Definition at line 320 of file clientmetadatatree_tests.py.

00320 
00321     def test_creates_directory_at_root(self):
00322         self.client.create('/foo', self.dir_encoded)
00323         self.assertEqual(self.client.listdir(self.clientid, '/'), ['foo'])
00324         self.assertEqual(self.client.get_metadata(self.clientid, '/foo'), 
00325                          self.dir_encoded)

Definition at line 307 of file clientmetadatatree_tests.py.

00307 
00308     def test_creates_file_at_root(self):
00309         self.client.create('/foo', self.file_encoded)
00310         self.assertEqual(self.client.listdir(self.clientid, '/'), ['foo'])
00311         self.assertEqual(self.client.get_metadata(self.clientid, '/foo'),
00312                          self.file_encoded)

Definition at line 388 of file clientmetadatatree_tests.py.

00388 
00389     def test_generation_has_no_chunk_refs_initially(self):
00390         minkey = self.client.chunk_key(0, 0)
00391         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00392         self.assertEqual(list(self.client.tree.lookup_range(minkey, maxkey)), 
00393                          [])
                         

Here is the caller graph for this function:

Definition at line 394 of file clientmetadatatree_tests.py.

00394 
00395     def test_generation_has_no_chunk_refs_initially(self):
00396         minkey = self.client.chunk_key(0, 0)
00397         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00398         self.assertEqual(list(self.client.tree.lookup_range(minkey, maxkey)), 
00399                          [])

Here is the call graph for this function:

Definition at line 405 of file clientmetadatatree_tests.py.

00405 
00406     def test_generation_has_no_chunk_refs_initially(self):
00407         minkey = self.client.chunk_key(0, 0)
00408         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00409         self.assertEqual(list(self.client.tree.lookup_range(minkey, maxkey)), 
00410                          [])

Here is the call graph for this function:

Definition at line 295 of file clientmetadatatree_tests.py.

00295 
00296     def test_has_empty_root_initially(self):
00297         self.assertEqual(self.client.listdir(self.clientid, '/'), [])

Definition at line 369 of file clientmetadatatree_tests.py.

00369 
00370     def test_has_no_file_chunks_initially(self):
00371         self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), [])

Definition at line 298 of file clientmetadatatree_tests.py.

00298 
00299     def test_has_no_metadata_initially(self):
00300         self.assertRaises(KeyError, self.client.get_metadata, self.clientid, 
00301                           '/foo')

Definition at line 457 of file clientmetadatatree_tests.py.

00457 
00458     def test_lists_chunks_in_generation_only_once(self):
00459         gen_id = self.client.get_generation_id(self.client.tree)
00460         self.client.set_file_chunks('/foo', [0])
00461         self.client.set_file_chunks('/bar', [0])
00462         self.assertEqual(self.client.list_chunks_in_generation(gen_id), [0])
00463 

Definition at line 446 of file clientmetadatatree_tests.py.

00446 
00447     def test_lists_no_chunks_in_generation_initially(self):
00448         gen_id = self.client.get_generation_id(self.client.tree)
00449         self.assertEqual(self.client.list_chunks_in_generation(gen_id), [])

Definition at line 450 of file clientmetadatatree_tests.py.

00450 
00451     def test_lists_used_chunks_in_generation(self):
00452         gen_id = self.client.get_generation_id(self.client.tree)
00453         self.client.set_file_chunks('/foo', [0])
00454         self.client.set_file_chunks('/bar', [1])
00455         self.assertEqual(set(self.client.list_chunks_in_generation(gen_id)), 
00456                          set([0, 1]))

Definition at line 429 of file clientmetadatatree_tests.py.

00429 
00430     def test_remove_removes_chunk_refs(self):
00431         self.client.set_file_chunks('/foo', [1, 2])
00432         self.client.remove('/foo')
00433         minkey = self.client.chunk_key(0, 0)
00434         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00435         self.assertEqual(list(self.client.tree.lookup_range(minkey, maxkey)), 
00436                          [])
        

Definition at line 353 of file clientmetadatatree_tests.py.

00353 
00354     def test_removes_directory_and_files_and_subdirs(self):
00355         self.client.create('/foo', self.dir_encoded)
00356         self.client.create('/foo/foobar', self.file_encoded)
00357         self.client.create('/foo/bar', self.dir_encoded)
00358         self.client.create('/foo/bar/baz', self.file_encoded)
00359         self.client.remove('/foo')
00360         self.assertEqual(self.client.listdir(self.clientid, '/'), [])
00361         self.assertRaises(KeyError, self.client.get_metadata, 
00362                           self.clientid, '/foo')
00363         self.assertRaises(KeyError, self.client.get_metadata, 
00364                           self.clientid, '/foo/foobar')
00365         self.assertRaises(KeyError, self.client.get_metadata, 
00366                           self.clientid, '/foo/bar')
00367         self.assertRaises(KeyError, self.client.get_metadata, 
00368                           self.clientid, '/foo/bar/baz')

Definition at line 326 of file clientmetadatatree_tests.py.

00326 
00327     def test_removes_directory_at_root(self):
00328         self.client.create('/foo', self.dir_encoded)
00329         self.client.remove('/foo')
00330         self.assertEqual(self.client.listdir(self.clientid, '/'), [])
00331         self.assertRaises(KeyError, self.client.get_metadata, 
00332                           self.clientid, '/foo')

Definition at line 313 of file clientmetadatatree_tests.py.

00313 
00314     def test_removes_file_at_root(self):
00315         self.client.create('/foo', self.file_encoded)
00316         self.client.remove('/foo')
00317         self.assertEqual(self.client.listdir(self.clientid, '/'), [])
00318         self.assertRaises(KeyError, self.client.get_metadata, 
00319                           self.clientid, '/foo')

Definition at line 441 of file clientmetadatatree_tests.py.

00441 
00442     def test_report_chunk_in_use_after_it_is(self):
00443         gen_id = self.client.get_generation_id(self.client.tree)
00444         self.client.set_file_chunks('/foo', [0])
00445         self.assertTrue(self.client.chunk_in_use(gen_id, 0))

Definition at line 437 of file clientmetadatatree_tests.py.

00437 
00438     def test_report_chunk_not_in_use_initially(self):
00439         gen_id = self.client.get_generation_id(self.client.tree)
00440         self.assertFalse(self.client.chunk_in_use(gen_id, 0))
        

Definition at line 411 of file clientmetadatatree_tests.py.

00411 
00412     def test_set_file_chunks_adds_chunk_refs(self):
00413         self.client.set_file_chunks('/foo', [1, 2])
00414         file_id = self.client.get_file_id(self.client.tree, '/foo')
00415         minkey = self.client.chunk_key(0, 0)
00416         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00417         self.assertEqual(set(self.client.tree.lookup_range(minkey, maxkey)), 
00418                          set([(self.client.chunk_key(1, file_id), ''),
00419                               (self.client.chunk_key(2, file_id), '')]))

Definition at line 420 of file clientmetadatatree_tests.py.

00420 
00421     def test_set_file_chunks_removes_now_unused_chunk_refs(self):
00422         self.client.set_file_chunks('/foo', [1, 2])
00423         self.client.set_file_chunks('/foo', [1])
00424         file_id = self.client.get_file_id(self.client.tree, '/foo')
00425         minkey = self.client.chunk_key(0, 0)
00426         maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID)
00427         self.assertEqual(list(self.client.tree.lookup_range(minkey, maxkey)), 
00428                          [(self.client.chunk_key(1, file_id), '')])

Definition at line 372 of file clientmetadatatree_tests.py.

00372 
00373     def test_sets_file_chunks(self):
00374         self.client.set_file_chunks('/foo', [1, 2, 3])
00375         self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), 
00376                          [1, 2, 3])

Here is the caller graph for this function:

Definition at line 400 of file clientmetadatatree_tests.py.

00400 
00401     def test_sets_file_chunks(self):
00402         self.client.set_file_chunks('/foo', [1, 2, 3])
00403         self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), 
00404                          [1, 2, 3])
                         

Here is the call graph for this function:

Definition at line 302 of file clientmetadatatree_tests.py.

00302 
00303     def test_sets_metadata(self):
00304         self.client.set_metadata('/foo', self.file_encoded)
00305         self.assertEqual(self.client.get_metadata(self.clientid, '/foo'), 
00306                          self.file_encoded)


Member Data Documentation

Definition at line 278 of file clientmetadatatree_tests.py.

Definition at line 286 of file clientmetadatatree_tests.py.

Definition at line 290 of file clientmetadatatree_tests.py.

Definition at line 289 of file clientmetadatatree_tests.py.

Definition at line 288 of file clientmetadatatree_tests.py.

Definition at line 287 of file clientmetadatatree_tests.py.

Definition at line 276 of file clientmetadatatree_tests.py.

Definition at line 273 of file clientmetadatatree_tests.py.

Definition at line 274 of file clientmetadatatree_tests.py.


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