Skip to content

Commit

Permalink
Optimize the integration test mirror code. (apache#12274)
Browse files Browse the repository at this point in the history
  • Loading branch information
totalo authored Sep 8, 2021
1 parent 2090365 commit 231d93f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public static void startUp(final String databaseType, final String scenario, fin
if (EMBEDDED_DATABASES_CACHE.containsKey(embeddedDatabaseKey)) {
return;
}
DATABASE_RESOURCE_LOCK.lock();
try {
DATABASE_RESOURCE_LOCK.lock();
startUpSafely(embeddedDatabaseKey, databaseType, embeddedDatabaseProps, port);
} finally {
DATABASE_RESOURCE_LOCK.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,15 @@ private static class InsertTask implements Callable<Void> {
private final String insertSQL;

private final Collection<SQLValueGroup> sqlValueGroups;

@Override
public Void call() throws SQLException {
try (Connection connection = dataSource.getConnection()) {
try (PreparedStatement preparedStatement = connection.prepareStatement(insertSQL)) {
for (SQLValueGroup each : sqlValueGroups) {
setParameters(preparedStatement, each);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(insertSQL)) {
for (SQLValueGroup each : sqlValueGroups) {
setParameters(preparedStatement, each);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public ZookeeperContainer(final ParameterizedArray parameterizedArray) {
* @return server list
*/
public String getServerLists() {
return "localhost:" + getMappedPort(2181);
return this.getHost() + getMappedPort(2181);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ protected void configure() {
@SneakyThrows
protected void execute() {
int time = 0;
Class.forName(getDriverClassName());
String url = DataSourceEnvironment.getURL("PostgreSQL", getHost(), getPort());
// TODO logic need prefect
while (time++ < 20) {
Class.forName(getDriverClassName());
try (Connection ignored = DriverManager.getConnection(DataSourceEnvironment.getURL("PostgreSQL", getHost(), getPort()), getUsername(), getPassword())) {
try (Connection ignored = DriverManager.getConnection(url, getUsername(), getPassword())) {
break;
} catch (PSQLException ex) {
Thread.sleep(1000);
Thread.sleep(1000L);
}
}
}
Expand Down

0 comments on commit 231d93f

Please sign in to comment.