public void testTestFinalize() throws Throwable { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream captured = new PrintStream(baos); mysqldResource = new MysqldResource(baseDir, dataDir, "", captured, captured, utils); mysqldResource.finalize(); captured.flush(); String output = new String(baos.toByteArray()); assertEquals("", output); PrintStream devNull = new NullPrintStream(); String[] none = new String[0]; mysqldResource.setShell(new Shell.Default(none, "bogus", devNull, devNull)); mysqldResource.finalize(); captured.flush(); output = new String(baos.toByteArray()); testUtil.assertContainsIgnoreCase(output, "MysqldResource.initTrace"); }
@Override public void run() { if (p != null) { throw new IllegalStateException("Process already running"); } try { returnCode = null; p = runtime.exec(args, envp, workingDir); captureStdOutAndStdErr(); returnCode = Integer.valueOf(p.waitFor()); } catch (Exception e) { throw exceptions.toRuntime(e); } finally { // p.destroy(); p = null; for (int i = 0; i < listeners.size(); i++) { new Thread((Runnable) listeners.get(i)).start(); } listeners.clear(); } }
public void testCompletionListener() { Exception expected = null; try { shell.addCompletionListener(null); } catch (IllegalArgumentException e) { expected = e; } assertNotNull(expected); class TestListener implements Runnable { int timesRun = 0; public void run() { timesRun++; } } TestListener listener = new TestListener(); shell.addCompletionListener(listener); shell.run(); for (int c = 0; c < 5 && (listener.timesRun == 0); c++) { new Threads().pause(10); } assertEquals(1, listener.timesRun); }
public void testCompletionListener() { Exception expected = null; try { shell.addCompletionListener(null); } catch (IllegalArgumentException e) { expected = e; } assertNotNull(expected); class TestListener implements Runnable { int timesRun = 0; public void run() { timesRun++; } } TestListener listener = new TestListener(); shell.addCompletionListener(listener); shell.run(); for (int c = 0; c < 5 && (listener.timesRun == 0); c++) { new Threads().pause(10); } assertEquals(1, listener.timesRun); }
public void run() { if (p != null) { throw new IllegalStateException("Process already running"); } try { returnCode = null; p = runtime.exec(args, envp, workingDir); captureStdOutAndStdErr(); returnCode = new Integer(p.waitFor()); } catch (Exception e) { throw exceptions.toRuntime(e); } finally { // p.destroy(); p = null; for (int i = 0; i < listeners.size(); i++) { new Thread((Runnable) listeners.get(i)).start(); } listeners.clear(); } }
public void run() { if (p != null) { throw new IllegalStateException("Process already running"); } try { returnCode = null; p = runtime.exec(args, envp, workingDir); captureStdOutAndStdErr(); returnCode = new Integer(p.waitFor()); } catch (Exception e) { throw exceptions.toRuntime(e); } finally { // p.destroy(); p = null; for (int i = 0; i < listeners.size(); i++) { new Thread((Runnable) listeners.get(i)).start(); } listeners.clear(); } }
public void testTestFinalize() throws Throwable { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream captured = new PrintStream(baos); mysqldResource = new MysqldResource(fileUtil.nullFile(), captured, captured, fileUtil, shellFactory, streams, threads, str, classUtil); mysqldResource.finalize(); captured.flush(); String output = new String(baos.toByteArray()); assertEquals("", output); PrintStream devNull = new NullPrintStream(); String[] none = new String[0]; mysqldResource.setShell(new Shell.Default(none, "bogus", devNull, devNull)); mysqldResource.finalize(); captured.flush(); output = new String(baos.toByteArray()); testUtil.assertContainsIgnoreCase(output, "<init>"); }
@Override public int returnCode() { if (!hasReturned()) { throw new RuntimeException("Process hasn't returned yet"); } return returnCode.intValue(); }
protected void setUp() { super.setUp(); processSleep = 0; String[] commandLineArgs = new String[] { "java" }; String threadName = "ShellTest" + shellName++; shell = new Shell.Default(commandLineArgs, threadName, System.out, System.err); setRuntime(0); }
public Shell newShell(String[] args, String name, PrintStream out, PrintStream err) { return new Default(args, name, out, err); } }
public Shell newShell(String[] args, String name, PrintStream out, PrintStream err) { return new Default(args, name, out, err); } }
public Shell newShell(String[] args, String name, PrintStream out, PrintStream err) { return new Default(args, name, out, err); } }
public void testDestroy() throws Exception { processSleep = 2000; assertNull(testProcess); shell.start(); new Threads().pause(20); shell.destroyProcess(); assertEquals(1, testProcess.destroyCalled); }
public void testForThrownExceptions() throws Exception { shell = new Shell.Default(null, "foo", null, null); Exception expected = null; try { shell.run(); } catch (Exception e) { expected = e; } assertNotNull(expected); }
protected void setUp() { super.setUp(); processSleep = 0; String[] commandLineArgs = new String[] { "java" }; String threadName = "ShellTest" + shellName++; shell = new Shell.Default(commandLineArgs, threadName, System.out, System.err); setRuntime(0); }
public int returnCode() { if (!hasReturned()) { throw new RuntimeException("Process hasn't returned yet"); } return returnCode.intValue(); }