diff --git a/flink-scala-shell/pom.xml b/flink-scala-shell/pom.xml index 6f490e44eed53a457662873feb0e593f88e59376..e3126991235bcd644b9cb9a7b40aad723ae04bbc 100644 --- a/flink-scala-shell/pom.xml +++ b/flink-scala-shell/pom.xml @@ -242,6 +242,61 @@ under the License. + + maven-assembly-plugin + 2.4 + + + create-library-loading-jar + process-test-classes + + single + + + + + + + + customjar + false + + src/test/assembly/test-scalashell-customjar-assembly.xml + + + + + + + + + + maven-clean-plugin + 2.5 + + + remove-classloading-test-dependencies + process-test-classes + + clean + + + true + + + ${project.build.testOutputDirectory} + + **/jar/*.class + + + + + + + + diff --git a/flink-scala-shell/src/test/assembly/test-scalashell-customjar-assembly.xml b/flink-scala-shell/src/test/assembly/test-scalashell-customjar-assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef20cfd5e517e588dc3768a23a25315d3cefca5b --- /dev/null +++ b/flink-scala-shell/src/test/assembly/test-scalashell-customjar-assembly.xml @@ -0,0 +1,35 @@ + + + + test-jar + + jar + + false + + + ${project.build.testOutputDirectory} + / + + + org/apache/flink/api/scala/jar/* + + + + diff --git a/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/ScalaShellITCase.scala b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/ScalaShellITCase.scala index 0e89da3b9a29508486d280eadb376163e4be4bbf..ce08304395c0c925dcfb3d0c104499652cd11180 100644 --- a/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/ScalaShellITCase.scala +++ b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/ScalaShellITCase.scala @@ -169,36 +169,19 @@ class ScalaShellITCase extends TestLogger { def testSubmissionOfExternalLibraryBatch: Unit = { val input = """ - import org.apache.flink.ml.math._ - val denseVectors = benv.fromElements[Vector](DenseVector(1.0, 2.0, 3.0)) - denseVectors.print() + import org.apache.flink.api.scala.jar.TestingData + val source = benv.fromCollection(TestingData.elements) + source.print() """.stripMargin - // find jar file that contains the ml code - var externalJar = "" - val folder = findLibraryFolder( - "../flink-libraries/flink-ml/target/", - "../../flink-libraries/flink-ml/target/") - - val listOfFiles = folder.listFiles() - - for (i <- listOfFiles.indices) { - val filename: String = listOfFiles(i).getName - if (!filename.contains("test") && !filename.contains("original") && filename.contains( - ".jar")) { - externalJar = listOfFiles(i).getAbsolutePath - } - } - - assert(externalJar != "") - - val output: String = processInShell(input, Option(externalJar)) + val output: String = processInShell(input, Option("customjar-test-jar.jar")) Assert.assertFalse(output.contains("failed")) Assert.assertFalse(output.contains("error")) Assert.assertFalse(output.contains("Exception")) - Assert.assertTrue(output.contains("\nDenseVector(1.0, 2.0, 3.0)")) + + Assert.assertTrue(output.contains("\nHELLO 42")) } /** Submit external library */ @@ -206,37 +189,19 @@ class ScalaShellITCase extends TestLogger { def testSubmissionOfExternalLibraryStream: Unit = { val input = """ - import org.apache.flink.ml.math._ - val denseVectors = senv.fromElements[Vector](DenseVector(1.0, 2.0, 3.0)) - denseVectors.print() + import org.apache.flink.api.scala.jar.TestingData + val source = senv.fromCollection(TestingData.elements) + source.print() senv.execute """.stripMargin - // find jar file that contains the ml code - var externalJar = "" - val folder = findLibraryFolder( - "../flink-libraries/flink-ml/target/", - "../../flink-libraries/flink-ml/target/") - - val listOfFiles = folder.listFiles() - - for (i <- listOfFiles.indices) { - val filename: String = listOfFiles(i).getName - if (!filename.contains("test") && !filename.contains("original") && filename.contains( - ".jar")) { - externalJar = listOfFiles(i).getAbsolutePath - } - } - - assert(externalJar != "") - - val output: String = processInShell(input, Option(externalJar)) + val output: String = processInShell(input, Option("customjar-test-jar.jar")) Assert.assertFalse(output.contains("failed")) Assert.assertFalse(output.contains("error")) Assert.assertFalse(output.contains("Exception")) - Assert.assertTrue(output.contains("\nDenseVector(1.0, 2.0, 3.0)")) + Assert.assertTrue(output.contains("\nHELLO 42")) } @@ -413,14 +378,4 @@ object ScalaShellITCase { case _ => throw new IllegalStateException("The cluster has not been started.") } } - - def findLibraryFolder(paths: String*): File = { - for (path <- paths) { - val folder = new File(path) - if (folder.exists()) { - return folder - } - } - throw new RuntimeException("Library folder not found in any of the supplied paths!") - } } diff --git a/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/TestingData.scala b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/TestingData.scala new file mode 100644 index 0000000000000000000000000000000000000000..428a8e6e3decd640c464da3cd0856a6b01aa8c2b --- /dev/null +++ b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/TestingData.scala @@ -0,0 +1,26 @@ +/* + * 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. + */ +package org.apache.flink.api.scala.jar + +/** + * Testing data for [[org.apache.flink.api.scala.ScalaShellITCase]]. This will be put into a + * separate jar file to test loading of external libraries. + */ +object TestingData { + val elements = Seq("HELLO 42", "CIAO", "BLA", "BLU") +} diff --git a/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/package.scala b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/package.scala new file mode 100644 index 0000000000000000000000000000000000000000..51303f27486a7dd3c7f1c1fc95d8690dcaf19330 --- /dev/null +++ b/flink-scala-shell/src/test/scala/org/apache/flink/api/scala/jar/package.scala @@ -0,0 +1,25 @@ +/* + * 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. + */ +package org.apache.flink.api.scala + +/** + * Custom objects for use in testing loading of external jars in [[ScalaShellITCase]]. + */ +package object jar { + +}