コード例 #1
0
    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({}, {})
コード例 #2
0
ファイル: test_component.py プロジェクト: keipher/streamparse
    def test_read_tuple(self):
        # This is only valid for bolts, so we only need to test with task IDs
        # and Tuples
        inputs = [  # Tuple with all values
            ('{ "id": "-6955786537413359385", "comp": "1", "stream": "1"'
             ', "task": 9, "tuple": ["snow white and the seven dwarfs", '
             '"field2", 3]}\n'),
            'end\n',
            # Tick Tuple
            ('{ "id": null, "task": -1, "comp": "__system", "stream": '
             '"__tick", "tuple": [50]}\n'),
            'end\n',
            # Heartbeat Tuple
            ('{ "id": null, "task": -1, "comp": "__system", "stream": '
             '"__heartbeat", "tuple": []}\n'),
            'end\n',
        ]
        outputs = []
        for msg in inputs[::2]:
            output = json.loads(msg)
            output['component'] = output['comp']
            output['values'] = output['tuple']
            del output['comp']
            del output['tuple']
            outputs.append(Tuple(**output))

        component = Component(input_stream=BytesIO(
            ''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())

        for output in outputs:
            log.info('Checking Tuple for %s', output)
            tup = component.read_tuple()
            self.assertEqual(output, tup)
コード例 #3
0
 def test_heartbeat_response(self, send_message_mock, read_tuple_mock):
     # Make sure we send sync for heartbeats
     read_tuple_mock.return_value = Tuple(id='foo', task=-1,
                                          stream='__heartbeat', values=[],
                                          component='__system')
     self.bolt._run()
     send_message_mock.assert_called_with(self.bolt, {'command': 'sync'})
コード例 #4
0
    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)
コード例 #5
0
 def test_process_tick(self, process_tick_mock, read_tuple_mock):
     # Make sure we send sync for heartbeats
     read_tuple_mock.return_value = Tuple(id=None, task=-1,
                                          component='__system',
                                          stream='__tick', values=[50])
     self.bolt._run()
     process_tick_mock.assert_called_with(self.bolt,
                                          read_tuple_mock.return_value)
コード例 #6
0
 def setUp(self):
     self.tup_dict = {'id': 14,
                      'comp': 'some_spout',
                      'stream': 'default',
                      'task': 'some_spout',
                      'tuple': [1, 2, 3]}
     self.tup = Tuple(self.tup_dict['id'], self.tup_dict['comp'],
                      self.tup_dict['stream'], self.tup_dict['task'],
                      self.tup_dict['tuple'],)
     self.spout = Spout(input_stream=BytesIO(),
                        output_stream=BytesIO())
     self.spout.initialize({}, {})
     self.spout.logger = log
コード例 #7
0
 def setUp(self):
     self.tup_dict = {'id': 14,
                      'comp': 'some_spout',
                      'stream': 'default',
                      'task': 'some_bolt',
                      'tuple': [1, 2, 3]}
     tup_json = "{}\nend\n".format(json.dumps(self.tup_dict)).encode('utf-8')
     self.tup = Tuple(self.tup_dict['id'], self.tup_dict['comp'],
                      self.tup_dict['stream'], self.tup_dict['task'],
                      self.tup_dict['tuple'],)
     self.bolt = Bolt(input_stream=BytesIO(tup_json),
                      output_stream=BytesIO())
     self.bolt.initialize({}, {})
コード例 #8
0
 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({}, {})
コード例 #9
0
 def setUp(self):
     self.tup_dict = {
         'id': 14,
         'comp': 'some_spout',
         'stream': 'default',
         'task': 'some_bolt',
         'tuple': [1, 2, 3]
     }
     tup_json = "{}\nend\n".format(json.dumps(self.tup_dict))
     self.tup = Tuple(
         self.tup_dict['id'],
         self.tup_dict['comp'],
         self.tup_dict['stream'],
         self.tup_dict['task'],
         self.tup_dict['tuple'],
     )
     self.bolt = Bolt(input_stream=itertools.cycle(
         tup_json.splitlines(True)),
                      output_stream=BytesIO())
     self.bolt.initialize({}, {})