HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@939018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f1fee1804a
commit
cd85fc46dc
|
@ -373,6 +373,9 @@ Trunk (unreleased changes)
|
|||
HADOOP-6719. Insert all missing methods in FilterFs.
|
||||
(Rodrigo Schmidt via dhruba)
|
||||
|
||||
HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory.
|
||||
(Todd Lipcon via tomwhite)
|
||||
|
||||
Release 0.21.0 - Unreleased
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -494,10 +494,12 @@ public class Client {
|
|||
private void handleConnectionFailure(
|
||||
int curRetries, int maxRetries, IOException ioe) throws IOException {
|
||||
// close the current connection
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Not able to close a socket", e);
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Not able to close a socket", e);
|
||||
}
|
||||
}
|
||||
// set socket to null so that the next call to setupIOstreams
|
||||
// can start the process of connect all over again.
|
||||
|
|
|
@ -29,8 +29,10 @@ import java.util.Random;
|
|||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
||||
|
@ -267,6 +269,25 @@ public class TestIPC extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that, if the socket factory throws an IOE, it properly propagates
|
||||
* to the client.
|
||||
*/
|
||||
public void testSocketFactoryException() throws Exception {
|
||||
SocketFactory mockFactory = mock(SocketFactory.class);
|
||||
doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
|
||||
Client client = new Client(LongWritable.class, conf, mockFactory);
|
||||
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
|
||||
try {
|
||||
client.call(new LongWritable(RANDOM.nextLong()),
|
||||
address, null, null);
|
||||
fail("Expected an exception to have been thrown");
|
||||
} catch (IOException e) {
|
||||
assertTrue(e.getMessage().contains("Injected fault"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue