|
@@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.DataOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.net.URL;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
@@ -70,6 +71,54 @@ public class TestFetcher {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Test(timeout=30000)
|
|
|
+ public void testCopyFromHostConnectionTimeout() throws Exception {
|
|
|
+ LOG.info("testCopyFromHostConnectionTimeout");
|
|
|
+ JobConf job = new JobConf();
|
|
|
+ TaskAttemptID id = TaskAttemptID.forName("attempt_0_1_r_1_1");
|
|
|
+ ShuffleScheduler<Text, Text> ss = mock(ShuffleScheduler.class);
|
|
|
+ MergeManager<Text, Text> mm = mock(MergeManager.class);
|
|
|
+ Reporter r = mock(Reporter.class);
|
|
|
+ ShuffleClientMetrics metrics = mock(ShuffleClientMetrics.class);
|
|
|
+ ExceptionReporter except = mock(ExceptionReporter.class);
|
|
|
+ SecretKey key = JobTokenSecretManager.createSecretKey(new byte[]{0,0,0,0});
|
|
|
+ HttpURLConnection connection = mock(HttpURLConnection.class);
|
|
|
+ when(connection.getInputStream()).thenThrow(
|
|
|
+ new SocketTimeoutException("This is a fake timeout :)"));
|
|
|
+
|
|
|
+ Counters.Counter allErrs = mock(Counters.Counter.class);
|
|
|
+ when(r.getCounter(anyString(), anyString()))
|
|
|
+ .thenReturn(allErrs);
|
|
|
+
|
|
|
+ Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(job, id, ss, mm,
|
|
|
+ r, metrics, except, key, connection);
|
|
|
+
|
|
|
+ MapHost host = new MapHost("localhost", "http://localhost:8080/");
|
|
|
+
|
|
|
+ ArrayList<TaskAttemptID> maps = new ArrayList<TaskAttemptID>(1);
|
|
|
+ TaskAttemptID map1ID = TaskAttemptID.forName("attempt_0_1_m_1_1");
|
|
|
+ maps.add(map1ID);
|
|
|
+ TaskAttemptID map2ID = TaskAttemptID.forName("attempt_0_1_m_2_1");
|
|
|
+ maps.add(map2ID);
|
|
|
+ when(ss.getMapsForHost(host)).thenReturn(maps);
|
|
|
+
|
|
|
+ String encHash = "vFE234EIFCiBgYs2tCXY/SjT8Kg=";
|
|
|
+
|
|
|
+ underTest.copyFromHost(host);
|
|
|
+
|
|
|
+ verify(connection)
|
|
|
+ .addRequestProperty(SecureShuffleUtils.HTTP_HEADER_URL_HASH,
|
|
|
+ encHash);
|
|
|
+
|
|
|
+ verify(allErrs).increment(1);
|
|
|
+ verify(ss).copyFailed(map1ID, host, false, false);
|
|
|
+ verify(ss).copyFailed(map2ID, host, false, false);
|
|
|
+
|
|
|
+ verify(ss).putBackKnownMapOutput(any(MapHost.class), eq(map1ID));
|
|
|
+ verify(ss).putBackKnownMapOutput(any(MapHost.class), eq(map2ID));
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Test
|
|
|
public void testCopyFromHostBogusHeader() throws Exception {
|