Skip to content

Commit

Permalink
Introduce presto product tests suite
Browse files Browse the repository at this point in the history
Patch introduces bunch of product tests based on tempto
testing framework.
  • Loading branch information
kokosing authored and martint committed Nov 5, 2015
1 parent 1f9d4a6 commit c71bd92
Show file tree
Hide file tree
Showing 495 changed files with 26,816 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -20,3 +20,4 @@ benchmark_outputs
*.pyc
*.class
.checkstyle
*-local.yaml
31 changes: 31 additions & 0 deletions pom.xml
Expand Up @@ -88,6 +88,7 @@
<module>presto-ml</module>
<module>presto-benchmark</module>
<module>presto-tests</module>
<module>presto-product-tests</module>
<module>presto-jdbc</module>
<module>presto-cli</module>
<module>presto-benchmark-driver</module>
Expand Down Expand Up @@ -237,6 +238,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-product-tests</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.facebook.presto.hadoop</groupId>
<artifactId>hadoop-apache1</artifactId>
Expand Down Expand Up @@ -665,6 +672,30 @@
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.teradata.tempto</groupId>
<artifactId>tempto-core</artifactId>
<version>1.0.38</version>
</dependency>

<dependency>
<groupId>com.teradata.tempto</groupId>
<artifactId>tempto-runner</artifactId>
<version>1.0.38</version>
</dependency>

<dependency>
<groupId>com.facebook.presto.hive</groupId>
<artifactId>hive-apache-jdbc</artifactId>
<version>0.13.1-1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
30 changes: 30 additions & 0 deletions presto-product-tests/README.md
@@ -0,0 +1,30 @@
# Presto product tests

## Test configuration

Test assume that you have hadoop and presto cluster running. For setting up development environment we
recommend presto-docker-devenv project. This presto-docker-devenv contains tools for building and running
docker images to be used on local developer machine for easy setup of presto instance together with dependencies
like hadoop. You can also start presto on your machine locally from IDE (please check main presto README).

To make it work you need either:
- define environment variables for hadoop ${HADOOP_MASTER} and presto ${PRESTO_MASTER} with their IP numbers,
and ${PRESTO_PRODUCT_TESTS_ROOT} with path to the presto product test directory
- create test-configuration-local.yaml with following (example content):

```
databases:
hive:
host: 172.16.2.10
presto:
host: 192.168.205.1
```

## Running tests

Product tests are not run by default. To start them use run following command:

```
java -jar target/presto-product-tests-*-executable.jar --config-local file://`pwd`/tempto-configuration-local.yaml
```
111 changes: 111 additions & 0 deletions presto-product-tests/pom.xml
@@ -0,0 +1,111 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>presto-root</artifactId>
<groupId>com.facebook.presto</groupId>
<version>0.126-SNAPSHOT</version>
</parent>

<artifactId>presto-product-tests</artifactId>
<name>presto-product-tests</name>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<main-class>com.facebook.presto.tests.TemptoProductTestRunner</main-class>
</properties>

