Example #1
0
    def setUp(self):
        from gc3libs.persistence.filesystem import FilesystemStore
        self.tmpdir = tempfile.mkdtemp()
        self.store = FilesystemStore(self.tmpdir)

        yield
        
        shutil.rmtree(self.tmpdir)
Example #2
0
    def setUp(self):
        from gc3libs.persistence.filesystem import FilesystemStore
        self.tmpdir = mkdtemp(prefix='gc3libs.', suffix='.tmp.d')
        self.store = FilesystemStore(self.tmpdir)

        yield

        shutil.rmtree(self.tmpdir)
Example #3
0
class TestFilesystemStore(GenericStoreChecks):

    @pytest.fixture(autouse=True)    
    def setUp(self):
        from gc3libs.persistence.filesystem import FilesystemStore
        self.tmpdir = tempfile.mkdtemp()
        self.store = FilesystemStore(self.tmpdir)

        yield
        
        shutil.rmtree(self.tmpdir)

    # XXX: there's nothing which is `FilesystemStore`-specific here!
    def test_filesystemstorage_pickler_class(self):
        """
        Check that `Persistable` instances are saved saparately.

        Namely, if you want to save two independent objects but one of
        them has a reference to the other, the standard behavior of
        Pickle is to save a copy of the contained object into the same
        file of the containing object.

        The FilesystemStorage.Pickler class is aimed to avoid this.
        """
        obj1 = SimplePersistableObject('parent')
        obj2 = SimplePersistableObject('children')
        obj1.children = obj2
        id2 = self.store.save(obj2)
        id1 = self.store.save(obj1)
        del obj1
        del obj2
        obj1 = self.store.load(id1)
        obj2 = self.store.load(id2)
        assert obj1.children.value == 'children'
        assert obj2.value == 'children'
        assert obj1.children == obj2

    def test_disaggregate_persistable_objects(self):
        """
        Check that `Persistable` instances are saved separately from
        their containers.

        In addition to the checks done in `GenericStoreChecks`, we
        also test that files have been created.
        """
        # std checks
        container_id, obj_id = super(
            TestFilesystemStore, self).test_disaggregate_persistable_objects()
        # check that files exist
        container_file = os.path.join(self.store._directory, str(container_id))
        assert os.path.exists(container_file)
        obj_file = os.path.join(self.store._directory, str(obj_id))
        assert os.path.exists(obj_file)
Example #4
0
def test_engine_cannot_find_task_by_id_if_no_store():
    """
    Test that `Engine.find_task_by_id` always raises `KeyError` if the Engine has no associated store.
    """
    with temporary_engine() as engine:
        with temporary_directory() as tmpdir:
            store = FilesystemStore(tmpdir)

            task = SuccessfulApp()
            engine.add(task)

            store.save(task)  # guarantee it has a `.persistent_id`
            task_id = task.persistent_id
            with pytest.raises(KeyError):
                engine.find_task_by_id(task_id)
Example #5
0
def test_engine_find_task_by_id():
    """
    Test that saved tasks are can be retrieved from the Engine given their ID only.
    """
    with temporary_core() as core:
        with temporary_directory() as tmpdir:
            store = FilesystemStore(tmpdir)
            engine = Engine(core, store=store)

            task = SuccessfulApp()
            store.save(task)
            engine.add(task)

            task_id = task.persistent_id
            assert engine.find_task_by_id(task_id) == task
Example #6
0
def test_engine_cannot_find_task_by_id_if_not_saved():
    """
    Test that *unsaved* tasks are cannot be retrieved from the Engine given their ID only.
    """
    with temporary_core() as core:
        with temporary_directory() as tmpdir:
            store = FilesystemStore(tmpdir)
            engine = Engine(core, store=store)

            task = SuccessfulApp()
            engine.add(task)

            store.save(task)  # guarantee it has a `.persistent_id`
            task_id = task.persistent_id
            with pytest.raises(KeyError):
                engine.find_task_by_id(task_id)