|
36 | 36 | import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type; |
37 | 37 |
|
38 | 38 | import javax.sql.DataSource; |
| 39 | +import java.io.IOException; |
| 40 | +import lombok.extern.slf4j.Slf4j; |
39 | 41 | import java.sql.DriverManager; |
40 | 42 | import java.time.Duration; |
41 | 43 | import java.util.Collection; |
|
50 | 52 | /** |
51 | 53 | * Docker storage container. |
52 | 54 | */ |
| 55 | +@Slf4j |
53 | 56 | public class DockerStorageContainer extends DockerITContainer implements StorageContainer { |
54 | 57 |
|
55 | 58 | private final StorageContainerConfigurationOption option; |
@@ -114,10 +117,26 @@ private String getURL() { |
114 | 117 |
|
115 | 118 | @Override |
116 | 119 | protected void postStart() { |
| 120 | + if ("Hive".equalsIgnoreCase(option.getDatabaseType())) { |
| 121 | + executeHiveMountedSQLScripts(); |
| 122 | + } |
117 | 123 | actualDataSourceMap.putAll(createAccessDataSources(getDataSourceNames(getDataSourceNameAndTypeMap(Type.ACTUAL)))); |
118 | 124 | expectedDataSourceMap.putAll(createAccessDataSources(getDataSourceNames(getDataSourceNameAndTypeMap(Type.EXPECTED)))); |
119 | 125 | } |
120 | 126 |
|
| 127 | + private void executeHiveMountedSQLScripts() { |
| 128 | + try { |
| 129 | + execInContainer("bash", "-c", |
| 130 | + "if [ -f /docker-entrypoint-initdb.d/50-scenario-actual-init.sql ]; then beeline -u \"jdbc:hive2://localhost:10000/default\" -f " |
| 131 | + + "/docker-entrypoint-initdb.d/50-scenario-actual-init.sql; fi"); |
| 132 | + execInContainer("bash", "-c", |
| 133 | + "if [ -f /docker-entrypoint-initdb.d/60-scenario-expected-init.sql ]; then beeline -u \"jdbc:hive2://localhost:10000/default\" -f " |
| 134 | + + "/docker-entrypoint-initdb.d/60-scenario-expected-init.sql; fi"); |
| 135 | + } catch (final InterruptedException | IOException ex) { |
| 136 | + log.warn("Hive init scripts execution failed.", ex); |
| 137 | + } |
| 138 | + } |
| 139 | + |
121 | 140 | private Map<String, DatabaseType> getDataSourceNameAndTypeMap(final Type type) { |
122 | 141 | return null == scenario ? Collections.emptyMap() : DatabaseEnvironmentManager.getDatabaseTypes(scenario, option.getType(), type); |
123 | 142 | } |
|
0 commit comments