Пример #1
0
def test_request():
    channel = TChannel(name="test")
    hyperbahn.advertise(channel, "foo", ["127.0.0.1:23000"])

    # Just want to make sure all the plumbing fits together.

    with pytest.raises(NoAvailablePeerError):
        yield channel.request(service="bar").send(arg1="baz", arg2="bam", arg3="boo", headers={"as": "qux"})
Пример #2
0
def test_advertise_should_raise_on_invalid_router_file():

    channel = TChannel(name='client')
    with pytest.raises(IOError):
        yield hyperbahn.advertise(channel, 'baz', None, None, '?~~lala')

    with pytest.raises(ValueError):
        yield hyperbahn.advertise(channel, 'baz', '?~~lala', None, '?~~lala')
Пример #3
0
def test_advertise_should_raise_on_invalid_router_file():

    channel = TChannel(name="client")
    with pytest.raises(IOError):
        yield hyperbahn.advertise(channel, "baz", None, None, "?~~lala")

    with pytest.raises(ValueError):
        yield hyperbahn.advertise(channel, "baz", "?~~lala", None, "?~~lala")
Пример #4
0
def test_new_client_establishes_peers():
    routers = ["127.0.0.1:2300" + str(i) for i in xrange(5)]

    # TChannel knows about one of the peers already.
    channel = TChannel("test", known_peers=["127.0.0.1:23002"])

    hyperbahn.advertise(channel, "baz", routers)

    for router in routers:
        assert channel.peers.lookup(router)
Пример #5
0
def test_request():
    channel = TChannel()
    hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])

    # Just want to make sure all the plumbing fits together.
    with pytest.raises(ConnectionClosedError):
        yield channel.request(service='bar').send(
            arg1='baz',
            arg2='bam',
            arg3='boo',
            headers={'as': 'qux'},
        )
Пример #6
0
def test_request():
    channel = TChannel(name='test')
    hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])

    # Just want to make sure all the plumbing fits together.

    with pytest.raises(ConnectionClosedError):
        yield channel.request(service='bar').send(
            arg1='baz',
            arg2='bam',
            arg3='boo',
            headers={'as': 'qux'},
        )
Пример #7
0
def test_new_client_establishes_peers_from_file():

    host_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../data/hosts.json")

    # TChannel knows about one of the peers already.
    channel = TChannel("test", known_peers=["127.0.0.1:23002"])

    hyperbahn.advertise(channel, "baz", None, None, host_path)

    with open(host_path, "r") as json_data:
        routers = json.load(json_data)
    for router in routers:
        assert channel.peers.lookup(router)
Пример #8
0
def test_new_client_establishes_peers():
    routers = ['127.0.0.1:2300' + str(i) for i in xrange(5)]

    # TChannel knows about one of the peers already.
    channel = TChannel('test', known_peers=['127.0.0.1:23002'])

    hyperbahn.advertise(
        channel,
        'baz',
        routers,
    )

    for router in routers:
        assert channel.peers.lookup(router)
Пример #9
0
def test_new_client_establishes_peers_from_file():

    host_path = os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        '../data/hosts.json',
    )

    # TChannel knows about one of the peers already.
    channel = TChannel('test', known_peers=['127.0.0.1:23002'])

    hyperbahn.advertise(channel, 'baz', None, None, host_path)

    with open(host_path, 'r') as json_data:
        routers = json.load(json_data)
    for router in routers:
        assert channel.peers.lookup(router)
Пример #10
0
def test_advertise(echobahn):
    channel = TChannel(name='test')

    response = yield hyperbahn.advertise(channel, 'test', [echobahn.hostport])
    result = yield response.get_body()
    assert (result == '{"services": [{"serviceName": "test", "cost": 0}]}'
            or result == '{"services": [{"cost": 0, "serviceName": "test"}]}')
Пример #11
0
def test_advertise_should_raise_on_invalid_router_file():

    channel = TChannel(name='client')
    with pytest.raises(IOError):
        yield hyperbahn.advertise(
            channel,
            'baz',
            None,
            None,
            '?~~lala')

    with pytest.raises(ValueError):
        yield hyperbahn.advertise(
            channel,
            'baz',
            '?~~lala',
            None,
            '?~~lala')
Пример #12
0
def test_advertise(echobahn):
    channel = TChannel(name='test')

    response = yield hyperbahn.advertise(channel, 'test', [echobahn.hostport])
    result = yield response.get_body()
    assert (
        result == '{"services": [{"serviceName": "test", "cost": 0}]}' or
        result == '{"services": [{"cost": 0, "serviceName": "test"}]}'
    )
Пример #13
0
def test_advertise():
    server = TChannel(name="test_server")

    @server.register('ad', 'json')
    @tornado.gen.coroutine
    def ad(request, response):
        body = yield request.get_body()
        response.write_body(body)

    server.listen()
    channel = TChannel(name='test')

    response = yield hyperbahn.advertise(channel, 'test', [server.hostport])
    result = yield response.get_body()
    assert (result == '{"services": [{"serviceName": "test", "cost": 0}]}'
            or result == '{"services": [{"cost": 0, "serviceName": "test"}]}')
Пример #14
0
def test_advertise():
    server = TChannel(name="test_server")

    @server.register("ad", "json")
    @tornado.gen.coroutine
    def ad(request, response):
        body = yield request.get_body()
        response.write_body(body)

    server.listen()
    channel = TChannel(name="test")

    response = yield hyperbahn.advertise(channel, "test", [server.hostport])
    result = yield response.get_body()
    assert (
        result == '{"services": [{"serviceName": "test", "cost": 0}]}'
        or result == '{"services": [{"cost": 0, "serviceName": "test"}]}'
    )
Пример #15
0
def test_register():
    channel = TChannel()

    with pytest.raises(ConnectionClosedError):
        yield hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])