def store(request, event_loop, context, direct_resources, serializer):
    if request.param == 'sqlalchemy':
        engine = create_engine('sqlite:///:memory:',
                               connect_args={'check_same_thread': False},
                               poolclass=StaticPool)
        context.add_teardown_callback(engine.dispose)
        if not direct_resources:
            context.add_resource(engine)
            engine = 'default'

        store_ = SQLAlchemyStore(engine=engine, serializer=serializer)
    elif request.param == 'redis':
        address = (os.getenv('REDIS_HOST', 'localhost'), 6379)
        redis = event_loop.run_until_complete(
            create_reconnecting_redis(address))
        context.add_teardown_callback(redis.close)
        if not direct_resources:
            context.add_resource(redis)
            redis = 'default'

        store_ = RedisStore(client=redis, serializer=serializer)
    elif request.param == 'mongodb':
        host = os.getenv('MONGODB_HOST', 'localhost')
        client = AsyncIOMotorClient(host=host)
        context.add_teardown_callback(client.close)
        if not direct_resources:
            context.add_resource(client)
            client = 'default'

        store_ = MongoDBStore(client=client, serializer=serializer)

    event_loop.run_until_complete(store_.start(context))
    return store_
예제 #2
0
    def test_multi_exec(self):
        redis = yield from create_reconnecting_redis(
            ('localhost', self.redis_port), db=1, loop=self.loop)
        self.assertEqual(repr(redis), '<Redis <AutoConnector None>>')

        m = redis.multi_exec()
        m.echo('ECHO')
        res = yield from m.execute()
        self.assertEqual(res, [b'ECHO'])
예제 #3
0
def test_multi_exec(server, loop):
    redis = yield from create_reconnecting_redis(
        server.tcp_address, db=1, loop=loop)
    assert repr(redis) == '<Redis <AutoConnector None>>'

    m = redis.multi_exec()
    m.echo('ECHO')
    res = yield from m.execute()
    assert res == [b'ECHO']
    # FIXME: bad interface
    conn = yield from redis.connection.get_atomic_connection()
    conn.close()
    yield from conn.wait_closed()
예제 #4
0
    def test_multi_exec(self):
        redis = yield from create_reconnecting_redis(
            ('localhost', self.redis_port), db=1, loop=self.loop)
        self.assertEqual(repr(redis), '<Redis <AutoConnector None>>')

        m = redis.multi_exec()
        m.echo('ECHO')
        res = yield from m.execute()
        self.assertEqual(res, [b'ECHO'])
        # FIXME: bad interface
        conn = yield from redis.connection.get_atomic_connection()
        conn.close()
        yield from conn.wait_closed()
예제 #5
0
    def test_multi_exec(self):
        redis = yield from create_reconnecting_redis(
            ('localhost', self.redis_port), db=1, loop=self.loop)
        self.assertEqual(repr(redis), '<Redis <AutoConnector None>>')

        m = redis.multi_exec()
        m.echo('ECHO')
        res = yield from m.execute()
        self.assertEqual(res, [b'ECHO'])
        # FIXME: bad interface
        conn = yield from redis.connection.get_atomic_connection()
        conn.close()
        yield from conn.wait_closed()
예제 #6
0
def test_multi_exec(server, loop):
    redis = yield from create_reconnecting_redis(server.tcp_address,
                                                 db=1,
                                                 loop=loop)
    assert repr(redis) == '<Redis <AutoConnector None>>'

    m = redis.multi_exec()
    m.echo('ECHO')
    res = yield from m.execute()
    assert res == [b'ECHO']
    # FIXME: bad interface
    conn = yield from redis.connection.get_atomic_connection()
    conn.close()
    yield from conn.wait_closed()
예제 #7
0
    def test_recon(self):
        redis = yield from create_reconnecting_redis(
            ('localhost', self.redis_port), db=1, loop=self.loop)
        self.assertEqual(repr(redis), '<Redis <AutoConnector None>>')
        resp = yield from redis.echo('ECHO')
        self.assertEqual(resp, b'ECHO')
        self.assertEqual(repr(redis),
                         '<Redis <AutoConnector <RedisConnection [db:1]>>>')
        conn_id = id(redis._conn._conn)

        redis._conn._conn._do_close(ValueError("Emulate connection close"))

        resp = yield from redis.echo('ECHO')
        self.assertEqual(resp, b'ECHO')
        self.assertNotEqual(conn_id, id(redis._conn._conn))
예제 #8
0
def test_recon(server, loop):
    redis = yield from create_reconnecting_redis(
        server.tcp_address, db=1, loop=loop)
    assert repr(redis) == '<Redis <AutoConnector None>>'
    resp = yield from redis.echo('ECHO')
    assert resp == b'ECHO'
    assert repr(redis) == '<Redis <AutoConnector <RedisConnection [db:1]>>>'
    conn_id = id(redis._conn._conn)

    redis._conn._conn._do_close(ValueError("Emulate connection close"))

    resp = yield from redis.echo('ECHO')
    assert resp == b'ECHO'
    assert conn_id != id(redis._conn._conn)
    # FIXME: bad interface
    conn = yield from redis.connection.get_atomic_connection()
    conn.close()
    yield from conn.wait_closed()
예제 #9
0
    def test_recon(self):
        redis = yield from create_reconnecting_redis(
            ('localhost', self.redis_port), db=1, loop=self.loop)
        self.assertEqual(repr(redis), '<Redis <AutoConnector None>>')
        resp = yield from redis.echo('ECHO')
        self.assertEqual(resp, b'ECHO')
        self.assertEqual(repr(redis),
                         '<Redis <AutoConnector <RedisConnection [db:1]>>>')
        conn_id = id(redis._conn._conn)

        redis._conn._conn._do_close(ValueError("Emulate connection close"))

        resp = yield from redis.echo('ECHO')
        self.assertEqual(resp, b'ECHO')
        self.assertNotEqual(conn_id, id(redis._conn._conn))
        # FIXME: bad interface
        conn = yield from redis.connection.get_atomic_connection()
        conn.close()
        yield from conn.wait_closed()
예제 #10
0
def test_recon(server, loop):
    redis = yield from create_reconnecting_redis(server.tcp_address,
                                                 db=1,
                                                 loop=loop)
    assert repr(redis) == '<Redis <AutoConnector None>>'
    resp = yield from redis.echo('ECHO')
    assert resp == b'ECHO'
    assert repr(redis) == '<Redis <AutoConnector <RedisConnection [db:1]>>>'
    conn_id = id(redis._conn._conn)

    redis._conn._conn._do_close(ValueError("Emulate connection close"))

    resp = yield from redis.echo('ECHO')
    assert resp == b'ECHO'
    assert conn_id != id(redis._conn._conn)
    # FIXME: bad interface
    conn = yield from redis.connection.get_atomic_connection()
    conn.close()
    yield from conn.wait_closed()