예제 #1
0
def transaction_transport(aiopg_connection, aiopg_cursor, loop):
    transport = TransactionalEventTransport(DebugEventTransport())
    block(transport.set_connection(aiopg_connection, aiopg_cursor),
          loop=loop,
          timeout=1)
    block(transport.database.migrate(), loop=loop, timeout=1)
    return transport
예제 #2
0
def atomic_context(dummy_bus: BusPath, aiopg_connection):
    registry = dummy_bus.client.transport_registry
    current_event_transport = registry.get_event_transport("default")
    registry.set_event_transport(
        "default", TransactionalEventTransport(child_transport=current_event_transport)
    )
    return lightbus_set_database(dummy_bus, aiopg_connection, apis=["some_api", "some_api2"])
예제 #3
0
def test_init_multiple_transports(dummy_bus: BusPath, aiopg_connection):
    registry = dummy_bus.client.transport_registry
    registry.set_event_transport(
        "another_api", TransactionalEventTransport(DebugEventTransport()))

    with pytest.raises(ApisMustUseSameTransport):
        lightbus_set_database(dummy_bus,
                              aiopg_connection,
                              apis=["some_api", "another_api"])
예제 #4
0
def test_from_config():
    transport = TransactionalEventTransport.from_config(
        config=Config.load_dict({}),
        child_transport={"redis": {
            "url": "redis://foo/1"
        }},
        database_class="lightbus.transports.transactional.DbApiConnection",
    )
    assert isinstance(transport.child_transport, RedisEventTransport)
    assert transport.child_transport.connection_parameters[
        "address"] == "redis://foo/1"
예제 #5
0
 async def inner():
     transport = TransactionalEventTransport(
         child_transport=lightbus.RedisEventTransport(
             redis_pool=pool,
             consumer_group_prefix="test_cg",
             consumer_name="test_consumer",
             stream_use=StreamUse.PER_EVENT,
         )
     )
     config = dummy_bus.client.config
     transport_registry = TransportRegistry().load_config(config)
     transport_registry.set_event_transport("default", transport)
     client = lightbus.BusClient(config=config, transport_registry=transport_registry)
     bus = lightbus.path.BusPath(name="", parent=None, client=client)
     return bus
예제 #6
0
def transactional_bus(dummy_bus: BusPath, new_redis_pool, aiopg_connection,
                      aiopg_cursor, loop):
    transport = TransactionalEventTransport(
        child_transport=lightbus.RedisEventTransport(
            redis_pool=new_redis_pool(maxsize=10000),
            consumer_group_prefix="test_cg",
            consumer_name="test_consumer",
            stream_use=StreamUse.PER_EVENT,
        ))
    registry = dummy_bus.client.transport_registry
    registry.set_event_transport("default", transport)

    database = DbApiConnection(aiopg_connection, aiopg_cursor)
    # Don't migrate here, that should be handled by the auto-migration

    return dummy_bus
예제 #7
0
    async def make_it(event_messages):
        async def dummy_consume_method(*args, **kwargs):
            for event_message in event_messages:
                yield event_message
                yield True

        transport = TransactionalEventTransport(DebugEventTransport())
        # start_transaction=False, as we start a transaction below (using BEGIN)
        await transport.set_connection(aiopg_connection, aiopg_cursor)
        await aiopg_cursor.execute(
            "BEGIN -- transaction_transport_with_consumer")
        await transport.database.migrate()
        # Commit the migrations
        await aiopg_cursor.execute(
            "COMMIT -- transaction_transport_with_consumer")
        transport.child_transport.consume = dummy_consume_method
        return transport
예제 #8
0
async def test_set_connection_already_set(aiopg_connection, aiopg_cursor):
    transport = TransactionalEventTransport(DebugEventTransport())
    await transport.set_connection(aiopg_connection, aiopg_cursor)
    with pytest.raises(ConnectionAlreadySet):
        await transport.set_connection(aiopg_connection, aiopg_cursor)
예제 #9
0
async def test_set_connection_ok(aiopg_connection, aiopg_cursor):
    transport = TransactionalEventTransport(DebugEventTransport())
    await transport.set_connection(aiopg_connection, aiopg_cursor)
    assert transport.connection == aiopg_connection
    assert transport.cursor == aiopg_cursor
    assert await active_transactions() == 0
예제 #10
0
async def transaction_transport(aiopg_connection, aiopg_cursor, loop):
    transport = TransactionalEventTransport(DebugEventTransport())
    await transport.set_connection(aiopg_connection, aiopg_cursor)
    await transport.database.migrate()
    return transport
예제 #11
0
async def test_commit_and_finish_no_database():
    transport = TransactionalEventTransport(DebugEventTransport())
    with pytest.raises(DatabaseNotSet):
        await transport.commit_and_finish()