Skip to content

Commit 65e5868

Browse files
[test] add java packaging test project (elastic#30161)
[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 e11070b commit 65e5868

File tree

5 files changed

+113
-17
lines changed

5 files changed

+113
-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/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

+41-15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class VagrantTestPlugin implements Plugin<Project> {
5151
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb']
5252

5353
private static final PACKAGING_CONFIGURATION = 'packaging'
54+
private static final PACKAGING_TEST_CONFIGURATION = 'packagingTest'
5455
private static final BATS = 'bats'
5556
private static final String BATS_TEST_COMMAND ="cd \$PACKAGING_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS"
5657
private static final String PLATFORM_TEST_COMMAND ="rm -rf ~/elasticsearch && rsync -r /elasticsearch/ ~/elasticsearch && cd ~/elasticsearch && ./gradlew test integTest"
@@ -66,6 +67,7 @@ class VagrantTestPlugin implements Plugin<Project> {
6667

6768
// Creates custom configurations for Bats testing files (and associated scripts and archives)
6869
createPackagingConfiguration(project)
70+
project.configurations.create(PACKAGING_TEST_CONFIGURATION)
6971

7072
// Creates all the main Vagrant tasks
7173
createVagrantTasks(project)
@@ -144,10 +146,12 @@ class VagrantTestPlugin implements Plugin<Project> {
144146
}
145147

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

@@ -174,6 +178,18 @@ class VagrantTestPlugin implements Plugin<Project> {
174178
from project.configurations[PACKAGING_CONFIGURATION]
175179
}
176180

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

235251
Task vagrantSetUpTask = project.tasks.create('setupPackagingTest')
236252
vagrantSetUpTask.dependsOn 'vagrantCheckVersion'
237-
vagrantSetUpTask.dependsOn copyPackagingArchives, createVersionFile, createUpgradeFromFile, createUpgradeIsOssFile
253+
vagrantSetUpTask.dependsOn copyPackagingArchives, copyPackagingTests, createTestRunnerScript
254+
vagrantSetUpTask.dependsOn createVersionFile, createUpgradeFromFile, createUpgradeIsOssFile
238255
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils
239256
}
240257

@@ -393,20 +410,29 @@ class VagrantTestPlugin implements Plugin<Project> {
393410
packagingTest.dependsOn(batsPackagingTest)
394411
}
395412

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

401-
TaskExecutionAdapter groovyPackagingReproListener = createReproListener(project, groovyPackagingTest.path)
402-
groovyPackagingTest.doFirst {
403-
project.gradle.addListener(groovyPackagingReproListener)
427+
TaskExecutionAdapter javaPackagingReproListener = createReproListener(project, javaPackagingTest.path)
428+
javaPackagingTest.doFirst {
429+
project.gradle.addListener(javaPackagingReproListener)
404430
}
405-
groovyPackagingTest.doLast {
406-
project.gradle.removeListener(groovyPackagingReproListener)
431+
javaPackagingTest.doLast {
432+
project.gradle.removeListener(javaPackagingReproListener)
407433
}
408434
if (project.extensions.esvagrant.boxes.contains(box)) {
409-
packagingTest.dependsOn(groovyPackagingTest)
435+
packagingTest.dependsOn(javaPackagingTest)
410436
}
411437

412438
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+
testRuntime 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)