scala 类路径中缺少符号“type io.gatling.core.check.FindCheckBuilder”

yrdbyhpb  于 12个月前  发布在  Scala
关注(0)|答案(1)|浏览(100)

我试着用Grpc实现gatling,通过phiSgr:

package load

import com.github.phisgr.gatling.grpc.Predef._
import example.myapp.helloworld.grpc.hello_world.{GreeterServiceGrpc, HelloRequest}
import io.gatling.core.Predef.{stringToExpression => _, _}
import io.grpc.Status
import load.Constants.grpcPsgConf
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

import scala.concurrent.duration.DurationInt
import scala.language.postfixOps

class GrpcSimulation extends Simulation {

  val scn = scenario("Make Hello Request and Get Response")
    .exec(grpc("Hello Request")
      .rpc(GreeterServiceGrpc.METHOD_SAY_HELLO)
      .payload(HelloRequest("Gatling Load Test"))
      .extract(_.message.some)(_ saveAs "message")
      .check(statusCode is Status.Code.OK)
    )
    .exec(grpc("Hello Request with parameter from session")
      .rpc(GreeterServiceGrpc.METHOD_SAY_HELLO)
      .payload(session => HelloRequest(session.attributes("message").asInstanceOf[String]))
      .check(statusCode is Status.Code.OK)
    )

  setUp(scn.inject(rampUsersPerSec(1) to (2) during (20 seconds)).protocols(grpcPsgConf.shareChannel))
}

当我运行 sbt compile 时,它可以成功完成,但是当我使用 *sbt“Gatling / testOnly .GrpcSimulation” 时,它会返回以下2个错误:

[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\BiDiStreamingSimulation.scala:16:23: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath.
[error] This symbol is required by 'value com.github.phisgr.gatling.grpc.check.GrpcCheckSupport.findCheckBuilder'.
[error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'GrpcCheckSupport.class' was compiled against an incompatible version of io.gatling.core.check.
[error]   val bidiCall = grpc("BiDi call").bidiStream("bidi")
[error]                       ^
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\GrpcSimulation.scala:20:28: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath.
[error] This symbol is required by 'value com.github.phisgr.gatling.grpc.request.CallDefinition.ts'.
[error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'CallDefinition.class' was compiled against an incompatible version of io.gatling.core.check.
[error]       .payload(HelloRequest("Gatling Load Test"))
[error]                            ^
[error] two errors found
[error] (Test / compileIncremental) Compilation failed
[error] Total time: 1 s, completed 09:20:29, 25 thg 9, 2023
sbt:gatling-grpc-tests-sample> reload
[info] welcome to sbt 1.9.6 (Oracle Corporation Java 17.0.8)
[info] loading settings for project gatling-grpc-tests-sample-build from assembly.sbt,gatling.sbt,plugins.sbt,scalapb.sbt ...
[info] loading project definition from C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project
[info] compiling 1 Scala source to C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\target\scala-2.12\sbt-1.0\classes ...
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\Dependencies.scala:2:11: object gatling is not a member of package sbt.io
[error] import io.gatling.core.Predef._
[error]           ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

我正在使用的build.sbt:

import Dependencies._

name := "gatling-grpc-tests-sample"

version := "0.1"

scalaVersion := "2.13.12"

libraryDependencies ++=  gatlingDependencies ++ loggingDependencies ++ grpcDependencies ++
  Seq(
    "com.github.daddykotex" %% "courier" % "3.0.0-M2a",
    "com.typesafe" % "config" % "1.4.1",
    "com.google.guava" % "guava" % "30.1.1-jre",
    "com.typesafe.akka" %% "akka-actor-typed" % "2.6.10",
    "com.typesafe.akka" %% "akka-protobuf-v3" % "2.6.10",
    "com.typesafe.akka" %% "akka-stream" % "2.6.10"
  )

enablePlugins(GatlingPlugin)

PB.targets in Compile := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)

gatling.sbt:

addSbtPlugin("io.gatling" % "gatling-sbt" % "4.5.0")

plugins.sbt:

addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "1.1.1")

scalapb.sbt”

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.10"

我该如何解决这个问题,有人能解释一下根本原因吗?任何帮助将不胜感激。
更改gatling和sbt版本以符合当前使用。

bzzcjhmw

bzzcjhmw1#

这显然是不兼容的依赖版本。
在评论OP说,
然而,我已经声明,我使用gatling-grpc v.0.16.0和gatling 3.9.5,仍然得到这个错误”
一个可能的原因是版本发生了变化,但构建工具仍然使用旧版本。
在这个错误日志中,我们可以看到原因。

[info] compiling 1 Scala source to C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\target\scala-2.12\sbt-1.0\classes ...
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\Dependencies.scala:2:11: object gatling is not a member of package sbt.io
[error] import io.gatling.core.Predef._
[error]           ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

出于某种原因,OP将import io.gatling.core.Predef._(测试代码的导入行)添加到构建脚本文件project/Dependencies.scala中。这个错误阻止了sbt重新加载和获得正确的依赖版本。
再一次,正如我在前面的回答中所指出的,使用Gatling并不一定要使用sbt或编写Scala。考虑到OP的混乱,他们应该坚持使用更主流的工具,如Gradle/Maven。

相关问题