def setUp(self): # mock seconds between batches to speed the tests up self._orig_secs = BatchingBolt.secs_between_batches BatchingBolt.secs_between_batches = 0.05 self.tup_dicts = [{ 'id': 14, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [1, 2, 3] }, { 'id': 15, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [4, 5, 6] }, { 'id': 16, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [7, 8, 9] }] tups_json = '\nend\n'.join( [json.dumps(tup_dict) for tup_dict in self.tup_dicts] + ['']) self.tups = [ Tuple(tup_dict['id'], tup_dict['comp'], tup_dict['stream'], tup_dict['task'], tup_dict['tuple']) for tup_dict in self.tup_dicts ] self.bolt = BatchingBolt(input_stream=StringIO(tups_json), output_stream=BytesIO()) self.bolt.initialize({}, {})
def setUp(self): self.ticks_between_batches = 1 self.tup_dicts = [{ 'id': 14, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [1, 2, 3] }, { 'id': 15, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [4, 5, 6] }, { 'id': None, 'comp': '__system', 'stream': '__tick', 'task': -1, 'tuple': [1] }, { 'id': 16, 'comp': 'some_spout', 'stream': 'default', 'task': 'some_bolt', 'tuple': [7, 8, 9] }, { 'id': None, 'comp': '__system', 'stream': '__tick', 'task': -1, 'tuple': [2] }] tups_json = '\nend\n'.join( [json.dumps(tup_dict) for tup_dict in self.tup_dicts] + ['']) self.tups = [ Tuple(tup_dict['id'], tup_dict['comp'], tup_dict['stream'], tup_dict['task'], tup_dict['tuple']) for tup_dict in self.tup_dicts ] self.nontick_tups = [ tup for tup in self.tups if tup.stream != '__tick' ] self.bolt = BatchingBolt(input_stream=BytesIO( tups_json.encode('utf-8')), output_stream=BytesIO()) self.bolt.initialize({}, {})
def setUp(self): # mock seconds between batches to speed the tests up self._orig_secs = BatchingBolt.secs_between_batches BatchingBolt.secs_between_batches = 0.05 self.bolt = BatchingBolt(output_stream=BytesIO()) self.bolt.initialize({}, {}) # Mock read_tuple and manually since it all needs to be mocked self.tups = [ Tuple(14, 'some_spout', 'default', 'some_bolt', [1, 2, 3]), Tuple(15, 'some_spout', 'default', 'some_bolt', [4, 5, 6]), Tuple(16, 'some_spout', 'default', 'some_bolt', [7, 8, 9]) ] self._orig_read_tuple = self.bolt.read_tuple tups_cycle = itertools.cycle(self.tups) self.bolt.read_tuple = lambda: next(tups_cycle)