def __init__( self, identity, workdir, nailgun_classpath, distribution, startup_timeout=10, connect_timeout=10, connect_attempts=5, metadata_base_dir=None, ): Executor.__init__(self, distribution=distribution) FingerprintedProcessManager.__init__( self, name=identity, process_name=self._PROCESS_NAME, metadata_base_dir=metadata_base_dir, ) if not isinstance(workdir, str): raise ValueError( "Workdir must be a path string, not: {workdir}".format(workdir=workdir) ) self._identity = identity self._workdir = workdir self._ng_stdout = os.path.join(workdir, "stdout") self._ng_stderr = os.path.join(workdir, "stderr") self._nailgun_classpath = ensure_str_list(nailgun_classpath, allow_single_str=True) self._startup_timeout = startup_timeout self._connect_timeout = connect_timeout self._connect_attempts = connect_attempts
def __init__(self, identity, workdir, nailgun_classpath, distribution, ins=None, connect_timeout=10, connect_attempts=5): Executor.__init__(self, distribution=distribution) ProcessManager.__init__(self, name=identity, process_name=self._PROCESS_NAME) if not isinstance(workdir, string_types): raise ValueError( 'Workdir must be a path string, not: {workdir}'.format( workdir=workdir)) self._identity = identity self._workdir = workdir self._ng_stdout = os.path.join(workdir, 'stdout') self._ng_stderr = os.path.join(workdir, 'stderr') self._nailgun_classpath = maybe_list(nailgun_classpath) self._ins = ins self._connect_timeout = connect_timeout self._connect_attempts = connect_attempts
def __init__(self, identity, workdir, nailgun_classpath, distribution, ins=None, connect_timeout=10, connect_attempts=5): Executor.__init__(self, distribution=distribution) ProcessManager.__init__(self, name=identity, process_name=self._PROCESS_NAME) if not isinstance(workdir, string_types): raise ValueError('Workdir must be a path string, not: {workdir}'.format(workdir=workdir)) self._identity = identity self._workdir = workdir self._ng_stdout = os.path.join(workdir, 'stdout') self._ng_stderr = os.path.join(workdir, 'stderr') self._nailgun_classpath = maybe_list(nailgun_classpath) self._ins = ins self._connect_timeout = connect_timeout self._connect_attempts = connect_attempts
class ExecuteJavaTest(unittest.TestCase): """ :API: public """ EXECUTOR_ERROR = Executor.Error() TEST_MAIN = 'foo.bar.main' TEST_CLASSPATH = ['A.jar', 'B.jar'] SAFE_CLASSPATH = ['C.jar'] SYNTHETIC_JAR_DIR = 'somewhere' def setUp(self): """ :API: public """ self.executor = Mock(spec=Executor) self.runner = Mock(spec=Executor.Runner) self.executor.runner = Mock(return_value=self.runner) self.runner.run = Mock(return_value=0) @contextmanager def mock_safe_classpath_helper(self, create_synthetic_jar=True): """ :API: public """ with patch('pants.java.util.safe_classpath') as mock_safe_classpath: mock_safe_classpath.side_effect = fake_safe_classpath yield mock_safe_classpath self.runner.run.assert_called_once_with(stdin=None) if create_synthetic_jar: self.executor.runner.assert_called_once_with(self.SAFE_CLASSPATH, self.TEST_MAIN, args=None, jvm_options=None, cwd=None) mock_safe_classpath.assert_called_once_with( self.TEST_CLASSPATH, self.SYNTHETIC_JAR_DIR) else: self.executor.runner.assert_called_once_with(self.TEST_CLASSPATH, self.TEST_MAIN, args=None, jvm_options=None, cwd=None) mock_safe_classpath.assert_not_called() def test_execute_java_no_error(self): """ :API: public """ with self.mock_safe_classpath_helper(): self.assertEqual( 0, execute_java(self.TEST_CLASSPATH, self.TEST_MAIN, executor=self.executor, synthetic_jar_dir=self.SYNTHETIC_JAR_DIR)) def test_execute_java_executor_error(self): """ :API: public """ with self.mock_safe_classpath_helper(): self.runner.run.side_effect = self.EXECUTOR_ERROR with self.assertRaises(type(self.EXECUTOR_ERROR)): execute_java(self.TEST_CLASSPATH, self.TEST_MAIN, executor=self.executor, synthetic_jar_dir=self.SYNTHETIC_JAR_DIR) def test_execute_java_no_synthentic_jar(self): """ :API: public """ with self.mock_safe_classpath_helper(create_synthetic_jar=False): self.assertEqual( 0, execute_java(self.TEST_CLASSPATH, self.TEST_MAIN, executor=self.executor, create_synthetic_jar=False))