Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2011-03-13 04:07:53 +0000
committerRyan D. Brooks2011-03-13 04:07:53 +0000
commitdca57ebf090b9112ba91d205b3e0f507409d6cf7 (patch)
treead0f8fa982259460ee7307ddfefee9a0733f7793 /plugins/org.eclipse.osee.framework.jdk.core.test
parent62861dcb9d056d48db529324c3b1640051d81c1a (diff)
downloadorg.eclipse.osee-dca57ebf090b9112ba91d205b3e0f507409d6cf7.tar.gz
org.eclipse.osee-dca57ebf090b9112ba91d205b3e0f507409d6cf7.tar.xz
org.eclipse.osee-dca57ebf090b9112ba91d205b3e0f507409d6cf7.zip
feature[ats_24T3P]: Allow a process created with Processes to be cleanly stoped
Diffstat (limited to 'plugins/org.eclipse.osee.framework.jdk.core.test')
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/ProcessesTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/ProcessesTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/ProcessesTest.java
new file mode 100644
index 0000000000..db5df5049d
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/ProcessesTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.eclipse.osee.framework.jdk.core.util.Processes;
+import org.eclipse.osee.framework.jdk.core.util.io.OutputRedirector;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Ryan Brooks
+ */
+public class ProcessesTest {
+
+ public static final ExecutorService executor = Executors.newCachedThreadPool();
+ private static final String argument = "progress";
+
+ @Test
+ public void testProcessCancel() throws IOException, InterruptedException, ExecutionException {
+ ProcessBuilder builder =
+ new ProcessBuilder("java", "-cp", ".\\bin", "org.eclipse.osee.framework.jdk.core.test.util.ProcessesTest",
+ argument, "bye");
+ builder.redirectErrorStream(true);
+ Process process = builder.start();
+
+ StringWriter stringWriter = new StringWriter();
+ BufferedReader stdOutputIn = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ Future<Long> outFuture = Processes.executor.submit(new OutputRedirector(stringWriter, stdOutputIn));
+ Thread.sleep(500);
+ process.destroy();
+ Assert.assertEquals(argument, stringWriter.toString());
+ Assert.assertEquals(new Long(argument.length()), outFuture.get());
+ }
+
+ @Test
+ public void testExecuteCommandToString() {
+ commandToStringHelper("java version ", "java", "-version");
+ commandToStringHelper("java.io.IOException: Cannot run program", "bogus command");
+ commandToStringHelper("Could not create the Java virtual machine", "java", "-alsdfk");
+ }
+
+ private void commandToStringHelper(String startsWith, String... callAndArgs) {
+ String actual = Processes.executeCommandToString(callAndArgs);
+ int pos = Math.min(actual.length(), startsWith.length());
+ Assert.assertEquals(startsWith, actual.substring(0, pos));
+ }
+
+ /**
+ * this method is invoked from testProcessCancel in a separate process
+ *
+ * @param args
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public static final void main(String[] args) throws IOException, InterruptedException {
+ System.out.print(args[0]);
+ Thread.sleep(3000);
+ System.in.read();
+ System.out.println(args[1]);
+ }
+} \ No newline at end of file

Back to the top