Example #1
0
    def test_stores_blob_persistently(self):
        bag_store = DummyBagStore()
        blob = 'this is a blob, yes it is'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_id = blob_store.put_blob(blob)
        blob_store.flush()

        blob_store_2 = obnamlib.BlobStore()
        blob_store_2.set_bag_store(bag_store)
        retrieved = blob_store_2.get_blob(blob_id)
        self.assertEqual(blob, retrieved)
Example #2
0
    def _load_data(self):
        if not self._data_is_loaded:
            bag_store = obnamlib.BagStore()
            bag_store.set_location(self._fs, self.get_dirname())

            blob_store = obnamlib.BlobStore()
            blob_store.set_bag_store(bag_store)
            blob = blob_store.get_well_known_blob(self._well_known_blob)

            leaf_store = obnamlib.LeafStore()
            leaf_store.set_blob_store(blob_store)

            if blob is None:
                self._by_chunk_id_tree = self._empty_cowtree(leaf_store)
                self._by_checksum_tree = self._empty_cowtree(leaf_store)
                self._used_by_tree = self._empty_cowtree(leaf_store)
            else:
                data = obnamlib.deserialise_object(blob)
                self._checksum_name = data['checksum_algorithm']

                self._by_chunk_id_tree = self._load_cowtree(
                    leaf_store, data['by_chunk_id'])
                self._by_checksum_tree = self._load_cowtree(
                    leaf_store, data['by_checksum'])
                self._used_by_tree = self._load_cowtree(
                    leaf_store, data['used_by'])

            self._data_is_loaded = True
Example #3
0
    def test_returns_None_for_missing_blob(self):
        bag_store = DummyBagStore()

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_id = obnamlib.make_object_id(123, 456)
        self.assertEqual(blob_store.get_blob(blob_id), None)
Example #4
0
    def test_returns_None_if_well_known_blog_does_not_exist(self):
        bag_store = DummyBagStore()
        well_known_id = 'bobby'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        retrieved = blob_store.get_well_known_blob(well_known_id)
        self.assertEqual(retrieved, None)
Example #5
0
    def test_returns_existing_blob(self):
        bag_store = DummyBagStore()
        blob = 'blobby blob blob blob'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_id = blob_store.put_blob(blob)
        retrieved = blob_store.get_blob(blob_id)
        self.assertEqual(blob, retrieved)
Example #6
0
    def _save_data(self):
        assert self._data is not None
        blob = obnamlib.serialise_object(self._data)

        bag_store = obnamlib.BagStore()
        bag_store.set_location(self._fs, self.get_dirname())

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_store.put_well_known_blob(self._well_known_blob, blob)
Example #7
0
    def set_fs(self, fs):
        self._fs = fs

        self._bag_store = obnamlib.BagStore()
        self._bag_store.set_location(fs, self._dirname)
        self._blob_store = obnamlib.BlobStore()
        self._blob_store.set_bag_store(self._bag_store)
        self._blob_store.set_max_cache_bytes(self._chunk_cache_size)
        if self._max_chunk_size is not None:
            self._blob_store.set_max_bag_size(self._max_chunk_size)
Example #8
0
    def _get_blob_store(self):
        if self._blob_store is None:
            bag_store = obnamlib.BagStore()
            bag_store.set_location(self._fs, self._dirname)

            self._blob_store = obnamlib.BlobStore()
            self._blob_store.set_bag_store(bag_store)
            self._blob_store.set_max_bag_size(self._dir_bag_size)
            self._blob_store.set_max_cache_bytes(self._dir_cache_size)
        return self._blob_store
Example #9
0
    def test_finds_unflushed_blob(self):
        bag_store = DummyBagStore()
        blob = 'this is a blob, yes it is'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_store.set_max_bag_size(len(blob) + 1)
        blob_id = blob_store.put_blob(blob)
        self.assertTrue(bag_store.is_empty())

        retrieved = blob_store.get_blob(blob_id)
        self.assertEqual(blob, retrieved)
Example #10
0
    def test_obeys_max_bag_size(self):
        bag_store = DummyBagStore()
        blob = 'this is a blob, yes it is'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)

        blob_store.set_max_bag_size(len(blob) + 1)
        blob_store.put_blob(blob)
        self.assertTrue(bag_store.is_empty())

        blob_store.set_max_bag_size(1)
        blob_store.put_blob(blob)
        self.assertFalse(bag_store.is_empty())
Example #11
0
    def test_puts_well_known_blob(self):
        bag_store = DummyBagStore()
        well_known_blob = 'Bob'
        well_known_id = 'bobby'

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_store.set_max_bag_size(len(well_known_blob) + 1)
        returned_id = blob_store.put_well_known_blob(
            well_known_id, well_known_blob)
        self.assertEqual(returned_id, None)

        retrieved = blob_store.get_well_known_blob(well_known_id)
        self.assertEqual(well_known_blob, retrieved)
Example #12
0
    def _save_data(self):
        root = {
            'checksum_algorithm': self._checksum_name,
            'by_chunk_id': self._by_chunk_id_tree.commit(),
            'by_checksum': self._by_checksum_tree.commit(),
            'used_by': self._used_by_tree.commit(),
        }

        blob = obnamlib.serialise_object(root)

        bag_store = obnamlib.BagStore()
        bag_store.set_location(self._fs, self.get_dirname())

        blob_store = obnamlib.BlobStore()
        blob_store.set_bag_store(bag_store)
        blob_store.put_well_known_blob(self._well_known_blob, blob)
Example #13
0
    def _load_data(self):
        if self._data_is_loaded:
            assert self._data is not None
        else:
            assert self._data is None

        if not self._data_is_loaded:
            bag_store = obnamlib.BagStore()
            bag_store.set_location(self._fs, self.get_dirname())

            blob_store = obnamlib.BlobStore()
            blob_store.set_bag_store(bag_store)
            blob = blob_store.get_well_known_blob(self._well_known_blob)

            if blob is None:
                self._data = {
                    'clients': {},
                }
            else:
                self._data = obnamlib.deserialise_object(blob)
                assert self._data is not None

            self._data_is_loaded = True
Example #14
0
    def setUp(self):
        self.blob_store = obnamlib.BlobStore()
        self.blob_store.set_bag_store(DummyBagStore())

        self.tree = obnamlib.GATree()
        self.tree.set_blob_store(self.blob_store)