Skip to content

Commit 3a9f05f

Browse files
committed
[test] add java packaging test project
Adds a project for building and running packaging tests written in java for portability. The vagrant tasks use jars on the packagingTest configuration, which are built in the same project. No tests are added yet. Corresponding changes are not made to :x-pack:qa:vagrant because the java packaging tests will all be consolidated into one project. For elastic#26741
1 parent df42358 commit 3a9f05f

File tree

6 files changed

+118
-17
lines changed

6 files changed

+118
-17
lines changed

Vagrantfile

+2
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export BATS=/project/build/bats
337337
export BATS_UTILS=/project/build/packaging/bats/utils
338338
export BATS_TESTS=/project/build/packaging/bats/tests
339339
export PACKAGING_ARCHIVES=/project/build/packaging/archives
340+
export PACKAGING_TESTS=/project/build/packaging/tests
340341
VARS
341342
cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars
342343
Defaults env_keep += "ZIP"
@@ -347,6 +348,7 @@ Defaults env_keep += "BATS"
347348
Defaults env_keep += "BATS_UTILS"
348349
Defaults env_keep += "BATS_TESTS"
349350
Defaults env_keep += "PACKAGING_ARCHIVES"
351+
Defaults env_keep += "PACKAGING_TESTS"
350352
SUDOERS_VARS
351353
chmod 0440 /etc/sudoers.d/elasticsearch_vars
352354
SHELL

