def setUp(self): if uname()[0] == "Darwin": self.skipTest("Cannot build static test_external on OS X") else: home = self.disco_settings["DISCO_HOME"] check_call( [ "gcc", "-g", "-O3", "-static", "-Wall", "-I", path.join(home, "ext"), "-o", path.join(home, "tests", "test_external"), path.join(home, "ext", "disco.c"), path.join(home, "tests", "test_external.c"), "-l", "Judy", ], stderr=STDOUT, ) self.map = external([path.join(home, "tests", "test_external")]) super(ExternalTestCase, self).setUp()
def test_extreduce(self): self.job = ExternalJob().run(input=self.test_server.urls(self.inputs), map=lambda e, params: [('', e)], reduce=external([self.binary])) ans = str_to_bytes( str( sum( map(ord, ''.join('test_{0}\n'.format(i) for i in self.inputs))))) self.assertEquals([(ans, ans)] * 10, list(self.results(self.job)))
def test_extmap(self): def reduce(iter, params): for k, v in iter: yield "red_" + bytes_to_str(k), "red_" + bytes_to_str(v) self.job = ExternalJob().run(input=self.test_server.urls(self.inputs), map=external([self.binary]), reduce=reduce) results = sorted((v, k) for k, v in self.results(self.job)) for n, (v, k) in enumerate(results): self.assertEquals(k, 'red_dkey') self.assertEquals(v, 'red_test_{0}\n'.format(self.inputs[int(n / 3)])) self.assertEquals(len(results), 9)
def test_extmap(self): def reduce(iter, params): for k, v in iter: yield "red_" + k, "red_" + v self.job = ExternalJob().run(input=self.test_server.urls(self.inputs), map=external([self.binary]), reduce=reduce) results = sorted((v, k) for k, v in self.results(self.job)) for n, (v, k) in enumerate(results): self.assertEquals(k, 'red_dkey') self.assertEquals(v, 'red_test_%s\n' % self.inputs[n / 3]) self.assertEquals(len(results), 9)
def setUp(self): if uname()[0] == 'Darwin': self.skipTest('Cannot build static test_external on OS X') else: home = self.disco_settings['DISCO_HOME'] check_call(['gcc', '-g', '-O3', '-static', '-Wall', '-I', path.join(home, 'ext'), '-o', path.join(home, 'tests', 'test_external'), path.join(home, 'ext', 'disco.c'), path.join(home, 'tests', 'test_external.c'), '-l', 'Judy'], stderr=STDOUT) self.map = external([path.join(home, 'tests', 'test_external')]) super(ExternalTestCase, self).setUp()
def setUp(self): if uname()[0] == 'Darwin': self.skipTest('Cannot build static test_external on OS X') else: home = self.disco_settings['DISCO_HOME'] check_call([ 'gcc', '-g', '-O3', '-static', '-Wall', '-I', path.join(home, 'ext'), '-o', path.join(home, 'tests', 'test_external'), path.join(home, 'ext', 'disco.c'), path.join(home, 'tests', 'test_external.c'), '-l', 'Judy' ], stderr=STDOUT) self.map = external([path.join(home, 'tests', 'test_external')]) super(ExternalTestCase, self).setUp()
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ from disco.core import Disco, result_iterator from disco.util import external ext_map_exec = "java_map.sh" ext_reduce_exec = "java_reduce.sh" map_class = "rmaus.disco.external.sample.WordCountMap" reduce_class = "rmaus.disco.external.sample.WordCountReduce" job = Disco("http://discomaster-dr-01:8989").new_job( name = "java_wordcount", input = ["raw://foo", "raw://bar", "raw://foo"], ext_params = { "mapFunction" : map_class, "reduceFunction" : reduce_class, "testKey" : "testValue" }, map = external([ext_map_exec]), reduce = external([ext_reduce_exec])) results = job.wait(show=True) for result in sorted(result_iterator(results), key=lambda x:x[1]): print result
def fun_reduce(iter, out, params): for k, v in iter: out.add("red_" + k, "red_" + v) tserver.run_server(data_gen) inputs = ["ape", "cat", "dog"] params = {"test1": "1,2,3",\ "one two three": "dim\ndam\n",\ "dummy": "value"} job = Disco(sys.argv[1]).new_job( name = "test_external", input = tserver.makeurl(inputs), map = external(["ext_test"]), reduce = fun_reduce, ext_params = params, nr_reduces = 1, sort = False) results = sorted([(v, k) for k, v in result_iterator(job.wait())]) for i, e in enumerate(results): v, k = e if k != "red_dkey" or v != "red_test_%s" % inputs[i / 3]: raise Exception("Invalid answer: %s, %s" % (k, v)) if len(results) != 9: raise Exception("Wrong number of results: %u vs. 9" % len(results)) job.purge()
def test_extreduce(self): self.job = ExternalJob().run(input=self.test_server.urls(self.inputs), map=lambda e, params: [('', e)], reduce=external([self.binary])) ans = str(sum(map(ord, ''.join('test_%s\n' % i for i in self.inputs)))) self.assertEquals([(ans, ans)] * 10, list(self.results(self.job)))