use of java.net.ConnectException in project hbase by apache.
the class TestIPCUtil method testWrapException.
@Test
public void testWrapException() throws Exception {
final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0);
assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException);
assertTrue(wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException);
assertTrue(wrapException(address, new ConnectionClosingException("Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException);
assertTrue(wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")).getCause() instanceof CallTimeoutException);
}
use of java.net.ConnectException in project hbase by apache.
the class MetaTableLocator method verifyRegionLocation.
/**
* Verify we can connect to <code>hostingServer</code> and that its carrying
* <code>regionName</code>.
* @param hostingServer Interface to the server hosting <code>regionName</code>
* @param address The servername that goes with the <code>metaServer</code>
* Interface. Used logging.
* @param regionName The regionname we are interested in.
* @return True if we were able to verify the region located at other side of
* the Interface.
* @throws IOException
*/
// TODO: We should be able to get the ServerName from the AdminProtocol
// rather than have to pass it in. Its made awkward by the fact that the
// HRI is likely a proxy against remote server so the getServerName needs
// to be fixed to go to a local method or to a cache before we can do this.
private boolean verifyRegionLocation(final ClusterConnection connection, AdminService.BlockingInterface hostingServer, final ServerName address, final byte[] regionName) throws IOException {
if (hostingServer == null) {
LOG.info("Passed hostingServer is null");
return false;
}
Throwable t;
HBaseRpcController controller = connection.getRpcControllerFactory().newController();
try {
// Try and get regioninfo from the hosting server.
return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) != null;
} catch (ConnectException e) {
t = e;
} catch (RetriesExhaustedException e) {
t = e;
} catch (RemoteException e) {
IOException ioe = e.unwrapRemoteException();
t = ioe;
} catch (IOException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof EOFException) {
t = cause;
} else if (cause != null && cause.getMessage() != null && cause.getMessage().contains("Connection reset")) {
t = cause;
} else {
t = e;
}
}
LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) + " at address=" + address + ", exception=" + t.getMessage());
return false;
}
use of java.net.ConnectException in project tomcat by apache.
the class SetParentClassLoaderRule method stopServer.
public void stopServer(String[] arguments) {
if (arguments != null) {
arguments(arguments);
}
Server s = getServer();
if (s == null) {
// Create and execute our Digester
Digester digester = createStopDigester();
File file = configFile();
try (FileInputStream fis = new FileInputStream(file)) {
InputSource is = new InputSource(file.toURI().toURL().toString());
is.setByteStream(fis);
digester.push(this);
digester.parse(is);
} catch (Exception e) {
log.error("Catalina.stop: ", e);
System.exit(1);
}
} else {
// Server object already present. Must be running as a service
try {
s.stop();
} catch (LifecycleException e) {
log.error("Catalina.stop: ", e);
}
return;
}
// Stop the existing server
s = getServer();
if (s.getPort() > 0) {
try (Socket socket = new Socket(s.getAddress(), s.getPort());
OutputStream stream = socket.getOutputStream()) {
String shutdown = s.getShutdown();
for (int i = 0; i < shutdown.length(); i++) {
stream.write(shutdown.charAt(i));
}
stream.flush();
} catch (ConnectException ce) {
log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(), String.valueOf(s.getPort())));
log.error("Catalina.stop: ", ce);
System.exit(1);
} catch (IOException e) {
log.error("Catalina.stop: ", e);
System.exit(1);
}
} else {
log.error(sm.getString("catalina.stopServer"));
System.exit(1);
}
}
use of java.net.ConnectException in project head by mifos.
the class MifosExecutableWARBasicTest method testExecutableWARStartup.
@Test
public void testExecutableWARStartup() throws IOException, InterruptedException {
// maven-dependency-plugin (see pom.xml) copied it:
final File warFile = new File("target/dependency/mifos.war");
assertTrue(warFile.toString() + " does not exist", warFile.exists());
int httpPort = 4847;
// Give it max. 5 min to start-up
Long timeOut = 5 * 60 * 1000L;
// Could have used http://commons.apache.org/exec/ instead here, but this seemed easier:
long startTime = System.currentTimeMillis();
final String execWARFilePath = warFile.getAbsolutePath();
final String port = Integer.toString(httpPort);
List<String> args = new ArrayList<String>();
args.add("java");
args.add("-jar");
args.add("-Xmx512M");
args.add("-XX:MaxPermSize=256m");
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
args.add("-d32");
}
args.add(execWARFilePath);
args.add(port);
final ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.redirectErrorStream(true);
Process p = processBuilder.start();
URL url = new URL("http://localhost:" + httpPort + "/mifos");
// Now either wait until the server is up on httpPort OR timeOut is reached
boolean keepGoing = true;
InputStream is = p.getInputStream();
do {
// Pipe process output to console
while (is.available() > 0) {
System.out.write(is.read());
}
// Check if the server is up and running
try {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
int r = con.getResponseCode();
if (r == 200 || r == 302) {
// Yeah, we're up and running! So shutdown now.
p.destroy();
keepGoing = false;
}
} catch (ConnectException e) {
// Oh well; not ready yet, never mind, ignore it and move on.
}
// Has the server died on it's own already may be?
try {
int exitValue = p.exitValue();
if (exitValue != 0) {
fail("Server Process died (unexpectedly), return code: " + exitValue);
}
} catch (IllegalThreadStateException e) {
// Great, it's still running; so move on.
}
// Have we hit time out?
if (System.currentTimeMillis() - startTime > timeOut) {
p.destroy();
fail("Giving up after " + timeOut + "ms; as Server Process is still not responding on " + url);
}
// Now have a rest before trying again
Thread.sleep(1000);
} while (keepGoing);
}
use of java.net.ConnectException in project failsafe by jhalterman.
the class RetryPolicyTest method testCanAbortForFailurePredicate.
public void testCanAbortForFailurePredicate() {
RetryPolicy policy = new RetryPolicy().abortOn(failure -> failure instanceof ConnectException);
assertTrue(policy.canAbortFor(null, new ConnectException()));
assertFalse(policy.canAbortFor(null, new IllegalArgumentException()));
}
Aggregations