Skip to content
Permalink
Browse files
ODPI-30. Write iTest tests for validating ODPi spec compliance
(cherry picked from commit 6a4e84a)
  • Loading branch information
Konstantin Boudnik authored and rvs committed Mar 23, 2017
1 parent 0f2436b commit 67f8eb55aff3395d1a82c95ec32092c4fe6fda45
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 0 deletions.
@@ -0,0 +1,35 @@
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.

Test suite to validate Hadoop basic specifications
==================================================

The test suite is intended to be used as a validation tool to make sure that a
Hadoop stack derived from Apache Bigtop is still compliant with it. The
minimalistic way of doing so would be to guarantee compatibility of the
environment, binaries layouts, certain configuration parameters, and so on.

Validation test suite for the specs is vaguely based on Apache Bigtop iTest and
consists of two essential parts: a configuration file, communicating the
functional commands and expected outcome(s) of it; and the test driver to run
the commands and compare the results.

Running the tests
=================

Tests could be executed by running the following command
```
gradle :bigtop-tests:spec-tests:runtime:test -Pspec.tests --info
```
@@ -0,0 +1,65 @@
/**
* 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.
*/
subprojects {
/**
* Utility function for tests to use to confirm EVN Variables.
*/
ext.checkEnv = { env_vars ->
env_vars.each() {
def value = System.getenv("${it}")
if (value == null || value == "null")
throw new GradleException("undeclared env variable: ${it}")
}
}

ext.groovyVersion = '1.8.0'
ext.hadoopVersion = '2.6.0'
// itest needs be greater than or equal to = 1.0.0
ext.itestVersion = '1.0.0' // Might need to be able to read an input for alternate version?
ext.BIGTOP_HOME = rootDir

dependencies {
compile group: 'org.apache.bigtop.itest', name: 'itest-common', version: itestVersion, transitive: 'true'
//needed to avoid groovy not on classpath error.
testCompile group: 'org.codehaus.groovy', name: 'groovy', version: groovyVersion
testRuntime project(':bigtop-tests:smoke-tests:logger-test-config')
}

test.doFirst {
// java_home should be declared in all cases.
checkEnv(["JAVA_HOME"])
// TestHadoopExamples and other tests rely on BIGTOP_HOME environment
// variable to find some resources. Let's set it up, using ext.BIGTOP_HOME
environment ("BIGTOP_HOME", BIGTOP_HOME)
}

test << {
println("Now testing...");
//todo, add back in 'basic' after BIGTOP-1392 .
testLogging {
events "passed", "skipped", "failed"
}
}

// Let's make sure all system Properties are passed into the forked test JVM
tasks.withType(Test) {
systemProperties = System.getProperties()
}
test.dependsOn compileGroovy
compileGroovy.dependsOn clean
}
@@ -0,0 +1,31 @@
/**
* 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 junitVersion = '4.11'
dependencies {
compile group: 'junit', name: 'junit', version: junitVersion, transitive: 'true'
if (System.env.HADOOP_CONF_DIR) testRuntime files(System.env.HADOOP_CONF_DIR)
}

test.doFirst {
checkEnv(["HADOOP_CONF_DIR"])
}

test {
// Change the default location where test data is picked up
systemProperty 'test.resources.dir', "${buildDir}/resources/test/"
}
@@ -0,0 +1,80 @@
/**
* 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.
*/
package org.odpi.specs.runtime

import org.junit.Assert
import org.apache.bigtop.itest.shell.*
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

/**
* Check all expected environment
* Tests are constructed dynamically, using external DSL to define
* - test name
* - test type
* - command to execute the test
* - expected pattern of the output
*/
@RunWith(Parameterized.class)
public class TestSpecsRuntime {
private String testName
private String type
private String command
private String pattern

@Parameters
public static Collection<Object[]> allTests() {
List<Object[]> specs = [];

config.specs.tests.each { test ->
specs.add([test.value.name, test.value.type, test.value.command, test.value.pattern] as Object[])
}
return specs
}

public TestSpecsRuntime (String testName, String type, String cmd, String ptrn) {
this.testName = testName
this.type = type
this.command = cmd
this.pattern = ptrn
}

public static final String testsList = System.properties['test.resources.dir'] ?:
"${System.properties['buildDir']}/resources/test"
def final static config = new ConfigSlurper().parse(new URL("file:${getTestConfigName()}"))

private static String getTestConfigName() {
return "$testsList/testRuntimeSpecConf.groovy";
}

@Test
public void testAll() {
switch (type) {
case 'shell':
Shell sh = new Shell()
def output = sh.exec(command).getOut().join("\n")
Assert.assertTrue("${testName} fail: $output doesn't contain expected pattern",
output ==~ /${pattern}/)
break
default:
break
}
}
}
@@ -0,0 +1,16 @@
specs {
tests {
'HADOOP_EJH1' {
name = 'HADOOP_EJH1'
type = 'shell'
command = 'echo $JAVA_HOME'
pattern = /.*\/usr\/.*/
}
'HADOOP_EC2' {
name = 'HADOOP_EC2'
type = 'shell'
command = 'echo $HADOOP_COMMON_HOME'
pattern = /.*\/usr\/lib\/hadoop.*/
}
}
}
@@ -427,6 +427,7 @@ task "bigtop-slaves"(type:Exec,

project.afterEvaluate {
checkClusterTestProjects("smoke.tests")
checkClusterTestProjects("spec.tests")
artifactToInstall(dependsOn: [installTopLevel, installCommon, installConf, installiTest])
}

@@ -31,4 +31,9 @@ fTree.each() { buildFile ->
def parent = buildFile.getParentFile().name
include("bigtop-tests:smoke-tests:$parent")
}
fTree = fileTree(dir: 'bigtop-tests/spec-tests', include: '*/build.gradle')
fTree.each() { buildFile ->
def parent = buildFile.getParentFile().name
include("bigtop-tests:spec-tests:$parent")
}

0 comments on commit 67f8eb5

Please sign in to comment.