-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add end-to-end test for Presto on Spark using Docker
- Loading branch information
Showing
7 changed files
with
876 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>presto-root</artifactId> | ||
<groupId>com.facebook.presto</groupId> | ||
<version>0.232-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>presto-spark-testing</artifactId> | ||
|
||
<properties> | ||
<air.main.basedir>${project.parent.basedir}</air.main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>units</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.airlift</groupId> | ||
<artifactId>log</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.airlift</groupId> | ||
<artifactId>testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-tests</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-main</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-spi</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-tpch</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-hive-hadoop2</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto.hadoop</groupId> | ||
<artifactId>hadoop-apache2</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>joda-time</groupId> | ||
<artifactId>joda-time</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Just to make sure these two packages are built before the presto-spark-testing --> | ||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-spark-launcher</artifactId> | ||
<version>${project.version}</version> | ||
<type>jar</type> | ||
<classifier>shaded</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.facebook.presto</groupId> | ||
<artifactId>presto-spark-package</artifactId> | ||
<version>${project.version}</version> | ||
<type>tar.gz</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.basepom.maven</groupId> | ||
<artifactId>duplicate-finder-maven-plugin</artifactId> | ||
<configuration> | ||
<ignoredResourcePatterns> | ||
<ignoredResourcePattern>parquet.thrift</ignoredResourcePattern> | ||
<ignoredResourcePattern>about.html</ignoredResourcePattern> | ||
</ignoredResourcePatterns> | ||
</configuration> | ||
</plugin> | ||
|
||
<!-- Workaround for "Corrupted STDOUT by directly writing to native stream in forked JVM 1" --> | ||
<!-- https://stackoverflow.com/questions/55632614/maven-surefire-plugin-crahsing-jvm-on-java-11-corrupted-stdout-by-directly-writ --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<forkCount>0</forkCount> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
154 changes: 154 additions & 0 deletions
154
presto-spark-testing/src/main/java/com/facebook/presto/spark/testing/DockerCompose.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.spark.testing; | ||
|
||
import com.google.common.base.Splitter; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static com.facebook.presto.spark.testing.Processes.startProcess; | ||
import static com.facebook.presto.spark.testing.Processes.waitForProcess; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.lang.String.format; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DockerCompose | ||
{ | ||
private final File composeYaml; | ||
|
||
public DockerCompose(File composeYaml) | ||
{ | ||
requireNonNull(composeYaml, "composeYaml is null"); | ||
checkArgument(composeYaml.exists() && composeYaml.isFile(), "file does not exist: %s", composeYaml); | ||
checkArgument(composeYaml.canRead(), "file is not readable: %s", composeYaml); | ||
this.composeYaml = composeYaml; | ||
} | ||
|
||
public void verifyInstallation() | ||
throws InterruptedException | ||
{ | ||
checkState(Processes.execute("docker", "--version") == 0, "docker is not installed"); | ||
checkState(Processes.execute("docker-compose", "--version") == 0, "docker-compose is not installed"); | ||
} | ||
|
||
public void pull() | ||
throws InterruptedException | ||
{ | ||
int exitCode = execute("pull"); | ||
checkState(exitCode == 0, "pull existed with code: %s", exitCode); | ||
} | ||
|
||
public Process up(Map<String, Integer> services) | ||
{ | ||
ImmutableList.Builder<String> parameters = ImmutableList.builder(); | ||
parameters.add("up", "--force-recreate", "--abort-on-container-exit"); | ||
services.forEach((service, scale) -> { | ||
parameters.add("--scale", format("%s=%s", service, scale)); | ||
}); | ||
parameters.addAll(services.keySet()); | ||
return start(parameters.build()); | ||
} | ||
|
||
public void down() | ||
throws InterruptedException | ||
{ | ||
int exitCode = execute("down"); | ||
checkState(exitCode == 0, "down existed with code: %s", exitCode); | ||
} | ||
|
||
public String getContainerAddress(String service) | ||
throws InterruptedException | ||
{ | ||
String containerId = getContainerId(service); | ||
return Processes.executeForOutput("docker", "inspect", "-f", "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", containerId).trim(); | ||
} | ||
|
||
public int run(String... parameters) | ||
throws InterruptedException | ||
{ | ||
return run(ImmutableList.copyOf(parameters)); | ||
} | ||
|
||
public int run(List<String> parameters) | ||
throws InterruptedException | ||
{ | ||
ImmutableList.Builder<String> args = ImmutableList.builder(); | ||
args.add("run", "--rm"); | ||
args.addAll(parameters); | ||
return execute(args.build()); | ||
} | ||
|
||
private String getContainerId(String service) | ||
throws InterruptedException | ||
{ | ||
List<String> containerIds = getContainerIds(); | ||
for (String containerId : containerIds) { | ||
String output = Processes.executeForOutput( | ||
"docker", | ||
"ps", "-q", | ||
"--filter", format("id=%s", containerId), | ||
"--filter", format("name=%s", service)); | ||
if (!output.isEmpty()) { | ||
return containerId; | ||
} | ||
} | ||
throw new IllegalArgumentException(format("container not found: %s", service)); | ||
} | ||
|
||
private List<String> getContainerIds() | ||
throws InterruptedException | ||
{ | ||
String output = executeForOutput("ps", "-q"); | ||
return Splitter.on('\n').trimResults().omitEmptyStrings().splitToList(output); | ||
} | ||
|
||
private int execute(String... args) | ||
throws InterruptedException | ||
{ | ||
return execute(ImmutableList.copyOf(args)); | ||
} | ||
|
||
private int execute(List<String> args) | ||
throws InterruptedException | ||
{ | ||
return waitForProcess(start(args)); | ||
} | ||
|
||
private String executeForOutput(String... args) | ||
throws InterruptedException | ||
{ | ||
return executeForOutput(ImmutableList.copyOf(args)); | ||
} | ||
|
||
private String executeForOutput(List<String> args) | ||
throws InterruptedException | ||
{ | ||
return Processes.executeForOutput(ImmutableList.<String>builder() | ||
.add("docker-compose", "-f", composeYaml.getAbsolutePath()) | ||
.addAll(args) | ||
.build()); | ||
} | ||
|
||
private Process start(List<String> args) | ||
{ | ||
return startProcess(ImmutableList.<String>builder() | ||
.add("docker-compose", "-f", composeYaml.getAbsolutePath()) | ||
.addAll(args) | ||
.build()); | ||
} | ||
} |
Oops, something went wrong.