HADOOP-15787. TestIPC.testRTEDuringConnectionSetup fails with jdk8u242. Contributed by Zsolt Venczel.
(cherry picked from commita463cf75a0
) (cherry picked from commit0b19c8e086
)
This commit is contained in:
parent
466f77a5cf
commit
a628ab0863
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -641,6 +640,16 @@ public class TestIPC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock socket class to help inject an exception for HADOOP-7428.
|
||||||
|
*/
|
||||||
|
static class MockSocket extends Socket {
|
||||||
|
@Override
|
||||||
|
public synchronized void setSoTimeout(int timeout) {
|
||||||
|
throw new RuntimeException("Injected fault");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that, if a RuntimeException is thrown after creating a socket
|
* Test that, if a RuntimeException is thrown after creating a socket
|
||||||
* but before successfully connecting to the IPC server, that the
|
* but before successfully connecting to the IPC server, that the
|
||||||
|
@ -654,11 +663,8 @@ public class TestIPC {
|
||||||
SocketFactory spyFactory = spy(NetUtils.getDefaultSocketFactory(conf));
|
SocketFactory spyFactory = spy(NetUtils.getDefaultSocketFactory(conf));
|
||||||
Mockito.doAnswer(new Answer<Socket>() {
|
Mockito.doAnswer(new Answer<Socket>() {
|
||||||
@Override
|
@Override
|
||||||
public Socket answer(InvocationOnMock invocation) throws Throwable {
|
public Socket answer(InvocationOnMock invocation) {
|
||||||
Socket s = spy((Socket)invocation.callRealMethod());
|
return new MockSocket();
|
||||||
doThrow(new RuntimeException("Injected fault")).when(s)
|
|
||||||
.setSoTimeout(anyInt());
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}).when(spyFactory).createSocket();
|
}).when(spyFactory).createSocket();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue