Skip to content

Commit a735e62

Browse files
committed
Replace more flaky "tests" with proper integration tests
- Add integTest sourceSet and task to li-hadoop-plugin subproject - Remove unused test resources and li-hadoop-plugin-test subproject - Local builds should no longer freeze or hang Signed-off-by: Kyle Moore <[email protected]>
1 parent 438cc97 commit a735e62

File tree

10 files changed

+114
-113
lines changed

10 files changed

+114
-113
lines changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,5 @@ The following were contributed by Sayali Kadam.
184184

185185
[Kyle Moore](https://www.linkedin.com/in/dpukyle/) ([DPUkyle](https://github.com/DPUkyle)) contributed the following:
186186
* `Refactored Hadoop DSL "tests" into proper integration tests using Gradle TestKit`
187+
* `Refactored li-hadoop-plugin "tests" into proper integration tests using Gradle TestKit`
187188

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ The project structure is setup as follows:
9393
* `example-project`: Example project that uses the Hadoop Plugin and DSL to build an example Azkaban workflow
9494
* `hadoop-jobs`: Code for re-usable Hadoop jobs and implementations of Hadoop DSL job types
9595
* `hadoop-plugin`: Code and tests for the various plugins that comprise the Hadoop Plugin
96-
* `li-hadoop-plugin`: LinkedIn-specific extensions to the Hadoop Plugin
97-
* `li-hadoop-plugin-test`: Test cases for the LinkedIn-specific extensions to the Hadoop Plugin
96+
* `li-hadoop-plugin`: LinkedIn-specific extensions to the Hadoop Plugin, and tests
9897

9998
Although the `li-hadoop-plugin` code is generally specific to LinkedIn, it is included in the
10099
project to show you how to use subclassing to extend the core functionality of the Hadoop Plugin for your
@@ -111,4 +110,4 @@ Unit tests are invoked by running `./gradlew :hadoop-plugin:test`. Individual t
111110

112111
##### Integration tests
113112

114-
Integration tests are invoked by running `./gradlew :hadoop-plugin:integTest`, or by running the `check` task.
113+
Integration tests are invoked by running `./gradlew :hadoop-plugin:integTest`, or by running the `check` task.

build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ if (isLinkedInBuild) {
3232
}
3333
}
3434
}
35-
else {
36-
project(':li-hadoop-plugin-test').ext['pluginTestDir'] = "${project(':hadoop-plugin').projectDir}/build/libs"
37-
project(':li-hadoop-plugin-test').ext['liPluginTestDir'] = "${project(':li-hadoop-plugin').projectDir}/build/libs"
38-
}
3935

4036
// Configure the Gradle wrapper
4137
wrapper {

li-hadoop-plugin-test/.crt

-1
This file was deleted.

li-hadoop-plugin-test/build.gradle

-48
This file was deleted.

li-hadoop-plugin-test/buildZipsCRT.gradle

-56
This file was deleted.

li-hadoop-plugin/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'groovy'
3+
id 'java-gradle-plugin'
34
id 'eclipse'
45
id 'idea'
56
}
@@ -23,6 +24,12 @@ sourceSets {
2324
compileClasspath+=configurations.provided
2425
runtimeClasspath+=configurations.provided
2526
}
27+
integTest {
28+
groovy.srcDir file('src/integTest/groovy')
29+
resources.srcDir file('src/integTest/resources')
30+
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
31+
runtimeClasspath += output + compileClasspath
32+
}
2633
}
2734

