当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionException类代码示例

本文整理汇总了Java中net.schmizz.sshj.connection.ConnectionException的典型用法代码示例。如果您正苦于以下问题:Java ConnectionException类的具体用法?Java ConnectionException怎么用?Java ConnectionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionException类属于net.schmizz.sshj.connection包,在下文中一共展示了ConnectionException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeCommand

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
private Command executeCommand(String command) throws TransportException, ConnectionException {
	Session sshSession = null;
	Command cmd = null;
	
	try {
		sshSession = sshClient.startSession();
		
		cmd = sshSession.exec(command);
		
		cmd.join(SSH_EXEC_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
		
	} catch (ConnectionException e) {
		if (e.getCause() instanceof TimeoutException) {
			return null;
		}
		throw e;
	} finally {
		if (sshSession != null) {
			sshSession.close();
		}
	}
	
	return cmd;
}
 
开发者ID:openaire,项目名称:iis,代码行数:25,代码来源:SshSimpleConnection.java

示例2: runCommandAsynchronouslyShouldProperlyShutDownConnectionOnJoinAndSessionCloseFail

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = ConnectionException.class)
public void runCommandAsynchronouslyShouldProperlyShutDownConnectionOnJoinAndSessionCloseFail()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  BlockingQueue clientDisconnectQueue = new LinkedBlockingQueue();
  doAnswer(new BlockingWaitAnswer(clientDisconnectQueue)).when(mMockSSHClient).disconnect();
  Command mockCommand = mock(Command.class);
  when(mockSession.exec(anyString())).thenReturn(mockCommand);
  doThrow(ConnectionException.class).when(mockSession).close();
  doThrow(ConnectionException.class).when(mockCommand).join();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  RemoteProcess process = mSSHEnv.runCommandAsynchronously(command);
  try {
    process.waitFor();
    fail();
  } catch (ConnectionException e) {
    clientDisconnectQueue.take();
    verify(mockCommand, never()).close();
    verify(mMockSSHClient).disconnect();
    throw e;
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:26,代码来源:SSHEnvironmentTest.java

示例3: runCommandAsynchronouslyShouldProperlyShutDownConnectionOnDestroyBlockingProcess

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = ConnectionException.class)
public void runCommandAsynchronouslyShouldProperlyShutDownConnectionOnDestroyBlockingProcess()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  Command mockCommand = mock(Command.class);
  when(mockSession.exec(anyString())).thenReturn(mockCommand);
  BlockingQueue<Object> joinAnswers = new LinkedBlockingQueue<>();
  doAnswer(new BlockingAnswer(joinAnswers)).when(mockCommand).join();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  RemoteProcess process = mSSHEnv.runCommandAsynchronously(command);
  verify(mockSession).exec(contains(StringUtils.join(command, " ")));
  verify(mockCommand, never()).close();
  verify(mockSession, never()).close();
  verify(mMockSSHClient, never()).disconnect();
  process.destroy();
  verify(mMockSSHClient).disconnect();
  joinAnswers.put(new ConnectionException("unit test error"));
  process.waitFor();
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:23,代码来源:SSHEnvironmentTest.java

示例4: testExecute_2

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test
public void testExecute_2() throws Exception {
	when(client.startSession()).thenReturn(session);
	when(session.exec(anyString())).thenThrow(new ConnectionException("error!"));
	
	try {
		ssh.execute("127.0.1.1", "username", "password", "ls", "ps");
		fail();
	} catch(ConnectionException ex) {
		;
	}
	
	verify(client, times(1)).connect("127.0.1.1");
	verify(client, times(1)).authPassword("username", "password".toCharArray());
	verify(session, times(1)).exec("ls\nps\n");
	verify(command, never()).join();
	
	verify(session, times(1)).close();
	verify(client, times(1)).disconnect();
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:21,代码来源:SSHTest.java

示例5: executeCommandWithRetries

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
private Command executeCommandWithRetries(String command) throws TransportException, ConnectionException {
	int currentRetryCount = 0;
	Command cmd = null;
	
	while(true) {
		
		cmd = executeCommand(command);
		
		if (cmd == null) {
			if (currentRetryCount >= SSH_MAX_RETRY_COUNT) {
				throw new RuntimeException("Retry limit exceeded when trying to execute ssh command.");
			}
			
			++currentRetryCount;
			log.debug("Timeout when trying to execute ssh command. Will try again in " + SSH_RETRY_COOLDOWN_IN_SEC + " seconds");
			
			try {
				Thread.sleep(1000 * SSH_RETRY_COOLDOWN_IN_SEC);
			} catch (InterruptedException e1) {
				throw new RuntimeException(e1);
			}
			
			continue;
		}
		
		break;
	}
	
	return cmd;
}
 
开发者ID:openaire,项目名称:iis,代码行数:31,代码来源:SshSimpleConnection.java

示例6: runCommandFromPwdShouldThrowOnCommandFailure

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = IOException.class)
public void runCommandFromPwdShouldThrowOnCommandFailure()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  when(mockSession.exec(anyString())).thenThrow(ConnectionException.class);

  List<String> command = new ArrayList<>();
  command.add("touch");
  command.add("FILE");
  mSSHEnv.runCommand(command, ".");
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:13,代码来源:SSHEnvironmentTest.java

