Skip to content

Commit de8c04a

Browse files
committed
Pass itest jar path to tests through system property (#1443)
1 parent 312f537 commit de8c04a

File tree

4 files changed

+14
-43
lines changed

4 files changed

+14
-43
lines changed

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/BuildPlugin.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ class BuildPlugin implements Plugin<Project> {
414414

415415
Test integrationTest = project.tasks.create('integrationTest', RestTestRunnerTask.class)
416416
integrationTest.dependsOn(itestJar)
417+
integrationTest.doFirst {
418+
integrationTest.systemProperty("es.hadoop.job.jar", itestJar.getArchiveFile().get().asFile.absolutePath)
419+
}
417420

418421
integrationTest.testClassesDirs = project.sourceSets.itest.output.classesDirs
419422
integrationTest.classpath = project.sourceSets.itest.runtimeClasspath

mr/src/itest/java/org/elasticsearch/hadoop/ProvisionerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.elasticsearch.hadoop;
2020

21-
import org.elasticsearch.hadoop.HdpBootstrap;
22-
import org.elasticsearch.hadoop.Provisioner;
2321
import org.junit.Test;
2422

2523
public class ProvisionerTest {

spark/core/itest/java/org/elasticsearch/spark/integration/SparkUtils.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,17 @@
1818
*/
1919
package org.elasticsearch.spark.integration;
2020

21-
import java.io.File;
22-
import java.io.FileFilter;
23-
import java.io.IOException;
2421
import java.lang.reflect.Constructor;
25-
import java.util.Arrays;
2622

2723
import org.apache.spark.SparkConf;
28-
import org.elasticsearch.hadoop.util.Assert;
24+
import org.elasticsearch.hadoop.Provisioner;
2925
import org.elasticsearch.hadoop.util.ReflectionUtils;
3026

3127
import com.esotericsoftware.kryo.Kryo;
3228

3329
public abstract class SparkUtils {
3430

35-
public static final String[] ES_SPARK_TESTING_JAR;
36-
37-
static {
38-
// init ES-Hadoop JAR
39-
// expect the jar under build\libs
40-
try {
41-
File folder = new File("build" + File.separator + "libs" + File.separator).getCanonicalFile();
42-
System.out.println(folder.getAbsolutePath());
43-
// find proper jar
44-
File[] files = folder.listFiles(new FileFilter() {
45-
46-
@Override
47-
public boolean accept(File pathname) {
48-
return pathname.getName().contains("-testing.jar");
49-
}
50-
});
51-
Assert.isTrue(files != null && files.length == 1,
52-
String.format("Cannot find elasticsearch spark jar (too many or no file found);%s", Arrays.toString(files)));
53-
ES_SPARK_TESTING_JAR = new String[] { files[0].getAbsoluteFile().toURI().toString() };
54-
55-
} catch (IOException ex) {
56-
throw new RuntimeException("Cannot find required files", ex);
57-
}
58-
}
31+
public static final String[] ES_SPARK_TESTING_JAR = new String[] {Provisioner.ESHADOOP_TESTING_JAR};
5932

6033
public static Kryo sparkSerializer(SparkConf conf) throws Exception {
6134
// reflection galore

test/shared/src/main/java/org/elasticsearch/hadoop/Provisioner.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ public abstract class Provisioner {
3737

3838
public static final String ESHADOOP_TESTING_JAR;
3939
public static final String HDFS_ES_HDP_LIB = "/eshdp/libs/es-hadoop.jar";
40+
public static final String SYS_PROP_JOB_JAR = "es.hadoop.job.jar";
4041

4142
static {
4243
// init ES-Hadoop JAR
4344
// expect the jar under build\libs
4445
try {
45-
File folder = new File("build" + File.separator + "libs" + File.separator).getCanonicalFile();
46-
// find proper jar
47-
File[] files = folder.listFiles(new FileFilter() {
48-
49-
@Override
50-
public boolean accept(File pathname) {
51-
return pathname.getName().contains("-testing");
52-
}
53-
});
54-
Assert.isTrue(files != null && files.length == 1,
55-
String.format("Cannot find elasticsearch hadoop jar (too many or no file found);%s", Arrays.toString(files)));
56-
ESHADOOP_TESTING_JAR = files[0].getAbsoluteFile().toURI().toString();
46+
String jobJarLocation = System.getProperty(SYS_PROP_JOB_JAR);
47+
if (jobJarLocation == null) {
48+
throw new RuntimeException("Cannot find elasticsearch hadoop jar. System Property [" + SYS_PROP_JOB_JAR + "] was not set.");
49+
}
5750

51+
File testJar = new File(jobJarLocation).getCanonicalFile();
52+
Assert.isTrue(testJar.exists(),
53+
String.format("Cannot find elasticsearch hadoop jar. File not found [%s]", testJar));
54+
ESHADOOP_TESTING_JAR = testJar.getAbsolutePath();
5855
} catch (IOException ex) {
5956
throw new RuntimeException("Cannot find required files", ex);
6057
}

0 commit comments

Comments
 (0)