BIGTOP-3223: Add smoke tests for Elasticsearch
Implement smoke tests for Elasticsearch
Change-Id: I3f448513688d2a789fba5d59d5e24f61e1811099
Signed-off-by: Jun He <jun.he@arm.com>
diff --git a/bigtop-tests/smoke-tests/elasticsearch/build.gradle b/bigtop-tests/smoke-tests/elasticsearch/build.gradle
new file mode 100644
index 0000000..d9ba7e3
--- /dev/null
+++ b/bigtop-tests/smoke-tests/elasticsearch/build.gradle
@@ -0,0 +1,43 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+
+def tests_to_include() {
+ return [
+ "TestBase.groovy",
+ "TestInfo.groovy",
+ "TestDocument.groovy",
+ ];
+}
+
+dependencies {
+ testCompile group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.7.1'
+}
+
+sourceSets {
+ test {
+ groovy {
+ srcDirs = [
+ "${BIGTOP_HOME}/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke"
+ ]
+ }
+ }
+}
+
+test.doFirst {
+ checkEnv(["ELASTICSEARCH_URL"])
+}
diff --git a/bigtop-tests/test-artifacts/elasticsearch/pom.xml b/bigtop-tests/test-artifacts/elasticsearch/pom.xml
new file mode 100644
index 0000000..be7aedf
--- /dev/null
+++ b/bigtop-tests/test-artifacts/elasticsearch/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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>
+ <groupId>org.apache.bigtop.itest</groupId>
+ <artifactId>bigtop-smokes</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <groupId>org.apache.bigtop.itest</groupId>
+ <artifactId>elasticsearch-smoke</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+
+ <name>elasticsearchsmoke</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestBase.groovy b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestBase.groovy
new file mode 100644
index 0000000..80646f4
--- /dev/null
+++ b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestBase.groovy
@@ -0,0 +1,46 @@
+/**
+ * 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.bigtop.itest.elasticsearch
+
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+import static org.junit.Assert.assertEquals
+import org.junit.Test
+import org.junit.BeforeClass
+import org.apache.commons.logging.LogFactory
+import org.apache.commons.logging.Log
+import groovyx.net.http.RESTClient
+
+import org.junit.runner.RunWith
+
+class ElasticsearchTestBase {
+ static RESTClient elastic
+
+ static String prop(String key) {
+ def value = System.getenv(key)
+ assertNotNull(value)
+ return value
+ }
+
+ @BeforeClass
+ static void setUp() {
+ elastic = new RESTClient("${prop('ELASTICSEARCH_URL')}:9200/")
+ elastic.parser.'text/plain' = elastic.parser.'application/json'
+ }
+}
diff --git a/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestDocument.groovy b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestDocument.groovy
new file mode 100644
index 0000000..7f19455
--- /dev/null
+++ b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestDocument.groovy
@@ -0,0 +1,72 @@
+/*
+ * 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.bigtop.itest.elasticsearch
+
+import static org.junit.Assert.assertTrue
+import static org.junit.Assert.assertEquals
+import org.junit.Test
+import groovy.json.JsonSlurper
+import groovy.json.JsonOutput
+
+/**
+ * Utterly trivial test to see if the server is running
+ */
+class TestDocument extends ElasticsearchTestBase {
+ static jsonSlurper = new JsonSlurper()
+
+ @Test
+ void testCRUD() {
+ // create a record
+ def data = jsonSlurper.parseText('{"title" : "Winter","artist" : "Giuliano Carmignola","album" : "Vivaldi : Le Quattro Stagioni","year" : 1994}')
+ def response = elastic.put(
+ path: '/music/classic/1',
+ contentType: 'application/json',
+ body: data,
+ headers: [Accept: 'application/json'])
+ assertEquals("created", response.data.result)
+ println "Sample record is created"
+
+ // now get it back
+ elastic.get( path: '/music/classic/1' ) { resp, json ->
+ println "Read it back: "+json
+ assertEquals(200, resp.status)
+ assertEquals("Winter", json._source.title)
+ }
+
+ // now update it
+ data = jsonSlurper.parseText('{"title" : "Winter","artist" : "Giuliano Carmignola","album" : "Vivaldi : Le Quattro Stagioni","year" : 1994, "Country":"Italy"}')
+ response = elastic.post(
+ path: '/music/classic/1',
+ contentType: 'application/json',
+ body: data,
+ headers: [Accept: 'application/json'])
+ assertEquals("updated", response.data.result)
+ println "Sample record is updated"
+
+ // read it back
+ elastic.get( path: '/music/classic/1' ) { resp, json ->
+ println "Read it back: "+json
+ assertEquals(200, resp.status)
+ assertEquals("Italy", json._source.Country)
+ }
+
+ // delete it
+ response = elastic.delete( path: '/music/classic/1' )
+ assertEquals("deleted", response.data.result)
+ println "Sample record is deleted"
+ }
+}
diff --git a/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestInfo.groovy b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestInfo.groovy
new file mode 100644
index 0000000..9711355
--- /dev/null
+++ b/bigtop-tests/test-artifacts/elasticsearch/src/main/groovy/org/apache/bigtop/itest/elasticsearch/smoke/TestInfo.groovy
@@ -0,0 +1,43 @@
+/*
+ * 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.bigtop.itest.elasticsearch
+
+import static org.junit.Assert.assertTrue
+import static org.junit.Assert.assertEquals
+import org.junit.Test
+
+/**
+ * Utterly trivial test to see if the server is running
+ */
+class TestInfo extends ElasticsearchTestBase {
+ @Test
+ void testStackInfo() {
+ elastic.get( path: '/' ) { resp, json ->
+ println json
+ assertEquals("bigtop-es", json.cluster_name)
+ assertEquals("You Know, for Search", json.tagline)
+ }
+ }
+
+ @Test
+ void testClusterInfo() {
+ elastic.get( path: '/_cluster/state' ) { resp, json ->
+ println json.nodes.size()+" nodes in cluster"
+ assertTrue(json.nodes.size()>0)
+ }
+ }
+}
diff --git a/bigtop-tests/test-execution/smokes/elasticsearch/pom.xml b/bigtop-tests/test-execution/smokes/elasticsearch/pom.xml
new file mode 100644
index 0000000..0854773
--- /dev/null
+++ b/bigtop-tests/test-execution/smokes/elasticsearch/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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>
+ <groupId>org.apache.bigtop.itest</groupId>
+ <artifactId>smoke-tests</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.bigtop.itest</groupId>
+ <artifactId>elasticsearch-smoke-test</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <name>Elasticsearch smoke test execution</name>
+
+ <properties>
+ <org.apache.maven-dependency-plugin.groupId>org.apache.bigtop.itest</org.apache.maven-dependency-plugin.groupId>
+ <org.apache.maven-dependency-plugin.artifactId>elasticsearch-smoke</org.apache.maven-dependency-plugin.artifactId>
+ <org.apache.maven-dependency-plugin.version>${elasticsearch-smoke.version}</org.apache.maven-dependency-plugin.version>
+ <org.apache.maven-dependency-plugin.type>jar</org.apache.maven-dependency-plugin.type>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.bigtop.itest</groupId>
+ <artifactId>elasticsearch-smoke</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/provisioner/utils/smoke-tests.sh b/provisioner/utils/smoke-tests.sh
index 43b3ff2..3b48d55 100755
--- a/provisioner/utils/smoke-tests.sh
+++ b/provisioner/utils/smoke-tests.sh
@@ -34,6 +34,7 @@
export ALLUXIO_HOME=${ALLUXIO_HOME:-/usr/lib/alluxio}
export AMBARI_URL=${AMBARI_URL:-http://localhost:8080}
+export ELASTICSEARCH_URL=${ELASTICSEARCH_URL:-http://localhost}
export FLUME_HOME=${FLUME_HOME:-/usr/lib/flume}
export GPDB_HOME=${GPDB_HOME:-/usr/lib/gpdb}
export HADOOP_HOME=${HADOOP_HOME:-/usr/lib/hadoop}