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"})
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')
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")
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)
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'}, )
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'}, )
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)
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)
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)
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"}]}')
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')
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"}]}' )
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"}]}')
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"}]}' )
def test_register(): channel = TChannel() with pytest.raises(ConnectionClosedError): yield hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])