def test_scatter_delete(): c = Center('127.0.0.1', 8017, loop=loop) a = Worker('127.0.0.1', 8018, c.ip, c.port, loop=loop, ncores=1) b = Worker('127.0.0.1', 8019, c.ip, c.port, loop=loop, ncores=1) @asyncio.coroutine def f(): while len(c.ncores) < 2: yield from asyncio.sleep(0.01, loop=loop) data = yield from scatter_to_center(c.ip, c.port, [1, 2, 3], loop=loop) assert merge(a.data, b.data) == \ {d.key: i for d, i in zip(data, [1, 2, 3])} assert set(c.who_has) == {d.key for d in data} assert all(len(v) == 1 for v in c.who_has.values()) assert [d.get() for d in data] == [1, 2, 3] yield from data[0]._delete() assert merge(a.data, b.data) == \ {d.key: i for d, i in zip(data[1:], [2, 3])} assert data[0].key not in c.who_has data = yield from scatter_to_workers(c.ip, c.port, [a.address, b.address], [4, 5, 6], loop=loop) m = merge(a.data, b.data) for d, v in zip(data, [4, 5, 6]): assert m[d.key] == v yield from a._close() yield from b._close() yield from c._close() loop.run_until_complete(asyncio.gather(c.go(), a.go(), b.go(), f()))
def test_delete_data(): from distributed import Worker c = Center('127.0.0.1', 8037, loop=loop) a = Worker('127.0.0.1', 8038, c.ip, c.port, loop=loop) @asyncio.coroutine def f(): while len(c.ncores) < 1: yield from asyncio.sleep(0.01, loop=loop) yield from rpc(a.ip, a.port).update_data(data={'x': 1, 'y': 2}) assert a.data == {'x': 1, 'y': 2} yield from rpc(c.ip, c.port).add_keys(address=(a.ip, a.port), keys=['x', 'y']) yield from rpc(c.ip, c.port).delete_data(keys=['x']) assert a.data == {'y': 2} assert not c.who_has['x'] assert list(c.has_what[(a.ip, a.port)]) == ['y'] yield from a._close() yield from c._close() loop.run_until_complete(asyncio.gather(c.go(), a.go(), f()))