def test_target_callable_func_is_called(): inqueue = mp.Queue() outqueue = mp.Queue() node = Node(lambda x: x + 1, inqueue, outqueue) inqueue.put(0) node.run() assert outqueue.get() == 1
def create_pipeline(events_queue=None): election = Election(events_queue=events_queue) election_pipeline = Pipeline( [Node(election.check_for_quorum), Node(election.requeue_transactions)]) return election_pipeline
def create_pipeline(): testPipline = TestPipline() pipeline = Pipeline([ Pipe(maxsize=5000), Node(testPipline.filter_tx, fraction_of_cores=5), Node(testPipline.create), ]) return pipeline
def create_pipeline(timeout=5, backlog_reassign_delay=5): """Create and return the pipeline of operations to be distributed on different processes.""" stm = StaleTransactionMonitor( timeout=timeout, backlog_reassign_delay=backlog_reassign_delay) monitor_pipeline = Pipeline( [Node(stm.check_transactions), Node(stm.reassign_transactions)]) return monitor_pipeline
def create_pipeline(): """Create and return the pipeline of operations to be distributed on different processes.""" voter = Vote() return Pipeline([ Node(voter.validate_block), Node(voter.ungroup), Node(voter.validate_tx, fraction_of_cores=1), Node(voter.vote), Node(voter.write_vote) ])
def create_pipeline(): """Create and return the pipeline of operations to be distributed on different processes.""" block = Block() block_pipeline = Pipeline([ Node(block.filter_tx), Node(block.validate_tx, fraction_of_cores=1), Node(block.create, timeout=1), Node(block.write), Node(block.delete_tx), ]) return block_pipeline
def get_changefeed(): """Create and return ordered changefeed of blocks starting from last voted block""" b = Bigchain() last_block_id = b.get_last_voted_block().id feed = backend.query.get_new_blocks_feed(b.connection, last_block_id) return Node(feed.__next__, name='changefeed')
def create_pipeline(): """Create and return the pipeline of operations to be distributed on different processes.""" block_pipeline = BlockPipeline() pipeline = Pipeline([ Pipe(maxsize=1000), Node(block_pipeline.filter_tx), Node(block_pipeline.validate_tx, fraction_of_cores=1), Node(block_pipeline.create, timeout=1), Node(block_pipeline.write), Node(block_pipeline.delete_tx), ]) return pipeline
def test_target_iterator_func_is_called(): inqueue = mp.Queue() outqueue = mp.Queue() def gen(n): def _gen(): yield n yield n + 1 yield n + 2 return _gen() node = Node(gen, inqueue, outqueue) inqueue.put(10) node.run() assert outqueue.get() == 10 assert outqueue.get() == 11 assert outqueue.get() == 12
def indata_pipeline_outdata(): from multipipes import Pipeline, Pipe, Node indata = Pipe() outdata = Pipe() def divide(a, b): return a / b def inc(n): return n + 1 p = Pipeline([ Node(divide), Node(inc, fraction_of_cores=1), ]) p.setup(indata=indata, outdata=outdata) return (indata, p, outdata)
def test_step(): result = [] def append(val): result.append(val) p = Pipeline([Node(emit()), Node(lambda x: x**2), Node(append)]) p.step() assert result == [0] p.step() assert result == [0, 1] p.step() assert result == [0, 1, 4] p.step() p.step() p.step() assert result == [0, 1, 4, 9, 16, 25]
def test_stop(): inqueue = mp.Queue() outqueue = mp.Queue() def double(val): return val * 2 node = Node(double, inqueue, outqueue) node.start() with pytest.raises(queue.Empty): outqueue.get(block=False) inqueue.put(2) assert outqueue.get() == 4 node.stop() node.join() assert node.is_alive() is False
def test_stop_triggers_a_timeout(): inqueue = mp.Queue() outqueue = mp.Queue() def double(val, timeout=None): if timeout: return 'TIMEOUT' return val * 2 node = Node(double, inqueue, outqueue, timeout=1) node.start() inqueue.put(2) assert outqueue.get() == 4 node.stop() node.join() assert node.is_alive() is False assert outqueue.get() == 'TIMEOUT'