Search in sources :

Example 1 with RDTCommandLauncher

use of org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher in project linuxtools by eclipse.

the class CommandLauncherProxyTest method testRemoteCommandLauncher.

@Test
public void testRemoteCommandLauncher() {
    IRemoteCommandLauncher cl = null;
    Process p = null;
    IPath commandPath, changeToDirectory;
    String[] args, env;
    try {
        cl = proxyManager.getLauncher(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", cl instanceof RDTCommandLauncher);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    commandPath = new Path("uptime");
    args = new String[] { "-s" };
    env = new String[] { "PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" };
    changeToDirectory = new Path("/tmp");
    try {
        p = cl.execute(commandPath, args, env, changeToDirectory, new NullProgressMonitor());
        assertNotNull(p);
        p.waitFor();
        assertEquals("Process exited with failure", 0, p.exitValue());
    } catch (Exception e) {
        fail("Unable to execute " + commandPath + " on remote machine: " + e.getMessage());
    }
    InputStream actualIS = p.getInputStream();
    int v = -1;
    try {
        v = actualIS.read();
    } catch (IOException e) {
        fail("Failed to read output of command executed remotely: " + e.getMessage());
    }
    // Ensure something can be read
    assertTrue(v != -1);
    /*
		 * Test it opens connection before execute.
		 */
    IRemoteConnection conn = getConnection();
    conn.close();
    assertFalse(conn.isOpen());
    try {
        p = cl.execute(new Path("ls"), new String[] {}, new String[] {}, null, new NullProgressMonitor());
        assertNotNull(p);
        p.waitFor();
        assertEquals("Process exited with failure", 0, p.exitValue());
    } catch (CoreException | InterruptedException e) {
        fail("Failed to open connection to execute a command: " + e.getMessage());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) InputStream(java.io.InputStream) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) IOException(java.io.IOException) RDTCommandLauncher(org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 2 with RDTCommandLauncher

use of org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher in project linuxtools by eclipse.

the class RemoteProxyManagerTest method testGetLauncher.

@Test
public void testGetLauncher() {
    IRemoteCommandLauncher cl;
    try {
        /*
			 * Test launcher got for local URIs and project
			 */
        cl = proxyManager.getLauncher(localProject.getLocationURI());
        assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
        cl = proxyManager.getLauncher(localProject.getProject());
        assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
        /*
			 * Test launcher got for remote project and URI
			 */
        cl = proxyManager.getLauncher(URI.create("ssh://" + CONNECTION_NAME + "/path/to/file"));
        assertTrue("Should have returned a remote file proxy", cl instanceof RDTCommandLauncher);
        cl = proxyManager.getLauncher(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", cl instanceof RDTCommandLauncher);
        /*
			 * Test launcher got for jsch scheme
			 */
        cl = proxyManager.getLauncher(URI.create("jsch://" + USERNAME + "@" + HOST + ":22/path/to/file"));
        assertTrue("Should have returned a remote file proxy", cl instanceof SSHCommandLauncher);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    /*
		 * Test the proxy for unsupported URIs
		 */
    try {
        // As of org.eclipse.remote 2.0, remotetools scheme is no longer
        // support
        cl = proxyManager.getLauncher(URI.create("remotetools://MyConnection/path/to/file"));
        fail("remotetools scheme should not be recognized");
    } catch (CoreException e) {
        assertTrue(e.getMessage(), true);
    }
}
Also used : LocalLauncher(org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher) CoreException(org.eclipse.core.runtime.CoreException) SSHCommandLauncher(org.eclipse.linuxtools.internal.ssh.proxy.SSHCommandLauncher) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) RDTCommandLauncher(org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)2 RDTCommandLauncher (org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher)2 IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)2 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 LocalLauncher (org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher)1 SSHCommandLauncher (org.eclipse.linuxtools.internal.ssh.proxy.SSHCommandLauncher)1 IRemoteConnection (org.eclipse.remote.core.IRemoteConnection)1