def test_read_task_ids(self): # Check that we properly queue commands and return only task IDs inputs = [ # Task IDs '[4, 8, 15]\n', 'end\n', # Incoming Tuple for bolt ('{ "id": "-6955786537413359385", "comp": "1", "stream": "1"' ', "task": 9, "tuple": ["snow white and the seven dwarfs", ' '"field2", 3]}\n'), 'end\n', # next command for spout '{"command": "next"}\n', 'end\n', # Task IDs '[16, 23, 42]\n', 'end\n' ] outputs = [json.loads(msg) for msg in inputs[::2]] component = Component(input_stream=BytesIO( ''.join(inputs).encode('utf-8')), output_stream=BytesIO()) # Skip middle outputs, because they're commands and won't be returned by # read_task_ids for output in (outputs[0], outputs[-1]): log.info('Checking msg for %s', output) msg = component.read_task_ids() self.assertEqual(output, msg) for output in outputs[1:-1]: self.assertEqual(component._pending_commands.popleft(), output)
def test_read_task_ids(self): # Check that we properly queue commands and return only task IDs inputs = [# Task IDs '[4, 8, 15]\n', 'end\n', # Incoming tuple for bolt ('{ "id": "-6955786537413359385", "comp": "1", "stream": "1"' ', "task": 9, "tuple": ["snow white and the seven dwarfs", ' '"field2", 3]}\n'), 'end\n', # next command for spout '{"command": "next"}\n', 'end\n', # Task IDs '[16, 23, 42]\n', 'end\n'] outputs = [json.loads(msg) for msg in inputs[::2]] component = Component(input_stream=StringIO(''.join(inputs)), output_stream=BytesIO()) # Skip middle outputs, because they're commands and won't be returned by # read_task_ids for output in (outputs[0], outputs[-1]): log.info('Checking msg for %s', output) msg = component.read_task_ids() self.assertEqual(output, msg) for output in outputs[1:-1]: self.assertEqual(component._pending_commands.popleft(), output)