コード例 #1
0
    def testRetriesDisconnectionErrors(self):
        """
        L{Transact.run} retries the transaction if a L{DisconnectionError}
        occurs during a transaction.
        """
        class FakeTransactionManager(object):
            def commit(self):
                self.committed = True

            def abort(self):
                self.aborted = True

        self.flag = False

        def function():
            if not self.flag:
                self.flag = True
                raise DisconnectionError('Disconnected')
            return 'success'

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager)
        result = yield transact.run(function)
        self.assertEqual('success', result)
        self.assertTrue(manager.aborted)
        self.assertTrue(manager.committed)
コード例 #2
0
 def setUp(self):
     super(FacadeUserMixinTest, self).setUp()
     self.transact = Transact(self.threadPool)
     factory = FluidinfoSessionFactory('API-9000')
     self.facade = Facade(self.transact, factory)
     system = createSystemData()
     self.admin = system.users[u'fluiddb']
コード例 #3
0
ファイル: test_checkers.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(FacadeCheckerTest, self).setUp()
     factory = FluidinfoSessionFactory('API-9000')
     transact = Transact(self.threadPool)
     createSystemData()
     self.checker = FacadeChecker()
     self.checker.facadeClient = Facade(transact, factory)
コード例 #4
0
    def testRetryWriteWarningInLog(self):
        """
        L{Transact.run} writes a warning in the logs if a retry is done.
        """
        class FakeTransactionManager(object):
            def commit(self):
                self.committed = True

            def abort(self):
                self.aborted = True

        self.flag = False

        def function():
            if not self.flag:
                self.flag = True
                raise psycopg2.Error('Error')
            return 'success'

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager, lambda seconds: None)
        result = yield transact.run(function)
        self.assertEqual('success', result)
        self.assertTrue(manager.aborted)
        self.assertTrue(manager.committed)
        self.assertIn('Retrying a transaction', self.log.getvalue())
コード例 #5
0
 def testWBDefaultTransactionManager(self):
     """
     By default L{Transact} uses the C{transaction} package as the default
     transaction manager.
     """
     transact = Transact(FakeThreadPool())
     self.assertIdentical(transaction, transact._transaction)
コード例 #6
0
    def testRetries(self):
        """
        L{Transact.run} retries the transaction if a DB error occours during
        a transaction collision.
        """
        class FakeTransactionManager(object):
            def commit(self):
                self.committed = True

            def abort(self):
                self.aborted = True

        self.flag = False

        def function():
            if not self.flag:
                self.flag = True
                raise psycopg2.Error('Error')
            return 'success'

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager, lambda seconds: None)
        result = yield transact.run(function)
        self.assertEqual('success', result)
        self.assertTrue(manager.aborted)
        self.assertTrue(manager.committed)
コード例 #7
0
ファイル: test_root.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(RootResourceTest, self).setUp()
     factory = FluidinfoSessionFactory('API-9000')
     transact = Transact(self.threadPool)
     createSystemData()
     self.checker = AnonymousChecker()
     self.checker.facadeClient = Facade(transact, factory)
     getConfig().set('service', 'allow-anonymous-access', 'False')
コード例 #8
0
 def setUp(self):
     super(OAuthEchoResourceTest, self).setUp()
     self.agent = Agent(self.FakeReactor())
     self.transact = Transact(self.threadPool)
     system = createSystemData()
     self.anonymous = system.users[u'anon']
     OAuthConsumerAPI().register(self.anonymous)
     self.agent = Agent(self.FakeReactor())
コード例 #9
0
ファイル: test_recent.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(RecentObjectsActivityResourceTest, self).setUp()
     createSystemData()
     UserAPI().create([(u'username', u'password', u'User',
                        u'*****@*****.**')])
     self.user = getUser(u'username')
     factory = FluidinfoSessionFactory('API-9000')
     self.transact = Transact(self.threadPool)
     self.facade = Facade(self.transact, factory)
コード例 #10
0
 def setUp(self):
     super(FacadeTagMixinTest, self).setUp()
     createSystemData()
     self.transact = Transact(self.threadPool)
     factory = FluidinfoSessionFactory('API-9000')
     self.facade = Facade(self.transact, factory)
     UserAPI().create([(u'username', u'password', u'User',
                        u'*****@*****.**')])
     self.user = getUser(u'username')
     self.permissions = CachingPermissionAPI(self.user)
コード例 #11
0
ファイル: test_users.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(VerifyUserPasswordResourceTest, self).setUp()
     self.transact = Transact(self.threadPool)
     createSystemData()
     UserAPI().create([
         (u'fluidinfo.com', 'secret', u'Fluidinfo', u'*****@*****.**'),
         (u'user', u'pass', u'Peter Parker', u'*****@*****.**')])
     consumer = getUser(u'anon')
     OAuthConsumerAPI().register(consumer)
     self.store.commit()