2835
dependencies {
@@ -34,6 +41,8 @@ dependencies {
3441

3542
testCompile 'junit:junit:4.12'
3643
testCompile 'org.mockito:mockito-core:2.10.0'
44+
45+
integTestCompile 'org.spockframework:spock-core:1.3-groovy-2.4@jar'
3746
}
3847

3948
task sourceJar(type: Jar) {
@@ -52,6 +61,25 @@ artifacts {
5261
archives groovydocJar, sourceJar
5362
}
5463

64+
task integTest(type: Test) {
65+
description = 'Runs the integration tests.'
66+
group = 'verification'
67+
testClassesDirs = sourceSets.integTest.output.classesDirs
68+
classpath = sourceSets.integTest.runtimeClasspath
69+
mustRunAfter test
70+
}
71+
72+
check.dependsOn integTest
73+
74+
gradlePlugin {
75+
plugins {
76+
liHadoopPlugin {
77+
id = 'li-hadoop-plugin'
78+
implementationClass = 'com.linkedin.gradle.lihadoop.LiHadoopPlugin'
79+
}
80+
}
81+
}
82+
5583
// In LinkedIn internal builds, we pull in some company-specific resource files into this project.
5684
boolean isLinkedInBuild = project.hasProperty('overrideBuildEnvironment')
5785

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.linkedin.gradle
2+
3+
4+
import org.gradle.testkit.runner.BuildResult
5+
import org.gradle.testkit.runner.GradleRunner
6+
import org.gradle.testkit.runner.TaskOutcome
7+
import org.junit.Rule
8+
import org.junit.rules.TemporaryFolder
9+
import spock.lang.Specification
10+
11+
import java.util.zip.ZipFile
12+
13+
class BuildHadoopZips extends Specification {
14+
15+
@Rule
16+
TemporaryFolder tmp = new TemporaryFolder()
17+
18+
def buildDotGradle
19+
def settingsDotGradle
20+
def gradleDotProperties
21+
def dotCrt
22+
23+
def setup() {
24+
tmp.create()
25+
buildDotGradle = tmp.newFile('build.gradle')
26+
settingsDotGradle = tmp.newFile('settings.gradle')
27+
gradleDotProperties = tmp.newFile('gradle.properties')
28+
dotCrt = tmp.newFile('.crt')
29+
}
30+
31+
/**
32+
* Integration test for including the sources zip and SCM metadata file in the Hadoop zip
33+
*/
34+
def 'verify zip contents'() {
35+
given:
36+
def projectName = 'build-hadoop-zips'
37+
def version = '1.0.0'
38+
buildDotGradle << this.class.classLoader.getResource('buildZips/buildZipsCRT.gradle').text
39+
settingsDotGradle << """rootProject.name='${projectName}'"""
40+
gradleDotProperties << """version=${version}"""
41+
dotCrt << '''Test .crt file\n'''
42+
GradleRunner runner = GradleRunner.create()
43+
.withProjectDir(tmp.root)
44+
.withPluginClasspath()
45+
.withArguments('buildHadoopZips', '-is')
46+
47+
when:
48+
BuildResult result = runner.build()
49+
50+
then:
51+
result.task(':azkabanHadoopZip').outcome == TaskOutcome.SUCCESS
52+
result.task(':CRTHadoopZip').outcome == TaskOutcome.SUCCESS
53+
54+
// find CRTHadoopZip, assert contains .crt file (build/distributions/build-hadoop-zips-1.0.0.zip)
55+
def crtHadoopZip = new File(tmp.root, "build/distributions/${projectName}-${version}.zip")
56+
crtHadoopZip.exists()
57+
def crtHadoopZipContents = new ZipFile(crtHadoopZip)
58+
assert crtHadoopZipContents.getEntry('.crt') != null
59+
60+
// find azkabanHadoopZip, assert contents (build/distributions/build-hadoop-zips-1.0.0-azkaban.zip)
61+
// contents == build.gradle, buildMetadata.json, build-hadoop-zips-1.0.0-sources.zip
62+
def azkabanZip = new File(tmp.root, "build/distributions/${projectName}-${version}-azkaban.zip")
63+
azkabanZip.exists()
64+
def zipFileContents = new ZipFile(azkabanZip)
65+
zipFileContents.getEntry('build.gradle') != null
66+
zipFileContents.getEntry('buildMetadata.json') != null
67+
zipFileContents.getEntry("${projectName}-${version}-sources.zip") != null
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'distribution'
3+
id 'li-hadoop-plugin'
4+
}
5+
6+
hadoopZip {
7+
base {
8+
from "build.gradle"
9+
}
10+
zip("azkaban") {
11+
from "buildZipsCRT.gradle"
12+
}
13+
CRT { }
14+
}

settings.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ include 'azkaban-client'
1717
include 'hadoop-jobs'
1818
include 'hadoop-plugin'
1919
include 'li-hadoop-plugin'
20-
include 'li-hadoop-plugin-test'

0 commit comments

Comments
 (0)