buildSrc/src/main/groovy/org/elasticsearch/gradle/FileContentsTask.groovy

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class FileContentsTask extends DefaultTask {
3636
@Input
3737
Object contents
3838

39+
@Input
40+
boolean executable = false
41+
3942
/**
4043
* The file to be built. Takes any objecct and coerces to a file.
4144
*/
@@ -47,5 +50,6 @@ class FileContentsTask extends DefaultTask {
4750
void setContents() {
4851
file = file as File
4952
file.text = contents.toString()
53+
file.setExecutable(executable)
5054
}
5155
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantPropertiesExtension.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class VagrantPropertiesExtension {
4141
@Input
4242
Boolean inheritTestUtils
4343

44+
@Input
45+
String testClass
46+
4447
VagrantPropertiesExtension(List<String> availableBoxes) {
4548
this.boxes = availableBoxes
4649
this.batsDir = 'src/test/resources/packaging'

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

+42-15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class VagrantTestPlugin implements Plugin<Project> {
4444
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb']
4545

4646
private static final PACKAGING_CONFIGURATION = 'packaging'
47+
private static final PACKAGING_TEST_CONFIGURATION = 'packagingTest'
4748
private static final BATS = 'bats'
4849
private static final String BATS_TEST_COMMAND ="cd \$PACKAGING_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS"
4950
private static final String PLATFORM_TEST_COMMAND ="rm -rf ~/elasticsearch && rsync -r /elasticsearch/ ~/elasticsearch && cd ~/elasticsearch && ./gradlew test integTest"
@@ -59,6 +60,7 @@ class VagrantTestPlugin implements Plugin<Project> {
5960

6061
// Creates custom configurations for Bats testing files (and associated scripts and archives)
6162
createPackagingConfiguration(project)
63+
project.configurations.create(PACKAGING_TEST_CONFIGURATION)
6264

6365
// Creates all the main Vagrant tasks
6466
createVagrantTasks(project)
@@ -142,10 +144,12 @@ class VagrantTestPlugin implements Plugin<Project> {
142144
}
143145

144146
private static void createCleanTask(Project project) {
145-
project.tasks.create('clean', Delete.class) {
146-
description 'Clean the project build directory'
147-
group 'Build'
148-
delete project.buildDir
147+
if (project.tasks.findByName('clean') == null) {
148+
project.tasks.create('clean', Delete.class) {
149+
description 'Clean the project build directory'
150+
group 'Build'
151+
delete project.buildDir
152+
}
149153
}
150154
}
151155

@@ -172,6 +176,19 @@ class VagrantTestPlugin implements Plugin<Project> {
172176
from project.configurations[PACKAGING_CONFIGURATION]
173177
}
174178

179+
File testsDir = new File(packagingDir, 'tests')
180+
Copy copyPackagingTests = project.tasks.create('copyPackagingTests', Copy) {
181+
into testsDir
182+
from project.configurations[PACKAGING_TEST_CONFIGURATION]
183+
}
184+
185+
Task createTestRunnerScript = project.tasks.create('createTestRunnerScript', FileContentsTask) {
186+
dependsOn copyPackagingTests
187+
file "${testsDir}/run-tests.sh"
188+
contents "java -cp \"*\" org.junit.runner.JUnitCore ${-> project.extensions.esvagrant.testClass}"
189+
executable true
190+
}
191+
175192
Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) {
176193
dependsOn copyPackagingArchives
177194
file "${archivesDir}/version"
@@ -232,7 +249,8 @@ class VagrantTestPlugin implements Plugin<Project> {
232249

233250
Task vagrantSetUpTask = project.tasks.create('setupPackagingTest')
234251
vagrantSetUpTask.dependsOn 'vagrantCheckVersion'
235-
vagrantSetUpTask.dependsOn copyPackagingArchives, createVersionFile, createUpgradeFromFile, createUpgradeIsOssFile
252+
vagrantSetUpTask.dependsOn copyPackagingArchives, copyPackagingTests, createTestRunnerScript
253+
vagrantSetUpTask.dependsOn createVersionFile, createUpgradeFromFile, createUpgradeIsOssFile
236254
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils
237255
}
238256

@@ -391,20 +409,29 @@ class VagrantTestPlugin implements Plugin<Project> {
391409
packagingTest.dependsOn(batsPackagingTest)
392410
}
393411

394-
// This task doesn't do anything yet. In the future it will execute a jar containing tests on the vm
395-
Task groovyPackagingTest = project.tasks.create("vagrant${boxTask}#groovyPackagingTest")
396-
groovyPackagingTest.dependsOn(up)
397-
groovyPackagingTest.finalizedBy(halt)
412+
Task javaPackagingTest = project.tasks.create("vagrant${boxTask}#javaPackagingTest", VagrantCommandTask) {
413+
command 'ssh'
414+
boxName box
415+
environmentVars vagrantEnvVars
416+
dependsOn up, setupPackagingTest
417+
finalizedBy halt
418+
args '--command', "cd \$PACKAGING_TESTS && ./run-tests.sh"
419+
}
420+
421+
// todo remove this onlyIf after all packaging tests are consolidated
422+
javaPackagingTest.onlyIf {
423+
project.extensions.esvagrant.testClass != null
424+
}
398425

399-
TaskExecutionAdapter groovyPackagingReproListener = createReproListener(project, groovyPackagingTest.path)
400-
groovyPackagingTest.doFirst {
401-
project.gradle.addListener(groovyPackagingReproListener)
426+
TaskExecutionAdapter javaPackagingReproListener = createReproListener(project, javaPackagingTest.path)
427+
javaPackagingTest.doFirst {
428+
project.gradle.addListener(javaPackagingReproListener)
402429
}
403-
groovyPackagingTest.doLast {
404-
project.gradle.removeListener(groovyPackagingReproListener)
430+
javaPackagingTest.doLast {
431+
project.gradle.removeListener(javaPackagingReproListener)
405432
}
406433
if (project.extensions.esvagrant.boxes.contains(box)) {
407-
packagingTest.dependsOn(groovyPackagingTest)
434+
packagingTest.dependsOn(javaPackagingTest)
408435
}
409436

410437
Task platform = project.tasks.create("vagrant${boxTask}#platformTest", VagrantCommandTask) {

qa/vagrant/build.gradle

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.elasticsearch.gradle.precommit.PrecommitTasks
2+
13
/*
24
* Licensed to Elasticsearch under one or more contributor
35
* license agreements. See the NOTICE file distributed with
@@ -17,8 +19,23 @@
1719
* under the License.
1820
*/
1921

20-
apply plugin: 'elasticsearch.vagrantsupport'
21-
apply plugin: 'elasticsearch.vagrant'
22+
plugins {
23+
id 'java'
24+
id 'elasticsearch.build'
25+
id 'elasticsearch.vagrantsupport'
26+
id 'elasticsearch.vagrant'
27+
}
28+
29+
dependencies {
30+
compile "junit:junit:${versions.junit}"
31+
compile "org.hamcrest:hamcrest-core:${versions.hamcrest}"
32+
33+
// needs to be on the classpath for JarHell
34+
runtime project(':libs:elasticsearch-core')
35+
36+
// pulls in the jar built by this project and its dependencies
37+
packagingTest project(path: project.path, configuration: 'runtime')
38+
}
2239

2340
List<String> plugins = []
2441
for (Project subproj : project.rootProject.subprojects) {
@@ -39,3 +56,20 @@ setupPackagingTest {
3956
expectedPlugins.setText(plugins.join('\n'), 'UTF-8')
4057
}
4158
}
59+
60+
esvagrant {
61+
testClass 'org.elasticsearch.packaging.PackagingTests'
62+
}
63+
64+
forbiddenApisMain {
65+
signaturesURLs = [
66+
PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')
67+
]
68+
}
69+
70+
// we don't have additional tests for the tests themselves
71+
tasks.test.enabled = false
72+
73+
// this project doesn't get published
74+
tasks.dependencyLicenses.enabled = false
75+
tasks.dependenciesInfo.enabled = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.packaging;
21+
22+
import org.junit.Test;
23+
24+
/**
25+
* This class doesn't have any tests yet
26+
*/
27+
public class PackagingTests {
28+
29+
@Test
30+
public void testDummy() {}
31+
}

0 commit comments

Comments
 (0)