Example #1
0
def test_transport_registry_get_event_transports(redis_default_config):
    registry = TransportRegistry().load_config(redis_default_config)

    # See comment in test_transport_registry_get_rpc_transports
    registry.set_event_transport("redis1", RedisEventTransport,
                                 RedisEventTransport.Config(batch_size=99),
                                 Config.default())
    registry.set_event_transport("redis2", RedisEventTransport,
                                 RedisEventTransport.Config(batch_size=99),
                                 Config.default())
    registry.set_event_transport("debug1", DebugEventTransport,
                                 DebugEventTransport.Config(),
                                 Config.default())
    registry.set_event_transport("debug2", DebugEventTransport,
                                 DebugEventTransport.Config(),
                                 Config.default())

    transports = registry.get_event_transports(
        ["default", "foo", "bar", "redis1", "redis2", "debug1", "debug2"])

    default_transport = registry.get_event_transport("default")
    redis_transport = registry.get_event_transport("redis1")
    debug_transport = registry.get_event_transport("debug1")

    assert set(transports[default_transport]) == {"default", "foo", "bar"}
    assert set(transports[debug_transport]) == {"debug1", "debug2"}
    assert set(transports[redis_transport]) == {"redis1", "redis2"}
Example #2
0
 async def _new_bus():
     bus = await lightbus.creation.create_async(
         config=RootConfig(
             apis={
                 'default': ApiConfig(
                     rpc_transport=RpcTransportSelector(
                         redis=RedisRpcTransport.Config(url=redis_server_url)
                     ),
                     result_transport=ResultTransportSelector(
                         redis=RedisResultTransport.Config(url=redis_server_url)
                     ),
                     event_transport=EventTransportSelector(redis=RedisEventTransport.Config(
                         url=redis_server_url,
                         stream_use=StreamUse.PER_EVENT,
                         service_name="test_service",
                         consumer_name="test_consumer",
                     )),
                 )
             },
             bus=BusConfig(
                 schema=SchemaConfig(
                     transport=SchemaTransportSelector(redis=RedisSchemaTransport.Config(url=redis_server_url)),
                 )
             )
         ),
         plugins=[],
     )
     return bus
Example #3
0
 def _new_bus(service_name="{friendly}"):
     bus = lightbus.creation.create(
         config=RootConfig(
             apis={
                 'default':
                 ApiConfig(
                     rpc_transport=RpcTransportSelector(
                         redis=RedisRpcTransport.Config(
                             url=redis_server_url)),
                     result_transport=ResultTransportSelector(
                         redis=RedisResultTransport.Config(
                             url=redis_server_url)),
                     event_transport=EventTransportSelector(
                         redis=RedisEventTransport.Config(
                             url=redis_server_url,
                             stream_use=StreamUse.PER_EVENT,
                             service_name="test_service",
                             consumer_name="test_consumer",
                         )),
                 )
             },
             bus=BusConfig(
                 schema=SchemaConfig(transport=SchemaTransportSelector(
                     redis=RedisSchemaTransport.Config(
                         url=redis_server_url)), )),
             service_name=service_name),
         plugins=[],
     )
     bus.client.disable_proxy()
     return bus
Example #4
0
async def redis_pool(redis_server_url):
    pool = TransportPool(
        transport_class=RedisEventTransport,
        transport_config=RedisEventTransport.Config(url=redis_server_url),
        config=Config.default(),
    )
    yield pool
    await pool.close()
Example #5
0
def test_not_equal(redis_pool, redis_server_url):
    """Test the __eq__ method"""
    assert redis_pool != TransportPool(
        transport_class=RedisEventTransport,
        transport_config=RedisEventTransport.Config(url=redis_server_url,
                                                    service_name="123"),
        config=Config.default(),
    )
Example #6
0
def test_get_all_transports(redis_default_config):
    registry = TransportRegistry().load_config(redis_default_config)

    # Is equal to the default transport, so will not be included
    # in the get_all_transports() return value
    registry.set_event_transport("another", RedisEventTransport,
                                 RedisEventTransport.Config(),
                                 Config.default())
    registry.set_event_transport("foo", DebugEventTransport,
                                 DebugEventTransport.Config(),
                                 Config.default())

    # redis rpc + redis result + redis event + foo debug transport (above) = 4
    assert len(registry.get_all_transports()) == 4