Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4215#discussion_r23962607
  
    --- Diff: 
core/src/test/scala/org/apache/spark/deploy/SparkSubmitUtilsSuite.scala ---
    @@ -0,0 +1,100 @@
    +/*
    + * 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.spark.deploy
    +
    +import java.io.File
    +
    +import org.apache.ivy.core.module.descriptor.MDArtifact
    +import org.apache.ivy.plugins.resolver.IBiblioResolver
    +import org.scalatest.FunSuite
    +
    +class SparkSubmitUtilsSuite extends FunSuite {
    +
    +  test("incorrect maven coordinate throws error") {
    +    val coordinates = Seq("a:b: ", " :a:b", "a: :b", "a:b:", ":a:b", 
"a::b", "::", "a:b", "a")
    +    for (coordinate <- coordinates) {
    +      intercept[IllegalArgumentException] {
    +        SparkSubmitUtils.extractMavenCoordinates(coordinate)
    +      }
    +    }
    +  }
    +
    +  test("create repo resolvers") {
    +    val resolver1 = SparkSubmitUtils.createRepoResolvers(None)
    +    // should have central by default
    +    assert(resolver1.getResolvers.size() === 1)
    +    
assert(resolver1.getResolvers.get(0).asInstanceOf[IBiblioResolver].getName === 
"central")
    +
    +    val repos = "a/1,b/2,c/3"
    +    val resolver2 = SparkSubmitUtils.createRepoResolvers(Option(repos))
    +    assert(resolver2.getResolvers.size() === 4)
    +    val expected = repos.split(",").map(r => s"$r/")
    +    resolver2.getResolvers.toArray.zipWithIndex.foreach { case (resolver: 
IBiblioResolver, i) =>
    +      if (i == 0) {
    +        assert(resolver.getName === "central")
    +      } else {
    +        assert(resolver.getName === s"repo-$i")
    +        assert(resolver.getRoot === expected(i - 1))
    +      }
    +    }
    +  }
    +
    +  test("add dependencies works correctly") {
    +    val md = SparkSubmitUtils.getModuleDescriptor
    +    val artifacts = 
SparkSubmitUtils.extractMavenCoordinates("com.databricks:spark-csv_2.10:0.1," +
    +      "com.databricks:spark-avro_2.10:0.1")
    +
    +    SparkSubmitUtils.addDependenciesToIvy(md, artifacts, "default")
    +    assert(md.getDependencies.length === 2)
    +  }
    +
    +  test("ivy path works correctly") {
    +    val ivyPath = "dummy/ivy"
    +    val md = SparkSubmitUtils.getModuleDescriptor
    +    val artifacts = for (i <- 0 until 3) yield new MDArtifact(md, 
s"jar-$i", "jar", "jar")
    +    var jPaths = 
SparkSubmitUtils.resolveDependencyPaths(artifacts.toArray, new File(ivyPath))
    +    for (i <- 0 until 3) {
    +      val index = jPaths.indexOf(ivyPath)
    +      assert(index >= 0)
    +      jPaths = jPaths.substring(index + ivyPath.length)
    +    }
    +    // end to end
    +    val jarPath = SparkSubmitUtils.resolveMavenCoordinates(
    +      "com.databricks:spark-csv_2.10:0.1", None, Option(ivyPath), true)
    +    assert(jarPath.indexOf(ivyPath) >= 0, "should use non-default ivy 
path")
    +  }
    +
    +  test("search for artifact at other repositories") {
    +    val path = 
SparkSubmitUtils.resolveMavenCoordinates("com.agimatec:agimatec-validation:0.9.3",
    +      Option("https://oss.sonatype.org/content/repositories/agimatec/";), 
None, true)
    +    assert(path.indexOf("agimatec-validation") >= 0, "should find package. 
If it doesn't, check" +
    +      "if package still exists. If it has been removed, replace the 
example in this test.")
    --- End diff --
    
    It would be cool if there was some way to mock out the Maven repository so 
that this test isn't reliant on third-party services that we don't control; 
that would also allow the test to run without an internet connection.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to