使用SBT测试运行时Spark测试失败

太空堡

我们已经编写了具有4个线程的本地模式下的Spark单元测试。

例如通过intellij或sbt testOnly一次启动时,每个测试运行正常。

使用sbt测试启动时,它们会失败,并显示以下错误:

[info] java.util.ServiceConfigurationError: org.apache.spark.sql.sources.DataSourceRegister: Provider org.apache.spark.sql.execution.datasources.csv.CSVFileFormat not a subtype

我们特别将sbt和spark版本升级到了最新版本,并尝试fork in test := true在build.sbt中运行,但这没有帮助。

Spark在2.4.3版本,sbt 1.2.8和2.12.8版本的scala中。

sbt config没什么特别的:

libraryDependencies ++= Seq(
  Dependencies.Test.concordion,
  Dependencies.`spark-sql` exclude("org.slf4j","slf4j-log4j12"),
  Dependencies.`better-files`
)

fork in test := true


dependencyOverrides += "com.google.guava" % "guava" % "11.0.2" 
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.6.7.1"

我们将sbt项目与多个子项目一起使用,定义方式如下:

scalacOptions in ThisBuild ++= Seq(
  "-encoding", "UTF-8", // source files are in UTF-8
  "-deprecation", // warn about use of deprecated APIs
  "-Yrangepos", // use range positions for syntax trees
  "-language:postfixOps", //  enables postfix operators
  "-language:implicitConversions", // enables defining implicit methods and members
  "-language:existentials", // enables writing existential types
  "-language:reflectiveCalls", // enables reflection
  "-language:higherKinds", // allow higher kinded types without `import scala.language.higherKinds`
  "-unchecked", // warn about unchecked type parameters
  "-feature", // warn about misused language features
  /*"-Xlint",               // enable handy linter warnings
    "-Xfatal-warnings",     // turn compiler warnings into errors*/
  "-Ypartial-unification" // allow the compiler to unify type constructors of different arities
)

autoCompilerPlugins := true

addCompilerPlugin(Dependencies.`kind-projector`)
addCompilerPlugin(Dependencies.`better-monadic-for`)


// Define the root project, and make it compile all child projects
lazy val `datarepo` =
  project
    .in(file("."))
    .aggregate(
      `foo`,
      `foo-other`,
      `sparkusingproject`,
      `sparkusingproject-test`,
      `sparkusingproject-other`,
    )

// Define individual projects, the directories they reside in, and other projects they depend on
lazy val `foo` =
  project
    .in(file("foo"))
    .settings(Common.defaultSettings: _*)

lazy val `foo-other` =
  project
    .in(file("foo-other"))
    .dependsOn(`foo`)
    .settings(Common.defaultSettings: _*)

伊凡·韦吉里耶夫(Ivan Vergiliev)

我只是在测试中遇到了此异常,这是由于尝试在与我启动的线程不同的线程中运行Spark动作引起的SparkSession您可能要禁用parallelExecution in Test(无论如何,建议在Spark集成测试中使用此功能)。

具体来说,我试图并行执行多个Spark动作,并尝试在Scala的ExecutionContext.global线程池中执行该操作当我创建一个newFixedPoolExecutor代替时,一切开始正常工作。

AFAICT这是因为,在中DataSource.scala:610,Spark获取线程的ContextClassLoader:

    val loader = Utils.getContextOrSparkClassLoader

并且,当在Scala的默认线程池中运行时,类加载器不包含相关的类和接口。相反,当您创建一个新的线程池时,它将从当前线程继承正确的类加载器,然后正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android的测试运行失败:没有测试结果

使用鼻子测试运行Django测试

将Maven依赖声明为仅测试运行时

我可以在测试运行时跳过JUnit测试吗?

bazel-测试运行时的可写归档路径

如何使用dotnet测试运行特定测试?

从测试运行时,getResourceAsStream(“ file”)在哪里搜索?

测试运行时未调用C#中的nUnit SetupFixture类

作为Maven测试运行时,TestNG测试失败,但作为TestNG套件运行时,则通过

在硒测试运行时,HTTP URL重定向为HTTPS

Angular 2+服务测试。服务导入在ng测试运行时未定义

Android Espresso UI测试----测试运行失败:由于“进程崩溃”,仪表运行失败。

在将应用程序作为TestNG测试运行时破坏测试用例

通过Jest获取测试运行时间

如何使用Vividus工具同步测试运行?

dotnet test命令显示单个测试运行时间?

Junit4在测试运行时引发异常

如何使用在测试运行时确定的类来创建特定GUI类的测试对象?

如何通过Mocha测试运行时参数?

具有预期异常的测试将产生以下错误:“测试运行时,代理进程已停止。”

作为插件测试运行时,不同项目中重复的软件包名称会导致InvalidAccessException

MAVEN:使用Maven测试运行多个Maven项目

使用JUNIT测试运行AsyncHttpClient

当我取消单元测试运行时,当前运行的测试是否完成?

cypress 测试运行时无法加载地图和 css 的图块

通过 spring boot 测试运行时,控制器中未发生 Bean 注入

ng 测试运行失败,tsconfig 路径映射

如何在测试运行时类型检查期间模拟 Python 类?

在 Selenium 中将类作为 TestNG 测试运行时出现 java.lang.StackOverflowError