コード例 #12
0
ファイル: test_permission.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(FacadePermissionTest, self).setUp()
     self.transact = Transact(FakeThreadPool())
     factory = FluidinfoSessionFactory('API-9000')
     self.facade = Facade(self.transact, factory)
     createSystemData()
     UserAPI().create([(u'username', u'password', u'User',
                        u'*****@*****.**')])
     user = getUser(u'username')
     self.permissions = CachingPermissionAPI(user)
     SecureTagAPI(user).create([(u'username/tag', u'description')])
コード例 #13
0
ファイル: application.py プロジェクト: xanixon/fluiddb
def setupFacade(config):
    """Get the L{Facade} instance to use in the API service."""
    from fluiddb.api.facade import Facade
    from fluiddb.util.transact import Transact

    maxThreads = int(config.get('service', 'max-threads'))
    threadpool = ThreadPool(minthreads=0, maxthreads=maxThreads)
    reactor.callWhenRunning(threadpool.start)
    reactor.addSystemEventTrigger('during', 'shutdown', threadpool.stop)
    transact = Transact(threadpool)
    factory = FluidinfoSessionFactory('API-%s' % config.get('service', 'port'))
    return Facade(transact, factory)
コード例 #14
0
    def testRunWithFunctionFailure(self):
        """
        If the given function raises an error, then L{Transact.run} aborts the
        transaction and re-raises the same error.
        """
        class FakeTransactionManager(object):
            def abort(self):
                self.aborted = True

        def function():
            raise RuntimeError('Function call exploded!')

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager)
        yield self.assertFailure(transact.run(function), RuntimeError)
        self.assertTrue(manager.aborted)
コード例 #15
0
    def testRun(self):
        """
        L{Transact.run} executes a function in a thread, commits the
        transaction and returns a C{Deferred} that fires with the function's
        result.
        """
        class FakeTransactionManager(object):
            def commit(self):
                self.committed = True

        def function(a, b=None):
            return a + b

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager)
        result = yield transact.run(function, 1, b=2)
        self.assertEqual(3, result)
        self.assertTrue(manager.committed)
コード例 #16
0
    def testRunWithCommitFailure(self):
        """
        If the specified function succeeds but the transaction fails to
        commit, then L{Transact.run} aborts the transaction and re-raises the
        commit exception.
        """
        class FakeTransactionManager(object):
            def abort(self):
                self.aborted = True

            def commit(self):
                raise RuntimeError('Commit exploded!')

        def function():
            pass

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager)
        yield self.assertFailure(transact.run(function), RuntimeError)
        self.assertTrue(manager.aborted)
コード例 #17
0
    def testReturnStormObject(self):
        """
        A C{RuntimeError} is raised if a Storm object is returned from the
        transaction.  Storm objects may only be used in the thread they were
        created in, so this provides some safety checking to prevent strange
        behaviour.
        """
        class FakeTransactionManager(object):
            def abort(self):
                self.aborted = True

        class StormObject(object):

            __storm_table__ = 'storm_object'

        def function():
            return StormObject()

        manager = FakeTransactionManager()
        transact = Transact(FakeThreadPool(), manager)
        yield self.assertFailure(transact.run(function), RuntimeError)
        self.assertTrue(manager.aborted)
コード例 #18
0
ファイル: test_session.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(TransactPluginTest, self).setUp()
     self.transact = Transact(self.threadPool, sleep=lambda seconds: None)
コード例 #19
0
 def setUp(self):
     super(FacadeUserCreationTest, self).setUp()
     factory = FluidinfoSessionFactory('API-9000')
     self.transact = Transact(self.threadPool)
     self.facade = Facade(self.transact, factory)
     self.system = createSystemData()
コード例 #20
0
ファイル: test_session.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(LoggingPluginTest, self).setUp()
     self.transact = Transact(self.threadPool)
コード例 #21
0
 def setUp(self):
     super(RenewOAuthTokenResourceTest, self).setUp()
     self.transact = Transact(self.threadPool)
     createSystemData()
コード例 #22
0
 def setUp(self):
     super(DelegatorTest, self).setUp()
     self.agent = Agent(self.FakeReactor())
     self.transact = Transact(self.threadPool)
     createSystemData()
コード例 #23
0
ファイル: test_application.py プロジェクト: xanixon/fluiddb
 def setUp(self):
     super(FluidinfoSessionFactoryTest, self).setUp()
     self.transact = Transact(self.threadPool)
コード例 #24
0
 def setUp(self):
     super(FacadeAuthenticateUserWithPasswordTest, self).setUp()
     factory = FluidinfoSessionFactory('API-9000')
     self.transact = Transact(self.threadPool)
     self.facade = Facade(self.transact, factory)
     self.system = createSystemData()