Пример #1
0
 def f():
     c = Center('127.0.0.1')
     c.listen(8007)
     w = Worker(c.ip, c.port, ip='127.0.0.1')
     yield w._start()
     assert isinstance(w.port, int)
     assert w.port > 1024
Пример #2
0
 def f():
     c = Center('127.0.0.1')
     c.listen(8007)
     w = Worker(c.ip, c.port, ip='127.0.0.1')
     yield w._start()
     assert isinstance(w.port, int)
     assert w.port > 1024
Пример #3
0
    def f():
        c = Center(ip='127.0.0.1')
        c.listen(0)
        x = Worker(c.ip, c.port, ip='127.0.0.1')
        y = Worker(c.ip, c.port, ip='127.0.0.1')
        z = Worker(c.ip, c.port, ip='127.0.0.1')
        x.data['a'] = 1
        y.data['a'] = 2
        yield [x._start(), y._start(), z._start()]

        zz = rpc(ip=z.ip, port=z.port)
        yield zz.compute(function=dumps(inc),
                         args=dumps(('a', )),
                         who_has={'a': [x.address]},
                         key='b')
        assert z.data['b'] == 2

        yield zz.compute(function=dumps(inc),
                         args=dumps(('a', )),
                         who_has={'a': [y.address]},
                         key='c')
        assert z.data['c'] == 3

        yield [x._close(), y._close(), z._close()]
        zz.close_streams()
Пример #4
0
    def f():
        c = Center(ip='127.0.0.1')
        c.listen(0)
        x = Worker(c.ip, c.port, ip='127.0.0.1')
        y = Worker(c.ip, c.port, ip='127.0.0.1')
        z = Worker(c.ip, c.port, ip='127.0.0.1')
        x.data['a'] = 1
        y.data['a'] = 2
        yield [x._start(), y._start(), z._start()]

        zz = rpc(ip=z.ip, port=z.port)
        yield zz.compute(function=dumps(inc),
                         args=dumps(('a',)),
                         who_has={'a': [x.address]},
                         key='b')
        assert z.data['b'] == 2

        yield zz.compute(function=dumps(inc),
                         args=dumps(('a',)),
                         who_has={'a': [y.address]},
                         key='c')
        assert z.data['c'] == 3

        yield [x._close(), y._close(), z._close()]
        zz.close_streams()
Пример #5
0
    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()
Пример #6
0
    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()
Пример #7
0
    def f():
        c = Center(ip="127.0.0.1")
        c.listen(0)
        x = Worker(c.ip, c.port, ip="127.0.0.1")
        y = Worker(c.ip, c.port, ip="127.0.0.1")
        z = Worker(c.ip, c.port, ip="127.0.0.1")
        x.data["a"] = 1
        y.data["a"] = 2
        yield [x._start(), y._start(), z._start()]

        zz = rpc(ip=z.ip, port=z.port)
        yield zz.compute(function=inc, args=("a",), needed=["a"], who_has={"a": {x.address}}, key="b")
        assert z.data["b"] == 2

        yield zz.compute(function=inc, args=("a",), needed=["a"], who_has={"a": {y.address}}, key="c")
        assert z.data["c"] == 3

        yield [x._close(), y._close(), z._close()]
        zz.close_streams()
Пример #8
0
def test_metadata(loop):
    c = Center('127.0.0.1', 8006)
    c.listen(8006)

    @gen.coroutine
    def f():
        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()

    IOLoop.current().run_sync(f)
Пример #9
0
def test_metadata():
    c = Center('127.0.0.1', 8006)
    c.listen(8006)

    @gen.coroutine
    def f():
        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.unregister(address='alice', close=True)
        assert response == b'OK'
        assert 'alice' not in c.has_what
        assert 'alice' not in c.ncores

        c.stop()

    IOLoop.current().run_sync(f)
Пример #10
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

    yield c.terminate()
Пример #11
0
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()