def test(): bolt = SplitSentenceBolt() mock_spout = mock.MockSpout(RandomSentenceSpout.declareOutputFields(), [["Madam, I'm Adam."]]) result = mock.run_simple_topology(None, [mock_spout, bolt], result_type=mock.LIST) assert_equal([['Madam,'], ["I'm"], ['Adam.']], result[bolt])
def test(): bolt = SplitSentenceBolt() mock_spout = mock.MockSpout( RandomSentenceSpout.declareOutputFields(), [["Madam, I'm Adam."]]) result = mock.run_simple_topology( None, [mock_spout, bolt], result_type=mock.LIST) assert_equal([['Madam,'], ["I'm"], ['Adam.']], result[bolt])
def test(): ss_bolt = SplitSentenceBolt() wc_bolt = WordCountBolt() mock_spout = mock.MockSpout(RandomSentenceSpout.declareOutputFields(), [["the bart the"]]) result = mock.run_simple_topology(None, [mock_spout, ss_bolt, wc_bolt], result_type=mock.LIST) assert_equal([['the', 1], ['bart', 1], ['the', 2]], result[wc_bolt])
def test(): ss_bolt = SplitSentenceBolt() wc_bolt = WordCountBolt() mock_spout = mock.MockSpout( RandomSentenceSpout.declareOutputFields(), [["the bart the"]]) result = mock.run_simple_topology( None, [mock_spout, ss_bolt, wc_bolt], result_type=mock.LIST) assert_equal([['the', 1], ['bart', 1], ['the', 2]], result[wc_bolt])
def test(): # To run this: # pip install nose # nosetests splitsentence.py from nose.tools import assert_equal bolt = SplitSentenceBolt() from petrel import mock from randomsentence import RandomSentenceSpout mock_spout = mock.MockSpout(RandomSentenceSpout.declareOutputFields(), [ ["Madam, I'm Adam."], ]) result = mock.run_simple_topology(None, [mock_spout, bolt], result_type=mock.LIST) assert_equal([['Madam,'], ["I'm"], ['Adam.']], result[bolt])
def test(): # To run this: # pip install nose # nosetests wordcount.py from nose.tools import assert_equal bolt = WordCountBolt() from petrel import mock from randomsentence import RandomSentenceSpout mock_spout = mock.MockSpout(RandomSentenceSpout.declareOutputFields(), [ ['word'], ['other'], ['word'], ]) result = mock.run_simple_topology(None, [mock_spout, bolt], result_type=mock.LIST) assert_equal(2, bolt._count['word']) assert_equal(1, bolt._count['other']) assert_equal([['word', 1], ['other', 1], ['word', 2]], result[bolt])
def create(builder): builder.setSpout("spout", RandomSentenceSpout(), 1) builder.setBolt( "split", SplitSentenceBolt(), 1).shuffleGrouping("spout") builder.setBolt( "count", WordCountBolt(), 1).fieldsGrouping("split", ["word"])