@Test public void shouldFindAvailableSockets() throws IOException { final ServerSocket socket = this.testee.getNextAvailableServerSocket(); assertTrue(socket != null); socket.close(); }
private void gatherCoverageData(final Collection<ClassInfo> tests, final CoverageData coverage) throws IOException, InterruptedException, ExecutionException { final List<String> filteredTests = FCollection .map(tests, classInfoToName()); final SideEffect1<CoverageResult> handler = resultProcessor(coverage); final SocketFinder sf = new SocketFinder(); final ServerSocket socket = sf.getNextAvailableServerSocket(); final CoverageProcess process = new CoverageProcess(ProcessArgs .withClassPath(this.code.getClassPath()).andBaseDir(this.workingDir) .andLaunchOptions(this.launchOptions).andStderr(logInfo()) .andStdout(captureStandardOutIfVerbose()), this.coverageOptions, socket, filteredTests, handler); process.start(); final ExitCode exitCode = process.waitToDie(); if (exitCode == ExitCode.JUNIT_ISSUE) { LOG.severe("Error generating coverage. Please check that your classpath contains JUnit 4.6 or above."); throw new PitError( "Coverage generation minion exited abnormally. Please check the classpath."); } else if (!exitCode.isOk()) { LOG.severe("Coverage generator Minion exited abnormally due to " + exitCode); throw new PitError("Coverage generation minion exited abnormally!"); } else { LOG.fine("Coverage generator Minion exited ok"); } }
public MutationTestProcess createWorker( final Collection<MutationDetails> remainingMutations, final Collection<ClassName> testClasses) { final MinionArguments fileArgs = new MinionArguments(remainingMutations, testClasses, this.config.getEngine().getName(), this.args, this.timeoutStrategy, Log.isVerbose(), this.fullMutationMatrix, this.pitConfig); final ProcessArgs args = ProcessArgs.withClassPath(this.classPath) .andLaunchOptions(this.config.getLaunchOptions()) .andBaseDir(this.baseDir).andStdout(captureStdOutIfVerbose()) .andStderr(printWith("stderr ")); final SocketFinder sf = new SocketFinder(); final MutationTestProcess worker = new MutationTestProcess( sf.getNextAvailableServerSocket(), args, fileArgs); return worker; }
private void runCoverageProcess(final Class<?> test, final List<CoverageResult> coveredClasses) throws IOException, InterruptedException { final SideEffect1<CoverageResult> handler = a -> coveredClasses.add(a); final CoverageOptions sa = new CoverageOptions(coverOnlyTestees(), excludeTests(), TestPluginArguments.defaults(), true, -1); final JarCreatingJarFinder agent = new JarCreatingJarFinder(); try { final LaunchOptions lo = new LaunchOptions(agent); final SocketFinder sf = new SocketFinder(); final CoverageProcess process = new CoverageProcess(ProcessArgs .withClassPath(new ClassPath()).andLaunchOptions(lo), sa, sf.getNextAvailableServerSocket(), Arrays.asList(test.getName()), handler); process.start(); final ExitCode exitCode = process.waitToDie(); assertEquals(ExitCode.OK, exitCode); } finally { agent.close(); } }
@Test public void shouldFailWithExitCode() throws Exception { final SideEffect1<CoverageResult> noOpHandler = a -> { }; final CoverageOptions sa = new CoverageOptions(coverOnlyTestees(), excludeTests(), TestPluginArguments.defaults(), true, -1); final JarCreatingJarFinder agent = new JarCreatingJarFinder(); final LaunchOptions lo = new LaunchOptions(agent); final SocketFinder sf = new SocketFinder(); final CoverageProcess process = new CoverageProcess(ProcessArgs .withClassPath(classPathWithoutJUnit()).andLaunchOptions(lo), sa, sf.getNextAvailableServerSocket(), Arrays.asList(TestsForMultiBlockCoverage.class.getName()), noOpHandler); process.start(); final ExitCode exitCode = process.waitToDie(); assertEquals(ExitCode.JUNIT_ISSUE, exitCode); }