def g():
        c = Center('127.0.0.1', 8017)
        c.listen(c.port)
        a = Worker('127.0.0.1', 8018, c.ip, c.port, ncores=1)
        yield a._start()
        b = Worker('127.0.0.1', 8019, c.ip, c.port, ncores=1)
        yield b._start()

        while len(c.ncores) < 2:
            yield gen.sleep(0.01)

        try:
            yield f(c, a, b)
        finally:
            with ignoring(Exception):
                yield a._close()
            with ignoring(Exception):
                yield b._close()
            c.stop()
    def g():
        c = Center('127.0.0.1', 8017)
        c.listen(c.port)
        a = Worker('127.0.0.1', 8018, c.ip, c.port, ncores=1)
        yield a._start()
        b = Worker('127.0.0.1', 8019, c.ip, c.port, ncores=1)
        yield b._start()

        while len(c.ncores) < 2:
            yield gen.sleep(0.01)

        try:
            yield f(c, a, b)
        finally:
            with ignoring(Exception):
                yield a._close()
            with ignoring(Exception):
                yield b._close()
            c.stop()
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

    c.stop()
Exemple #4
0
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

    c.stop()