Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,31 @@ public interface StorageContainerConfigurationOption extends DatabaseTypedSPI {
* @return container startup timeout seconds
*/
long getStartupTimeoutSeconds();

/**
* Whether support docker entrypoint.
*
* @return is support docker entrypoint or not
*/
default boolean isSupportDockerEntrypoint() {
return true;
}

/**
* Get default user when unsupported docker entrypoint.
*
* @return default user
*/
default Optional<String> getDefaultUserWhenUnsupportedDockerEntrypoint() {
return Optional.empty();
}

/**
* Get default password when unsupported docker entrypoint.
*
* @return default password
*/
default Optional<String> getDefaultPasswordWhenUnsupportedDockerEntrypoint() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,29 @@ public boolean withPrivilegedMode() {

@Override
public Optional<String> getDefaultDatabaseName(final int majorVersion) {
return Optional.empty();
return Optional.of("default");
}

@Override
public long getStartupTimeoutSeconds() {
return 180L;
}

@Override
public boolean isSupportDockerEntrypoint() {
return false;
}

@Override
public Optional<String> getDefaultUserWhenUnsupportedDockerEntrypoint() {
return Optional.of("");
}

@Override
public Optional<String> getDefaultPasswordWhenUnsupportedDockerEntrypoint() {
return Optional.of("");
}

@Override
public String getDatabaseType() {
return "Hive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.docker;

import com.github.dockerjava.api.command.InspectContainerResponse;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer;
Expand All @@ -29,14 +31,17 @@
import org.apache.shardingsphere.test.e2e.env.container.atomic.storage.mount.MountSQLResourceGenerator;
import org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option.StorageContainerConfigurationOption;
import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DockerImageVersion;
import org.apache.shardingsphere.test.e2e.env.container.atomic.util.SQLScriptUtils;
import org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
import org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
import org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager;
import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -81,10 +86,17 @@ protected final void configure() {
setCommands();
addEnvironments();
mapResources(new MountConfigurationResourceGenerator(option).generate(majorVersion, scenario));
mapResources(new MountSQLResourceGenerator(option).generate(majorVersion, scenario));
if (option.isSupportDockerEntrypoint()) {
mapResources(new MountSQLResourceGenerator(option).generate(majorVersion, scenario));
}
setPrivilegedMode();
withExposedPorts(getExposedPort());
setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(), StorageContainerConstants.CHECK_READY_USER, StorageContainerConstants.CHECK_READY_PASSWORD)));
if (option.isSupportDockerEntrypoint()) {
setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(), StorageContainerConstants.CHECK_READY_USER, StorageContainerConstants.CHECK_READY_PASSWORD)));
} else {
setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(),
option.getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""), option.getDefaultPasswordWhenUnsupportedDockerEntrypoint().orElse(""))));
}
withStartupTimeout(Duration.ofSeconds(option.getStartupTimeoutSeconds()));
}

Expand Down Expand Up @@ -112,6 +124,22 @@ private String getURL() {
.orElseGet(() -> dataSourceEnvironment.getURL("localhost", getFirstMappedPort()));
}

@SneakyThrows({SQLException.class, InterruptedException.class})
@Override
protected final void containerIsStarted(final InspectContainerResponse containerInfo) {
if (option.isSupportDockerEntrypoint()) {
return;
}
Thread.sleep(10000L);
try (
Connection connection = DriverManager.getConnection(DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, option.getType()).getURL("localhost", getFirstMappedPort()),
option.getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""), option.getDefaultPasswordWhenUnsupportedDockerEntrypoint().orElse(""))) {
for (String each : new MountSQLResourceGenerator(option).generate(majorVersion, scenario).keySet()) {
SQLScriptUtils.execute(connection, each);
}
}
}

@Override
protected void postStart() {
actualDataSourceMap.putAll(createAccessDataSources(getDataSourceNames(getDataSourceNameAndTypeMap(Type.ACTUAL))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public static void execute(final DataSource dataSource, final String scriptFileP
}
}

/**
* Execute SQL script.
*
* @param connection connection
* @param scriptFilePath script file path
*/
@SneakyThrows({SQLException.class, IOException.class})
public static void execute(final Connection connection, final String scriptFilePath) {
executeBatch(connection, readSQLs(scriptFilePath));
}

private static Collection<String> readSQLs(final String scriptFilePath) throws IOException {
Collection<String> result = new LinkedList<>();
try (
Expand Down

This file was deleted.