use of org.apache.tez.http.HttpConnectionParams in project tez by apache.
the class TestFetcher method testAsyncWithException.
@Test
@SuppressWarnings("unchecked")
public void testAsyncWithException() throws Exception {
Configuration conf = new TezConfiguration();
conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT, 3000);
conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_CONNECT_TIMEOUT, 3000);
ShuffleScheduler scheduler = mock(ShuffleScheduler.class);
MergeManager merger = mock(MergeManager.class);
Shuffle shuffle = mock(Shuffle.class);
TezCounters counters = new TezCounters();
InputContext inputContext = mock(InputContext.class);
when(inputContext.getCounters()).thenReturn(counters);
when(inputContext.getSourceVertexName()).thenReturn("");
JobTokenSecretManager jobMgr = mock(JobTokenSecretManager.class);
doReturn(new byte[10]).when(jobMgr).computeHash(any(byte[].class));
HttpConnectionParams httpConnectionParams = ShuffleUtils.getHttpConnectionParams(conf);
final MapHost host = new MapHost(HOST, PORT, 1, 1);
FetcherOrderedGrouped mockFetcher = new FetcherOrderedGrouped(httpConnectionParams, scheduler, merger, shuffle, jobMgr, false, 0, null, conf, false, HOST, PORT, "src vertex", host, ioErrsCounter, wrongLengthErrsCounter, badIdErrsCounter, wrongMapErrsCounter, connectionErrsCounter, wrongReduceErrsCounter, APP_ID, DAG_ID, true, false, true, false);
final FetcherOrderedGrouped fetcher = spy(mockFetcher);
fetcher.remaining = new LinkedHashMap<String, InputAttemptIdentifier>();
final List<InputAttemptIdentifier> srcAttempts = Arrays.asList(new InputAttemptIdentifier(0, 1, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_0"), new InputAttemptIdentifier(1, 2, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_1"), new InputAttemptIdentifier(3, 4, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_3"));
doReturn(srcAttempts).when(scheduler).getMapsForHost(host);
try {
long currentIOErrors = ioErrsCounter.getValue();
boolean connected = fetcher.setupConnection(host, srcAttempts);
Assert.assertTrue(connected == false);
// Ensure that counters are incremented (i.e it followed the exception codepath)
Assert.assertTrue(ioErrsCounter.getValue() > currentIOErrors);
} catch (IOException e) {
fail();
}
}
use of org.apache.tez.http.HttpConnectionParams in project tez by apache.
the class TezRuntimeUtils method getHttpConnectionParams.
public static HttpConnectionParams getHttpConnectionParams(Configuration conf) {
int connectionTimeout = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_CONNECT_TIMEOUT, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_STALLED_COPY_TIMEOUT_DEFAULT);
int readTimeout = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT_DEFAULT);
int bufferSize = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_BUFFER_SIZE, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_BUFFER_SIZE_DEFAULT);
boolean keepAlive = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_ENABLED, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_ENABLED_DEFAULT);
int keepAliveMaxConnections = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_MAX_CONNECTIONS, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_MAX_CONNECTIONS_DEFAULT);
if (keepAlive) {
System.setProperty("sun.net.http.errorstream.enableBuffering", "true");
System.setProperty("http.maxConnections", String.valueOf(keepAliveMaxConnections));
}
boolean sslShuffle = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_ENABLE_SSL, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_ENABLE_SSL_DEFAULT);
if (sslShuffle) {
if (sslFactory == null) {
synchronized (HttpConnectionParams.class) {
// Create sslFactory if it is null or if it was destroyed earlier
if (sslFactory == null || sslFactory.getKeystoresFactory().getTrustManagers() == null) {
sslFactory = new SSLFactory(org.apache.hadoop.security.ssl.SSLFactory.Mode.CLIENT, conf);
try {
sslFactory.init();
} catch (Exception ex) {
sslFactory.destroy();
sslFactory = null;
throw new RuntimeException(ex);
}
}
}
}
}
HttpConnectionParams httpConnParams = new HttpConnectionParams(keepAlive, keepAliveMaxConnections, connectionTimeout, readTimeout, bufferSize, sslShuffle, sslFactory);
return httpConnParams;
}
use of org.apache.tez.http.HttpConnectionParams in project tez by apache.
the class TestFetcher method testWithRetry.
@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void testWithRetry() throws Exception {
Configuration conf = new TezConfiguration();
conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT, 3000);
conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_CONNECT_TIMEOUT, 3000);
ShuffleScheduler scheduler = mock(ShuffleScheduler.class);
MergeManager merger = mock(MergeManager.class);
Shuffle shuffle = mock(Shuffle.class);
InputContext inputContext = mock(InputContext.class);
when(inputContext.getCounters()).thenReturn(new TezCounters());
when(inputContext.getSourceVertexName()).thenReturn("");
when(inputContext.getApplicationId()).thenReturn(ApplicationId.newInstance(0, 1));
HttpConnectionParams httpConnectionParams = ShuffleUtils.getHttpConnectionParams(conf);
final MapHost host = new MapHost(HOST, PORT, 1, 1);
FetcherOrderedGrouped mockFetcher = new FetcherOrderedGrouped(null, scheduler, merger, shuffle, null, false, 0, null, conf, false, HOST, PORT, "src vertex", host, ioErrsCounter, wrongLengthErrsCounter, badIdErrsCounter, wrongMapErrsCounter, connectionErrsCounter, wrongReduceErrsCounter, APP_ID, DAG_ID, false, false, true, false);
final FetcherOrderedGrouped fetcher = spy(mockFetcher);
final List<InputAttemptIdentifier> srcAttempts = Arrays.asList(new InputAttemptIdentifier(0, 1, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_0"), new InputAttemptIdentifier(1, 2, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_1"), new InputAttemptIdentifier(3, 4, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_3"));
doReturn(srcAttempts).when(scheduler).getMapsForHost(host);
doReturn(true).when(fetcher).setupConnection(any(MapHost.class), any(Collection.class));
URL url = ShuffleUtils.constructInputURL("http://" + HOST + ":" + PORT + "/mapOutput?job=job_123&&reduce=1&map=", srcAttempts, false);
fetcher.httpConnection = new FakeHttpConnection(url, null, "", null);
doAnswer(new Answer<MapOutput>() {
@Override
public MapOutput answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
MapOutput mapOutput = mock(MapOutput.class);
doReturn(MapOutput.Type.MEMORY).when(mapOutput).getType();
doReturn(args[0]).when(mapOutput).getAttemptIdentifier();
return mapOutput;
}
}).when(merger).reserve(any(InputAttemptIdentifier.class), anyInt(), anyInt(), anyInt());
// Create read timeout when reading data
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
// Emulate host down for 4 seconds.
Thread.sleep(4000);
doReturn(false).when(fetcher).setupConnection(any(MapHost.class), any(Collection.class));
// Throw IOException when fetcher tries to connect again to the same node
throw new FetcherReadTimeoutException("creating fetcher socket read timeout exception");
}
}).when(fetcher).copyMapOutput(any(MapHost.class), any(DataInputStream.class), any(InputAttemptIdentifier.class));
try {
fetcher.copyFromHost(host);
} catch (IOException e) {
// ignore
}
// setup connection should be called twice (1 for connect and another for retry)
verify(fetcher, times(2)).setupConnection(any(MapHost.class), any(Collection.class));
// since copyMapOutput consistently fails, it should call copyFailed once
verify(scheduler, times(1)).copyFailed(any(InputAttemptIdentifier.class), any(MapHost.class), anyBoolean(), anyBoolean(), anyBoolean());
verify(fetcher, times(1)).putBackRemainingMapOutputs(any(MapHost.class));
verify(scheduler, times(3)).putBackKnownMapOutput(any(MapHost.class), any(InputAttemptIdentifier.class));
// Verify by stopping the fetcher abruptly
try {
// flag to indicate fetcher stopped
fetcher.stopped = false;
fetcher.copyFromHost(host);
verify(fetcher, times(2)).putBackRemainingMapOutputs(any(MapHost.class));
} catch (IOException e) {
// ignore
}
}
Aggregations