示例#1
0
    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)
示例#2
0
    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=StringIO(''.join(inputs)),
                              output_stream=BytesIO())

        for output in outputs:
            log.info('Checking tuple for %s', output)
            tup = component.read_tuple()
            self.assertEqual(output, tup)