Beispiel #1
0
    def test_run(self):
        a = [0, 0, 0]
        b = [0, 0, 0]
        jvm = JVM('java')
        jvm.basepath = '/usr/bin'

        w = ScalaBench('dummy')
        jvm.workload = w
        jvm.hooks = [Hook(lambda: a.__setitem__(0, 1)),
                     Hook(lambda: a.__setitem__(1, 2)),
                     Hook(lambda: a.__setitem__(2, 3)),
                     Hook(teardown=lambda: b.__setitem__(0, 1)),
                     Hook(teardown=lambda: b.__setitem__(1, 2)),
                     Hook(teardown=lambda: b.__setitem__(2, 3))]

        self.assertFalse('stdout' in w.out)
        self.assertFalse('stderr' in w.out)
        self.assertFalse('exit_code' in w.out)

        with tempdir(prefix='penchy-test', delete=True):
            p = BootstrapPOM()
            for d in ScalaBench.DEPENDENCIES:
                p.add_dependency(d)
            p.write('pom.xml')
            jvm.add_to_cp(get_classpath())
            jvm.run()

        self.assertTrue('stdout' in w.out)
        self.assertTrue('stderr' in w.out)
        self.assertTrue('exit_code' in w.out)

        self.assertListEqual(a, [1, 2, 3])
        self.assertListEqual(b, [1, 2, 3])
Beispiel #2
0
    def run(self, composition):
        """
        Run clientside Job.

        :param composition: composition to run.
        :type composition: :class:`SystemComposition`
        """
        # setup
        pomfile = os.path.join(composition.node_setting.path, 'pom.xml')
        setup_dependencies(pomfile, self._get_client_dependencies(composition))
        composition.jvm.add_to_cp(get_classpath(pomfile))
        self._composition = composition

        # save send for restoring
        send = self.send
        # replace with one that knows how to identify the composition if it is set
        if self.send is not None:
            self.send = partial(self.send, composition.hash())

        composition.jvm.basepath = composition.node_setting.basepath

        _, edge_order = edgesort(composition.starts, composition.flow)

        for i in range(1, self.invocations + 1):
            log.info('Run invocation {0}'.format(i))
            with tempdir(prefix='penchy-invocation{0}-'.format(i)):
                composition.jvm.run()

        log.info('Run pipeline')
        for sink, group in groupby(edge_order, attrgetter('sink')):
            kwargs = build_keys(group)
            if isinstance(sink, SystemFilter):
                kwargs[':environment:'] = self._build_environment()
            log.debug('Passing this input to {0}:\n{1}'
                      .format(sink.__class__.__name__,
                              kwargs))
            try:
                sink.run(**kwargs)
            except TypeCheckError:
                log.error('Type check failed on component {0} and arguments {1}'
                          .format(sink.__class__.__name__, kwargs))
                raise
            except WrongInputError:
                log.error('Run failed on component {0} and arguments {1}'
                          .format(sink.__class__.__name__, kwargs))
                raise
            log.debug('{0} transformed input to:\n{1}'
                      .format(sink.__class__.__name__, sink.out))

        # reset state of filters for running multiple configurations
        composition._reset()
        # restore send
        self.send = send
        self._composition = None
Beispiel #3
0
 def test_save_and_backup(self):
     data = "'tis the end"
     with tempdir(delete=True):
         s = Save('save')
         s._run(data=data, **{':environment:' : self.env})
         b = BackupFile('backup')
         b._run(filename='save', **{':environment:' : self.env})
         with open('save') as f:
             self.assertEqual(f.read(), data)
         with open('backup') as f:
             self.assertEqual(f.read(), data)
Beispiel #4
0
 def test_change(self):
     cwd = os.getcwd()
     with util.tempdir(delete=True):
         self.assertNotEqual(cwd, os.getcwd())
     self.assertEqual(cwd, os.getcwd())