def test_read_command(self): # Check that we properly queue task IDs and return only commands inputs = [ # Task IDs '[12, 22, 24]\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' ] outputs = [json.loads(msg) for msg in inputs[::2]] component = Component(input_stream=BytesIO( ''.join(inputs).encode('utf-8')), output_stream=BytesIO()) # Skip first output, because it's a task ID, and won't be returned by # read_command for output in outputs[1:]: log.info('Checking msg for %r', output) msg = component.read_command() self.assertEqual(output, msg) self.assertEqual(component._pending_task_ids.pop(), outputs[0])
def test_read_command(self): # Check that we properly queue task IDs and return only commands inputs = [# Task IDs '[12, 22, 24]\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'] outputs = [json.loads(msg) for msg in inputs[::2]] component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')), output_stream=BytesIO()) # Skip first output, because it's a task ID, and won't be returned by # read_command for output in outputs[1:]: log.info('Checking msg for %r', output) msg = component.read_command() self.assertEqual(output, msg) self.assertEqual(component._pending_task_ids.pop(), outputs[0])