def test_metadata(): c = Center('127.0.0.1') c.listen(8006) stream = yield TCPClient().connect('127.0.0.1', 8006) cc = rpc(stream) response = yield cc.register(address='alice', ncores=4) assert 'alice' in c.has_what assert c.ncores['alice'] == 4 response = yield cc.add_keys(address='alice', keys=['x', 'y']) assert response == b'OK' response = yield cc.register(address='bob', ncores=4) response = yield cc.add_keys(address='bob', keys=['y', 'z']) assert response == b'OK' response = yield cc.who_has(keys=['x', 'y']) assert response == {'x': set(['alice']), 'y': set(['alice', 'bob'])} response = yield cc.remove_keys(address='bob', keys=['y']) assert response == b'OK' response = yield cc.has_what(keys=['alice', 'bob']) assert response == {'alice': set(['x', 'y']), 'bob': set(['z'])} response = yield cc.ncores() assert response == {'alice': 4, 'bob': 4} response = yield cc.ncores(addresses=['alice', 'charlie']) assert response == {'alice': 4, 'charlie': None} response = yield cc.unregister(address='alice', close=True) assert response == b'OK' assert 'alice' not in c.has_what assert 'alice' not in c.ncores yield c.terminate()
def test_metadata(): c = Center('127.0.0.1') c.listen(8006) cc = rpc(ip='127.0.0.1', port=8006) response = yield cc.register(address=alice, ncores=4) assert alice in c.has_what assert c.ncores[alice] == 4 response = yield cc.add_keys(address=alice, keys=['x', 'y']) assert response == 'OK' response = yield cc.register(address=bob, ncores=4) response = yield cc.add_keys(address=bob, keys=['y', 'z']) assert response == 'OK' response = yield cc.who_has(keys=['x', 'y']) assert valmap(set, response) == { 'x': {alice}, 'y': {alice, bob}} response = yield cc.remove_keys(address=bob, keys=['y']) assert response == 'OK' response = yield cc.has_what(keys=[alice, bob]) assert valmap(set, response) == {alice: {'x', 'y'}, bob: {'z'}} response = yield cc.ncores() assert response == {alice: 4, bob: 4} response = yield cc.ncores(addresses=[alice, charlie]) assert response == {alice: 4, charlie: None} response = yield cc.unregister(address=alice, close=True) assert response == 'OK' assert alice not in c.has_what assert alice not in c.ncores yield c.terminate()