Example #1
0
    def test_wb_transaction_registration(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        # Watch for register-transaction calls.
        calls = []
        def register_transaction(owner):
            calls.append(owner)
        store._event.hook("register-transaction", register_transaction)

        # Simulate a disconnection, and put the connection into a
        # state where it would attempt to reconnect.
        store._connection._raw_connection = None
        store._connection._state = storm.database.STATE_RECONNECT
        self.proxy.stop()

        self.assertRaises(DisconnectionError, wrapper.cursor)
        # The connection is in the disconnected state, and has been
        # registered with any listening transaction manager.
        self.assertNotEqual(calls, [])
        self.assertEqual(
            store._connection._state, storm.database.STATE_DISCONNECTED)

        wrapper._rollback()
        del calls[:]

        # Now reconnect:
        self.proxy.start()
        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
        # The connection is up, and has been registered with any
        # listening transaction manager.
        self.assertNotEqual(calls, [])
        self.assertEqual(
            store._connection._state, storm.database.STATE_CONNECTED)
Example #2
0
    def test_register_transaction(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        # Watch for register-transaction calls.
        calls = []
        def register_transaction(owner):
            calls.append(owner)
        store._event.hook("register-transaction", register_transaction)

        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
        self.assertNotEqual(calls, [])
Example #3
0
    def test_register_transaction(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        # Watch for register-transaction calls.
        calls = []

        def register_transaction(owner):
            calls.append(owner)

        store._event.hook("register-transaction", register_transaction)

        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
        self.assertNotEqual(calls, [])
Example #4
0
    def test_wb_disconnect(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        cursor = wrapper.cursor()
        cursor.execute("SELECT 'about to reset connection'")
        wrapper._rollback()
        cursor = wrapper.cursor()
        self.proxy.restart()
        self.assertRaises(DisconnectionError, cursor.execute, "SELECT 1")
        self.assertEqual(
            store._connection._state, storm.database.STATE_DISCONNECTED)
        wrapper._rollback()

        self.assertEqual(
            store._connection._state, storm.database.STATE_RECONNECT)
        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
Example #5
0
    def test_wb_disconnect(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        cursor = wrapper.cursor()
        cursor.execute("SELECT 'about to reset connection'")
        wrapper._rollback()
        cursor = wrapper.cursor()
        self.proxy.restart()
        self.assertRaises(DisconnectionError, cursor.execute, "SELECT 1")
        self.assertEqual(store._connection._state,
                         storm.database.STATE_DISCONNECTED)
        wrapper._rollback()

        self.assertEqual(store._connection._state,
                         storm.database.STATE_RECONNECT)
        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
Example #6
0
    def test_wb_transaction_registration(self):
        wrapper = make_wrapper()
        store = global_zstorm.get("django")
        # Watch for register-transaction calls.
        calls = []

        def register_transaction(owner):
            calls.append(owner)

        store._event.hook("register-transaction", register_transaction)

        # Simulate a disconnection, and put the connection into a
        # state where it would attempt to reconnect.
        store._connection._raw_connection = None
        store._connection._state = storm.database.STATE_RECONNECT
        self.proxy.stop()

        self.assertRaises(DisconnectionError, wrapper.cursor)
        # The connection is in the disconnected state, and has been
        # registered with any listening transaction manager.
        self.assertNotEqual(calls, [])
        self.assertEqual(store._connection._state,
                         storm.database.STATE_DISCONNECTED)

        wrapper._rollback()
        del calls[:]

        # Now reconnect:
        self.proxy.start()
        cursor = wrapper.cursor()
        cursor.execute("SELECT 1")
        # The connection is up, and has been registered with any
        # listening transaction manager.
        self.assertNotEqual(calls, [])
        self.assertEqual(store._connection._state,
                         storm.database.STATE_CONNECTED)
Example #7
0
def get_store(name):
    # Make sure that stores have been configured.
    ensure_stores_configured()

    return global_zstorm.get(name)
Example #8
0
def get_admin_store(store_name):
    """ Return the Storm.Store With and admin connection"""
    uri = _format_postgres_admin_uri(store_name)
    return zstorm.get("%s_admin" % store_name, uri)
def get_admin_store(store_name):
    """ Return the Storm.Store With and admin connection"""
    uri = _format_postgres_admin_uri(store_name)
    return zstorm.get("%s_admin" % store_name, uri)
Example #10
0
def get_store(name):
    # Make sure that stores have been configured.
    ensure_stores_configured()

    return global_zstorm.get(name)