Example #1
0
    def test_commit_process(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)

        trxn = transaction.get()
        storage.tpc_begin(trxn)
        storage.commit(trxn)
        storage.tpc_vote(trxn)

        stagecopy = [(c, k) for c, k, d in storage.stage.itervalues()]
        temppaths = storage.tempfiles.values()

        # At this stage, the new files should be written out to the temp dir
        for temppath in temppaths:
            assert os.path.isfile(temppath)

        storage.tpc_finish(trxn)

        # Now the new files should have moved from their temp dir...
        for temppath in temppaths:
            assert not os.path.exists(temppath)

        # To their final locations
        for cls, key in stagecopy:
            assert os.path.isfile(storage._path(self.directory, cls, key))
Example #2
0
    def test_other_dm_fail(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)
        assert not storage.url(cls, key)

        # Simulate voting failure of another datamanager during commit
        transaction.get().join(AlwaysFailDataManager())
        with pytest.raises(IntentionalError):
            transaction.commit()

        # The tempfiles should have been cleaned up on failure
        assert not storage.url(cls, key)
Example #3
0
    def test_other_dm_fail(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)
        assert not storage.url(cls, key)

        # Simulate voting failure of another datamanager during commit
        transaction.get().join(AlwaysFailDataManager())
        with pytest.raises(IntentionalError):
            transaction.commit()

        # The tempfiles should have been cleaned up on failure
        assert not storage.url(cls, key)
Example #4
0
    def test_url(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)

        # URL should be available immediately
        url = storage.url(cls, key)
        assert url.startswith('file://')
        assert key in url

        transaction.commit()

        fetched = urllib2.urlopen(url, timeout=5)
        assert fetched.read() == data.read()
Example #5
0
    def test_url(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)

        # URL should not be available immediately
        assert not storage.url(cls, key)

        transaction.commit()

        # ... but must be available after commit
        url = storage.url(cls, key)
        fetched = urllib2.urlopen(url, timeout=5)
        assert fetched.read() == data.read()
Example #6
0
    def test_url(self):
        storage = self._get_storage()
        cls, key, data = storage_put(storage)

        # URL should not be available immediately
        assert not storage.url(cls, key)

        transaction.commit()

        # ... but must be available after commit
        url = storage.url(cls, key)
        fetched = urllib2.urlopen(url, timeout=5)
        assert fetched.read() == data.read()