YARN-11634. [Addendum] Speed-up TestTimelineClient. (#6419)

Co-authored-by: slfan1989 <slfan1989@apache.org>
This commit is contained in:
slfan1989 2024-01-15 15:44:17 +08:00 committed by GitHub
parent 0f8b74b03f
commit 6ebce65ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 16 deletions

View File

@ -459,4 +459,10 @@ public class TimelineClientImpl extends TimelineClient {
public void setTimelineWriter(TimelineWriter writer) {
this.timelineWriter = writer;
}
@Private
@VisibleForTesting
public TimelineConnector getConnector() {
return connector;
}
}

View File

@ -78,8 +78,8 @@ public class TimelineConnector extends AbstractService {
private static final Joiner JOINER = Joiner.on("");
private static final Logger LOG =
LoggerFactory.getLogger(TimelineConnector.class);
@VisibleForTesting
public static int DEFAULT_SOCKET_TIMEOUT = 60_000; // 1 minute
private int socketTimeOut = 60_000;
private SSLFactory sslFactory;
Client client;
@ -113,7 +113,7 @@ public class TimelineConnector extends AbstractService {
sslFactory = getSSLFactory(conf);
connConfigurator = getConnConfigurator(sslFactory);
} else {
connConfigurator = DEFAULT_TIMEOUT_CONN_CONFIGURATOR;
connConfigurator = defaultTimeoutConnConfigurator;
}
String defaultAuth = UserGroupInformation.isSecurityEnabled() ?
KerberosAuthenticationHandler.TYPE :
@ -140,23 +140,18 @@ public class TimelineConnector extends AbstractService {
}
}
private static final ConnectionConfigurator DEFAULT_TIMEOUT_CONN_CONFIGURATOR
= new ConnectionConfigurator() {
@Override
public HttpURLConnection configure(HttpURLConnection conn)
throws IOException {
setTimeouts(conn, DEFAULT_SOCKET_TIMEOUT);
return conn;
}
};
private ConnectionConfigurator defaultTimeoutConnConfigurator = conn -> {
setTimeouts(conn, socketTimeOut);
return conn;
};
private ConnectionConfigurator getConnConfigurator(SSLFactory sslFactoryObj) {
try {
return initSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT, sslFactoryObj);
return initSslConnConfigurator(socketTimeOut, sslFactoryObj);
} catch (Exception e) {
LOG.debug("Cannot load customized ssl related configuration. "
+ "Fallback to system-generic settings.", e);
return DEFAULT_TIMEOUT_CONN_CONFIGURATOR;
return defaultTimeoutConnConfigurator;
}
}
@ -457,4 +452,9 @@ public class TimelineConnector extends AbstractService {
|| e instanceof SocketTimeoutException);
}
}
@VisibleForTesting
public void setSocketTimeOut(int socketTimeOut) {
this.socketTimeOut = socketTimeOut;
}
}

View File

@ -78,7 +78,7 @@ public class TestTimelineClient {
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 1.0f);
client = createTimelineClient(conf);
TimelineConnector.DEFAULT_SOCKET_TIMEOUT = 10;
client.getConnector().setSocketTimeOut(10);
}
@AfterEach
@ -89,7 +89,7 @@ public class TestTimelineClient {
if (isSSLConfigured()) {
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}
TimelineConnector.DEFAULT_SOCKET_TIMEOUT = 60_000;
client.getConnector().setSocketTimeOut(60_000);
}
@Test