def test_multiple(self): data = b'x\nx\nx\nx\nx\nx\n' mapper_cmd = 'cat -e' reducer_cmd = bash_wrap('wc -l | tr -Cd "[:digit:]"') job = CmdJob([ '--runner', 'local', '--mapper-cmd', mapper_cmd, '--combiner-cmd', 'uniq', '--reducer-cmd', reducer_cmd ]) job.sandbox(stdin=BytesIO(data)) with job.make_runner() as r: self.assertEqual(r._get_steps(), [{ 'type': 'streaming', 'mapper': { 'type': 'command', 'command': mapper_cmd }, 'combiner': { 'type': 'command', 'command': 'uniq' }, 'reducer': { 'type': 'command', 'command': reducer_cmd }, }]) r.run() self.assertEqual(list(r.stream_output()), [b'2'])
def test_multiple_2(self): data = 'x\ny\nz\n' job = CmdJob(['--mapper-cmd=cat', '--reducer-cmd-2', 'wc -l', '--runner=local', '--no-conf']) job.sandbox(stdin=StringIO(data)) with job.make_runner() as r: r.run() self.assertEqual(sum(int(l) for l in r.stream_output()), 3)
def test_cat_mapper(self): data = b'x\ny\nz\n' job = CmdJob(['--mapper-cmd=cat', '--runner=local']) job.sandbox(stdin=BytesIO(data)) with job.make_runner() as r: self.assertEqual(r._get_steps(), [{ 'type': 'streaming', 'mapper': { 'type': 'command', 'command': 'cat' } }]) r.run() lines = [line.strip() for line in list(r.stream_output())] self.assertEqual(sorted(lines), sorted(data.split()))
def test_cat_mapper(self): data = 'x\ny\nz\n' job = CmdJob(['--mapper-cmd=cat', '--runner=local']) job.sandbox(stdin=StringIO(data)) with job.make_runner() as r: self.assertEqual( r._get_steps(), [{ 'type': 'streaming', 'mapper': { 'type': 'command', 'command': 'cat'}}]) r.run() self.assertEqual(''.join(r.stream_output()), data)
def test_cat_reducer(self): data = b'x\ny\nz\n' job = CmdJob(['--reducer-cmd', 'cat -e', '--runner=local']) job.sandbox(stdin=BytesIO(data)) with job.make_runner() as r: self.assertEqual(r._get_steps(), [{ 'type': 'streaming', 'mapper': { 'type': 'script', }, 'reducer': { 'type': 'command', 'command': 'cat -e' } }]) r.run() lines = list(r.stream_output()) self.assertEqual(sorted(lines), [b'x$\n', b'y$\n', b'z$\n'])
def test_uniq_combiner(self): data = b'x\nx\nx\nx\nx\nx\n' job = CmdJob(['--combiner-cmd=uniq', '--runner=local']) job.sandbox(stdin=BytesIO(data)) with job.make_runner() as r: self.assertEqual(r._get_steps(), [{ 'type': 'streaming', 'mapper': { 'type': 'script', }, 'combiner': { 'type': 'command', 'command': 'uniq' } }]) r.run() # there are 2 map tasks, each of which has 1 combiner, and all rows # are the same, so we should end up with just 2 values self.assertEqual(b''.join(r.stream_output()), b'x\nx\n')
def test_passthrough_options(self): cmd_job = CmdJob(['--help']) output = self.stdout.getvalue() self.assertIn('--reducer-cmd-2', output)
def test_passthrough_options(self): CmdJob(['--help']) self.exit.assert_called_once_with(0) output = self.stdout.getvalue() self.assertIn('--reducer-cmd-2', output)