<dependencies>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-main</artifactId>
</dependency>
<dependency>
<groupId>com.teradata.tempto</groupId>
<artifactId>tempto-core</artifactId>
</dependency>
<dependency>
<groupId>com.teradata.tempto</groupId>
<artifactId>tempto-runner</artifactId>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-cli</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>units</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-client</artifactId>
</dependency>
<dependency>
<groupId>com.facebook.presto.hive</groupId>
<artifactId>hive-apache-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>executable</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${main-class}</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,52 @@
/*
* 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.tests;

import com.facebook.presto.tests.ImmutableTpchTablesRequirements.ImmutableNationTable;
import com.facebook.presto.tests.utils.PrestoDDLUtils.Table;
import com.teradata.tempto.ProductTest;
import com.teradata.tempto.Requires;
import org.testng.annotations.Test;

import java.io.IOException;

import static com.facebook.presto.tests.TestGroups.ALTER_TABLE;
import static com.facebook.presto.tests.TestGroups.SMOKE;
import static com.facebook.presto.tests.utils.PrestoDDLUtils.createPrestoTable;
import static com.teradata.tempto.assertions.QueryAssert.assertThat;
import static com.teradata.tempto.query.QueryExecutor.query;
import static com.teradata.tempto.query.QueryType.UPDATE;
import static java.lang.String.format;

@Requires(ImmutableNationTable.class)
public class AlterTableTests
extends ProductTest
{
@Test(groups = {ALTER_TABLE, SMOKE})
public void renameTable()
throws IOException
{
String tableName = "to_be_renamed_table_name";
String renamedTableName = "renamed_table_name";
try (Table table = createPrestoTable(tableName, "CREATE TABLE %s AS SELECT * FROM nation")) {
assertThat(query(format("ALTER TABLE %s RENAME TO %s", table.getNameInDatabase(), renamedTableName), UPDATE))
.hasRowsCount(1);
assertThat(query(format("SELECT * FROM %s", renamedTableName)))
.hasRowsCount(25);
// rename back to original name
assertThat(query(format("ALTER TABLE %s RENAME TO %s", renamedTableName, table.getNameInDatabase()), UPDATE))
.hasRowsCount(1);
}
}
}
@@ -0,0 +1,93 @@
/*
* 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.tests;

import com.facebook.presto.tests.ImmutableTpchTablesRequirements.ImmutableNationTable;
import com.teradata.tempto.ProductTest;
import com.teradata.tempto.Requires;
import org.testng.annotations.Test;

import java.io.IOException;

import static com.facebook.presto.tests.TestGroups.CREATE_DROP_VIEW;
import static com.facebook.presto.tests.TestGroups.SMOKE;
import static com.teradata.tempto.assertions.QueryAssert.assertThat;
import static com.teradata.tempto.context.ContextDsl.executeWith;
import static com.teradata.tempto.query.QueryExecutor.query;
import static com.teradata.tempto.query.QueryType.UPDATE;
import static com.teradata.tempto.sql.SqlContexts.createViewAs;
import static java.lang.String.format;

@Requires(ImmutableNationTable.class)
public class CreateDropViewTests
extends ProductTest
{
@Test(groups = CREATE_DROP_VIEW)
public void createSimpleView()
throws IOException
{
executeWith(createViewAs("SELECT * FROM nation"), view -> {
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(25);
});
}

@Test(groups = CREATE_DROP_VIEW)
public void createViewWithAggregate()
throws IOException
{
executeWith(createViewAs("SELECT n_regionkey, count(*) countries FROM nation GROUP BY n_regionkey ORDER BY n_regionkey"), view -> {
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(5);
});
}

@Test(groups = {CREATE_DROP_VIEW, SMOKE})
public void createOrReplaceSimpleView()
throws IOException
{
executeWith(createViewAs("SELECT * FROM nation"), view -> {
assertThat(query(format("CREATE OR REPLACE VIEW %s AS SELECT * FROM nation", view.getName()), UPDATE))
.hasRowsCount(1);
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(25);
});
}

@Test(groups = CREATE_DROP_VIEW)
public void createSimpleViewTwiceShouldFail()
throws IOException
{
executeWith(createViewAs("SELECT * FROM nation"), view -> {
assertThat(() -> query(format("CREATE VIEW %s AS SELECT * FROM nation", view.getName()), UPDATE))
.failsWithMessage("View already exists");
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(25);
});
}

@Test(groups = {CREATE_DROP_VIEW, SMOKE})
public void dropViewTest()
throws IOException
{
executeWith(createViewAs("SELECT * FROM nation"), view -> {
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(25);
assertThat(query(format("DROP VIEW %s", view.getName()), UPDATE))
.hasRowsCount(1);
assertThat(() -> query(format("SELECT * FROM %s", view.getName())))
.failsWithMessage("does not exist");
});
}
}
@@ -0,0 +1,51 @@
/*
* 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.tests;

import com.facebook.presto.tests.ImmutableTpchTablesRequirements.ImmutableNationTable;
import com.facebook.presto.tests.utils.PrestoDDLUtils.Table;
import com.teradata.tempto.ProductTest;
import com.teradata.tempto.Requires;
import org.testng.annotations.Test;

import static com.facebook.presto.tests.TestGroups.CREATE_TABLE;
import static com.facebook.presto.tests.utils.PrestoDDLUtils.createPrestoTable;
import static com.teradata.tempto.assertions.QueryAssert.assertThat;
import static com.teradata.tempto.query.QueryExecutor.query;
import static java.lang.String.format;

@Requires(ImmutableNationTable.class)
public class CreateTableTests
extends ProductTest
{
@Test(groups = CREATE_TABLE)
public void shouldCreateTableAsSelect()
throws Exception
{
String tableName = "create_table_as_select";
try (Table table = createPrestoTable(tableName, "CREATE TABLE %s AS SELECT * FROM nation")) {
assertThat(query(format("SELECT * FROM %s", table.getNameInDatabase()))).hasRowsCount(25);
}
}

@Test(groups = CREATE_TABLE)
public void shouldCreateTableAsEmptySelect()
throws Exception
{
String tableName = "create_table_as_empty_select";
try (Table table = createPrestoTable(tableName, "CREATE TABLE %s AS SELECT * FROM nation WHERE 0 is NULL")) {
assertThat(query(format("SELECT * FROM %s", table.getNameInDatabase()))).hasRowsCount(0);
}
}
}

0 comments on commit c71bd92

Please sign in to comment.