This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3c28378 AMBARI-25053. Validate SQL schema creation scripts with
Docker containers (#2728)
3c28378 is described below
commit 3c28378fa4e6f4299e7df01c47359b4c8643ef63
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed Dec 19 19:53:26 2018 +0100
AMBARI-25053. Validate SQL schema creation scripts with Docker containers
(#2728)
---
ambari-funtest/pom.xml | 52 ++++++++++++++-
.../funtest/server/tests/DeleteServiceTest.java | 31 ++++-----
.../ambari/funtest/server/tests/GetStacksTest.java | 23 +++----
.../tests/RoleBasedAccessControlBasicTest.java | 15 +++--
.../funtest/server/tests/db/DDLCreateIT.java | 74 ++++++++++++++++++++++
ambari-project/pom.xml | 49 ++++++++++++++
.../src/main/resources/Ambari-DDL-MySQL-CREATE.sql | 2 +-
7 files changed, 212 insertions(+), 34 deletions(-)
diff --git a/ambari-funtest/pom.xml b/ambari-funtest/pom.xml
index 23a9fd7..dd3deea 100644
--- a/ambari-funtest/pom.xml
+++ b/ambari-funtest/pom.xml
@@ -21,8 +21,20 @@
<packaging>jar</packaging>
<name>Ambari Functional Tests</name>
<description>Ambari Functional Tests</description>
+ <properties>
+ <jdk.version>1.8</jdk.version>
+ </properties>
<build>
<plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <source>${jdk.version}</source>
+ <target>${jdk.version}</target>
+ <useIncrementalCompilation>false</useIncrementalCompilation>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.vafer</groupId>
<artifactId>jdeb</artifactId>
@@ -76,11 +88,16 @@
<includes>
<include>**/*.java</include>
</includes>
- <forkMode>once</forkMode>
</configuration>
<executions>
<!-- Will display BUILD FAILURE if build fails or any test fails -->
<execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ <execution>
<id>run-verify</id>
<phase>verify</phase>
<goals>
@@ -98,6 +115,7 @@
<exclude>src/test/resources/os_family.json</exclude>
<exclude>src/test/resources/stacks/**</exclude>
<exclude>derby.log</exclude>
+ <exclude>pass.txt</exclude>
</excludes>
</configuration>
</plugin>
@@ -179,5 +197,37 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mariadb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mssqlserver</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>mssql-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mysql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java
index 1bfc6a2..f677b34 100644
---
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java
+++
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java
@@ -18,8 +18,11 @@
package org.apache.ambari.funtest.server.tests;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
import org.apache.ambari.funtest.server.ConnectionParams;
import org.apache.ambari.funtest.server.WebResponse;
import org.apache.ambari.funtest.server.api.cluster.DeleteClusterWebRequest;
@@ -29,28 +32,25 @@ import
org.apache.ambari.funtest.server.api.service.StopServiceWebRequest;
import org.apache.ambari.funtest.server.utils.ClusterUtils;
import org.apache.ambari.funtest.server.utils.RestApiUtils;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
-import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
+import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
+import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
+import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
-import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
-import
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntityPK;
import org.apache.ambari.server.state.State;
-
-import org.apache.http.HttpStatus;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpStatus;
+import org.junit.Ignore;
import org.junit.Test;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
@@ -58,6 +58,7 @@ import static org.junit.Assert.assertTrue;
* Simple test that starts the local ambari server,
* tests it's status and shuts down the server.
*/
+@Ignore
public class DeleteServiceTest extends ServerTestBase {
private static Log LOG = LogFactory.getLog(DeleteServiceTest.class);
diff --git
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/GetStacksTest.java
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/GetStacksTest.java
index 44d0daf..49cecdb 100644
---
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/GetStacksTest.java
+++
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/GetStacksTest.java
@@ -18,31 +18,32 @@
package org.apache.ambari.funtest.server.tests;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonArray;
-
-import java.io.StringReader;
import java.io.IOException;
+import java.io.StringReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
-import org.apache.http.HttpStatus;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.stream.JsonReader;
/**
* Simple test to get the list of stacks. Does not touch the DB.
*/
+@Ignore
public class GetStacksTest extends ServerTestBase {
/**
* Waits for the ambari server to startup and then checks it's
diff --git
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/RoleBasedAccessControlBasicTest.java
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/RoleBasedAccessControlBasicTest.java
index 549766c..0109f0c 100644
---
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/RoleBasedAccessControlBasicTest.java
+++
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/RoleBasedAccessControlBasicTest.java
@@ -19,7 +19,11 @@
package org.apache.ambari.funtest.server.tests;
-import com.google.gson.JsonElement;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.util.HashMap;
+
import org.apache.ambari.funtest.server.AmbariUserRole;
import org.apache.ambari.funtest.server.ClusterConfigParams;
import org.apache.ambari.funtest.server.ConnectionParams;
@@ -32,19 +36,18 @@ import
org.apache.ambari.funtest.server.api.cluster.GetAllClustersWebRequest;
import org.apache.ambari.funtest.server.api.user.DeleteUserWebRequest;
import org.apache.ambari.funtest.server.utils.ClusterUtils;
import org.apache.ambari.funtest.server.utils.RestApiUtils;
-import org.apache.http.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpStatus;
+import org.junit.Ignore;
import org.junit.Test;
-import java.util.HashMap;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
+import com.google.gson.JsonElement;
/**
* Tests operations with users with different levels of privileges
*/
+@Ignore
public class RoleBasedAccessControlBasicTest extends ServerTestBase {
private String clusterName = "c1";
diff --git
a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/db/DDLCreateIT.java
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/db/DDLCreateIT.java
new file mode 100644
index 0000000..7f17684
--- /dev/null
+++
b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/db/DDLCreateIT.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.funtest.server.tests.db;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.SQLException;
+import java.util.Properties;
+import java.util.function.Supplier;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.DBAccessor;
+import org.apache.ambari.server.orm.DBAccessorImpl;
+import org.apache.ambari.server.orm.PersistenceType;
+import org.junit.Test;
+import org.testcontainers.containers.JdbcDatabaseContainer;
+import org.testcontainers.containers.MariaDBContainer;
+import org.testcontainers.containers.MySQLContainer;
+import org.testcontainers.containers.PostgreSQLContainer;
+
+public class DDLCreateIT {
+
+ @Test
+ public void mysql() {
+ testSchemaCreate(() -> new
MariaDBContainer("mariadb:10.2").withConfigurationOverride(null).withInitScript("Ambari-DDL-MySQL-CREATE.sql"));
+ testSchemaCreate(() -> new
MySQLContainer("mysql:5.7").withConfigurationOverride(null).withInitScript("Ambari-DDL-MySQL-CREATE.sql"));
+ }
+
+ @Test
+ public void postgres() {
+ testSchemaCreate(() -> new
PostgreSQLContainer("postgres:9.6").withInitScript("Ambari-DDL-Postgres-CREATE.sql"));
+ testSchemaCreate(() -> new
PostgreSQLContainer("postgres:10").withInitScript("Ambari-DDL-Postgres-CREATE.sql"));
+ }
+
+ private static void testSchemaCreate(Supplier<? extends
JdbcDatabaseContainer> containerSupplier) {
+ try (JdbcDatabaseContainer container =
containerSupplier.get().withPassword(Configuration.SERVER_JDBC_USER_PASSWD.getDefaultValue()))
{
+ container.start();
+
+ Properties props = new Properties();
+ props.put(Configuration.SERVER_PERSISTENCE_TYPE.getKey(),
PersistenceType.REMOTE.getValue());
+ props.put(Configuration.SERVER_DB_NAME.getKey(),
container.getDatabaseName());
+ props.put(Configuration.SERVER_JDBC_DRIVER.getKey(),
container.getDriverClassName());
+ props.put(Configuration.SERVER_JDBC_URL.getKey(),
container.getJdbcUrl().replace("mariadb", "mysql"));
+ props.put(Configuration.SERVER_JDBC_USER_NAME.getKey(),
container.getUsername());
+ Configuration config = new Configuration(props);
+ DBAccessor db = new DBAccessorImpl(config);
+
+ assertTrue(db.tableExists("metainfo"));
+ assertEquals(new Integer(1),
+ db.getIntColumnValues("users", "user_id", new String[] { "user_name"
}, new String[] { "admin" }, false).get(0)
+ );
+ } catch (SQLException e) {
+ fail(e.getMessage());
+ }
+ }
+
+}
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index b0ce441..96fb7cc 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -41,6 +41,7 @@
<spring.security.version>4.2.7.RELEASE</spring.security.version>
<fasterxml.jackson.version>2.9.5</fasterxml.jackson.version>
<postgres.version>42.2.2</postgres.version>
+ <testContainers.version>1.10.2</testContainers.version>
<forkCount>4</forkCount>
<reuseForks>false</reuseForks>
<surefire.argLine>-Xmx1024m -Xms512m</surefire.argLine>
@@ -139,6 +140,54 @@
<version>1.1</version>
</dependency>
<dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>${testContainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mariadb</artifactId>
+ <version>${testContainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>2.3.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mssqlserver</artifactId>
+ <version>${testContainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>mssql-jdbc</artifactId>
+ <version>7.0.0.jre8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mysql</artifactId>
+ <version>${testContainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>8.0.13</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>${testContainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 8e7b228..0106b81 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -18,7 +18,7 @@
-- DROP DATABASE IF EXISTS `ambari`;
-- DROP USER `ambari`;
-delimiter ;
+# delimiter ;
# CREATE DATABASE `ambari` /*!40100 DEFAULT CHARACTER SET utf8 */;
#