diff options
author | Anton Leherbauer | 2015-02-24 13:54:29 +0000 |
---|---|---|
committer | Anton Leherbauer | 2015-02-24 13:55:01 +0000 |
commit | a6ebf61332729435fd1cf42bbdbdfce147a0ac34 (patch) | |
tree | f765055f6bc0b59fc201447930bc6d9abf07db78 | |
parent | 12e7d2c95e78f9c99333278f508ed0928ab64383 (diff) | |
download | org.eclipse.tcf-a6ebf61332729435fd1cf42bbdbdfce147a0ac34.tar.gz org.eclipse.tcf-a6ebf61332729435fd1cf42bbdbdfce147a0ac34.tar.xz org.eclipse.tcf-a6ebf61332729435fd1cf42bbdbdfce147a0ac34.zip |
Bug 460688 - Fix failing test: ProcessLauncherTestCase
Change-Id: I7a01a3e16b541a18241e70a8ec65b6c970a4f2fa
Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
2 files changed, 36 insertions, 17 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessLauncher.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessLauncher.java index ea321e33b..cb7df55f9 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessLauncher.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessLauncher.java @@ -560,14 +560,6 @@ public class ProcessLauncher extends PlatformObject implements IProcessLauncher return; } - // The callback collector assure that all necessary work, like opening the terminal - // window and terminal tab, is done before the process get launched finally. - AsyncCallbackCollector collector = new AsyncCallbackCollector(new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - } - }, new CallbackInvocationDelegate()); - // The streams got subscribed, check what we need to do with them if (streamsProxy != null) { // Publish the streams to the supplied proxy @@ -576,17 +568,17 @@ public class ProcessLauncher extends PlatformObject implements IProcessLauncher streamsProxy.connectOutputStreamMonitor(connectRemoteInputStream(getStreamsListener(), new String[] { IProcesses.PROP_STDOUT_ID }, null)); // Create and store the streams the terminal will see as stderr streamsProxy.connectErrorStreamMonitor(connectRemoteInputStream(getStreamsListener(), new String[] { IProcesses.PROP_STDERR_ID }, null)); + onAttachStreamsDone(); } else if (properties.getBooleanProperty(IProcessLauncher.PROP_PROCESS_ASSOCIATE_CONSOLE)) { // We don't have a streams proxy, we default the output redirection to the standard terminals console view - // Register the terminal tab listener to listen to the terminal events - terminalTabListener = new ProcessLauncherTerminalTabListener(this); - TerminalServiceFactory.getService().addTerminalTabListener(terminalTabListener); - // Get the terminal service ITerminalService terminal = TerminalServiceFactory.getService(); // If not available, we cannot fulfill this request if (terminal != null) { + // Register the terminal tab listener to listen to the terminal events + terminalTabListener = new ProcessLauncherTerminalTabListener(this); + terminal.addTerminalTabListener(terminalTabListener); // Create the terminal streams settings Map<String, Object> props = new HashMap<String, Object>(); props.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, "org.eclipse.tcf.te.ui.terminals.telnet.launcher.streams"); //$NON-NLS-1$ @@ -639,6 +631,8 @@ public class ProcessLauncher extends PlatformObject implements IProcessLauncher }); } }); + } else { + onAttachStreamsDone(); } } else if (properties.getStringProperty(IProcessLauncher.PROP_PROCESS_OUTPUT_REDIRECT_TO_FILE) != null) { // Get the file name where to redirect the process output to @@ -652,6 +646,7 @@ public class ProcessLauncher extends PlatformObject implements IProcessLauncher if (getStreamsListener() instanceof ProcessStreamsListener) { ((ProcessStreamsListener)getStreamsListener()).registerDataReceiver(receiver); } + onAttachStreamsDone(); } catch (IOException e) { // Construct the error message to show to the user String message = NLS.bind(getProcessLaunchFailedMessageTemplate(), @@ -666,9 +661,6 @@ public class ProcessLauncher extends PlatformObject implements IProcessLauncher return; } } - - // Mark the collector initialization as done - collector.initDone(); } /** diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/processes/launcher/ProcessLauncherTestCase.java b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/processes/launcher/ProcessLauncherTestCase.java index 75b5a55a4..dd349e733 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/processes/launcher/ProcessLauncherTestCase.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/processes/launcher/ProcessLauncherTestCase.java @@ -10,6 +10,7 @@ package org.eclipse.tcf.te.tests.tcf.processes.launcher; import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; import junit.framework.Test; import junit.framework.TestSuite; @@ -18,11 +19,13 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.tcf.services.IProcesses.ProcessesListener; import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.tcf.processes.core.interfaces.launcher.IProcessLauncher; import org.eclipse.tcf.te.tcf.processes.core.launcher.ProcessLauncher; +import org.eclipse.tcf.te.tcf.processes.core.launcher.ProcessProcessesListener; import org.eclipse.tcf.te.tests.tcf.TcfTestCase; /** @@ -93,10 +96,23 @@ public class ProcessLauncherTestCase extends TcfTestCase { assertNull("Failed to copy file from " + helloWorldLocation.toOSString() + " to " + tempHelloWorld.toOSString() + ": " + e, e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } + final AtomicBoolean processExited = new AtomicBoolean(); + // Create the process streams proxy ProcessStreamsProxy proxy = new ProcessStreamsProxy(); // Create the process launcher - ProcessLauncher launcher = new ProcessLauncher(proxy); + ProcessLauncher launcher = new ProcessLauncher(proxy) { + @Override + protected ProcessesListener createProcessesListener() { + return new ProcessProcessesListener(this) { + @Override + public void exited(String processId, int exitCode) { + super.exited(processId, exitCode); + processExited.set(true); + } + }; + } + }; // Create the launch properties IPropertiesContainer properties = new PropertiesContainer(); @@ -113,8 +129,19 @@ public class ProcessLauncherTestCase extends TcfTestCase { } }); + // Wait for the process to terminate + int counter = 50; + while (counter > 0 && !processExited.get()) { + waitAndDispatch(100); + counter--; + } + assertTrue("Test application did not exit in time.", processExited.get()); //$NON-NLS-1$ + + // Bug 431347: ProcessOutputReaderThread does not terminate itself on EOF + proxy.getOutputReader().interrupt(); + // Wait for the output reader to finish - int counter = 240; + counter = 240; while (counter > 0) { if (proxy.getOutputReader() != null && proxy.getOutputReader().isFinished()) break; waitAndDispatch(500); |