示例7: runCommandShouldThrowExceptionIfCommandFails

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = IOException.class)
public void runCommandShouldThrowExceptionIfCommandFails()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  Command mockCommand = mock(Command.class);
  when(mockSession.exec(anyString())).thenReturn(mockCommand);
  doThrow(new ConnectionException("mock test")).when(mockCommand).join();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  mSSHEnv.runCommand(command);
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:14,代码来源:SSHEnvironmentTest.java

示例8: runCommandShouldThrowOriginalExceptionOnFail

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = ConnectionException.class)
public void runCommandShouldThrowOriginalExceptionOnFail()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  when(mockSession.exec(anyString())).thenThrow(new ConnectionException("mock test"));
  doThrow(new IOException()).when(mMockSSHClient).disconnect();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  mSSHEnv.runCommand(command);
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:13,代码来源:SSHEnvironmentTest.java

示例9: runCommandAsynchronouslyShouldStillWorkOnSessionCloseFailure

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test
public void runCommandAsynchronouslyShouldStillWorkOnSessionCloseFailure()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  BlockingQueue clientDisconnectQueue = new LinkedBlockingQueue();
  doAnswer(new BlockingWaitAnswer(clientDisconnectQueue)).when(mMockSSHClient).disconnect();
  Command mockCommand = mock(Command.class);
  when(mockSession.exec(anyString())).thenReturn(mockCommand);
  doThrow(ConnectionException.class).when(mockSession).close();
  BlockingQueue<Object> joinAnswers = new LinkedBlockingQueue<>();
  doAnswer(new BlockingAnswer(joinAnswers)).when(mockCommand).join();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  RemoteProcess process = mSSHEnv.runCommandAsynchronously(command);
  verify(mockSession).exec(contains(StringUtils.join(command, " ")));
  verify(mockCommand, never()).close();
  verify(mockSession, never()).close();
  verify(mMockSSHClient, never()).disconnect();
  joinAnswers.add(0);
  int defaultReturnValue = 0;
  int returnValue = process.waitFor();
  assertEquals(defaultReturnValue, returnValue);
  clientDisconnectQueue.take();
  verify(mockCommand).close();
  verify(mockSession).close();
  verify(mMockSSHClient).disconnect();
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:30,代码来源:SSHEnvironmentTest.java

示例10: runCommandAsynchronouslyShouldThrowExceptionOnExecFailAndDisconnectSSHClient

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = ConnectionException.class)
public void runCommandAsynchronouslyShouldThrowExceptionOnExecFailAndDisconnectSSHClient()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  when(mockSession.exec(anyString())).thenThrow(new ConnectionException("mock test"));
  doThrow(new IOException()).when(mMockSSHClient).disconnect();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  mSSHEnv.runCommandAsynchronously(command);
  verify(mMockSSHClient).disconnect();
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:14,代码来源:SSHEnvironmentTest.java

示例11: runCommandAsynchronouslyShouldThrowExceptionOnExecFailAndDisconnectSSHClientFail

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test(expected = ConnectionException.class)
public void runCommandAsynchronouslyShouldThrowExceptionOnExecFailAndDisconnectSSHClientFail()
    throws IOException, InterruptedException {
  Session mockSession = mock(Session.class);
  when(mMockSSHClient.startSession()).thenReturn(mockSession);
  doThrow(IOException.class).when(mMockSSHClient).disconnect();
  when(mockSession.exec(anyString())).thenThrow(new ConnectionException("mock test"));
  doThrow(new IOException()).when(mMockSSHClient).disconnect();
  List<String> command = new ArrayList<>();
  command.add("echo");
  command.add("hello");
  mSSHEnv.runCommandAsynchronously(command);
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:14,代码来源:SSHEnvironmentTest.java

示例12: vcgencmd_in_path

import net.schmizz.sshj.connection.ConnectionException; //导入依赖的package包/类
@Test
public void vcgencmd_in_path() throws RaspiQueryException,
        ConnectionException, TransportException {
    String vcgencmdPath = "vcgencmd";
    sessionMocker.withCommand(vcgencmdPath, new CommandMocker()
            .withResponse("vcgencmd version 1.2.3.4").mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_clock arm",
            new CommandMocker().withResponse("frequency(45)=840090000")
                    .mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_clock core",
            new CommandMocker().withResponse("frequency(1)=320000000")
                    .mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_volts core",
            new CommandMocker().withResponse("volt=1.200V").mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_temp",
            new CommandMocker().withResponse("temp=41.2'C").mock());
    sessionMocker
            .withCommand(
                    vcgencmdPath + " version",
                    new CommandMocker()
                            .withResponse(
                                    "Dec 29 2014 14:23:10\nCopyright (c) 2012 Broadcom\nversion d3c15a3b57203798ff811c40ea65174834267d48 (clean) (release)")
                            .mock());
    VcgencmdBean vcgencmd = raspiQuery.queryVcgencmd();
    assertNotNull(vcgencmd);
    assertThat(vcgencmd.getArmFrequency(), CoreMatchers.is(840090000L));
    assertThat(vcgencmd.getCoreFrequency(), CoreMatchers.is(320000000L));
    assertEquals(1.200, vcgencmd.getCoreVolts(), 0.00001);
    assertEquals(41.2, vcgencmd.getCpuTemperature(), 0.00001);
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:31,代码来源:VcgencmdTest.java


注:本文中的net.schmizz.sshj.connection.ConnectionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。