Exemplo n.º 1
0
    def test_reraising_exception(self):
        e = Exception('reraise this')
        with self.assertRaises(Exception) as raised:
            with nested(TemporaryFile(), TemporaryFile()) as (a, b):
                raise e

        self.assertEqual(raised.exception, e)
Exemplo n.º 2
0
    def run(self):
        """
        Run the JVM in the current configuration.

        :raises: :exc:`JVMNotConfiguredError` if no workload or classpath is set
        """

        if not self._classpath:
            log.error('No classpath configured')
            raise JVMNotConfiguredError('no classpath configured')

        if not self.workload:
            log.error('No workload configured')
            raise JVMNotConfiguredError('no workload configured')

        log.debug("executing setup hooks")
        hooks = self._get_hooks()
        for hook in hooks:
            hook.setup()

        log.debug("executing {0}".format(self.cmdline))
        with nested(NamedTemporaryFile(delete=False, dir='.'),
                    NamedTemporaryFile(delete=False, dir='.')) \
            as (stderr, stdout):
            self.proc = subprocess.Popen(self.cmdline,
                    stdout=stdout, stderr=stderr)

            # measure usertime before
            before = os.times()[0]
            log.debug('CPU time before invocation: {0}'.format(before))

            self.proc.communicate()

            # measure usertime after
            after = os.times()[0]
            diff = after - before
            log.debug('CPU time after invocation: {0}, difference: '
                      '{1}'.format(after, diff))

            if diff > 0.1:
                log.error('High cpu difference: {0} seconds'.format(diff))

            self.workload.out['exit_code'].append(self.proc.returncode)
            self.workload.out['stdout'].append(stdout.name)
            self.workload.out['stderr'].append(stderr.name)
            if self.proc.returncode != 0:
                log.error('jvm execution failed, stderr:')
                stderr.seek(0)
                log.error(stderr.read())
                log.error('jvm execution failed, stdout:')
                stdout.seek(0)
                log.error(stdout.read())
                raise JVMExecutionError('non zero exit code: {0}'
                                        .format(self.proc.returncode))

        log.debug("executing teardown hooks")
        for hook in hooks:
            hook.teardown()
Exemplo n.º 3
0
    def test_raising_on_exit(self):
        @contextmanager
        def raising_cm(exception):
            yield
            raise exception

        on_exit = Exception('throw on exit')
        with self.assertRaises(Exception) as raised:
            with nested(raising_cm(on_exit)):
                pass
        self.assertEqual(raised.exception, on_exit)
Exemplo n.º 4
0
    def run_clients(self):
        """
        Run the client on all nodes.
        """
        with nested(make_bootstrap_pom(), make_bootstrap_client()) \
                as (pom, bclient):
            for node in self.nodes.values():
                with node.connection_required():
                    for upload in self.uploads:
                        node.put(*upload)
                    node.put(pom.name, 'bootstrap.pom')
                    node.put(bclient.name, 'penchy_bootstrap')

                    node.execute_penchy(' '.join(
                        self.bootstrap_args + [os.path.basename(self.job_file),
                            'config.py', node.setting.identifier]))