错误:找不到或加载主类io.gatling.app.Gatling [英] Error: Could not find or load main class io.gatling.app.Gatling

查看:169
本文介绍了错误:找不到或加载主类io.gatling.app.Gatling的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取错误:运行jar进行性能测试时找不到或加载主类io.gatling.app.Gatling ,但是当我在intellij上运行相同的代码时,效果很好 以下是执行代码的示例步骤

Getting Error: Could not find or load main class io.gatling.app.Gatling while running a jar for performance test,but works fine when I run the same code on intellij Below are the Sample steps for the execution of code

步骤:1 使用Gatling创建了PerformanceTest.jar的mvn包.

Step:1 Created a mvn package of PerformanceTest.jar using Gatling.

SampleTestPlayer.scala

package com.performance.SampleTest
import com.performance.config.ScenarioConfiguration
import com.performance.{Player, Feeders}
import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._

import scala.concurrent.duration._
import scala.util.Random

class SampleTestPlayer extends SomeClass {

  val config: ScenarioConfiguration.type = ScenarioConfiguration
  gdmServerEndpoint = config.gdmServerUrl
  Name = config.Name

  val regexGsdViewArea = "VA~(?:[\\d\\|]+?)+"


  def play(): ChainBuilder = {
    exec(http(TEST)
      .post(ServerEndpoint)
      .body(StringBody(session => bodyXml(session, config.Name,
        prepareRequest(session, config.Name, 10, 5))))
      .check(status.is(200)
        , regex("<SUCCESS>true</SUCCESS>").exists
        , regex(errorMsgId).notExists
        , regex(errorProtocol).optional.saveAs(errorProtocol)
      )
    )
      .exec(checkForErrors)
      .pause(requestsInterval)
     
  }


  val scn: ScenarioBuilder = scenario("SampleTest_Performance_Tests")
    .feed(Feeders.operator1UsersFeeder)
    .exec({ session => session.set("recoverAfterRequest", false)})
    .repeat(config.numPlays) {
      play()
    }

  if (config.model == "closed") {
    setUp(
      scn.inject(
        rampUsers(config.numUsers) during (config.rampUpDuration)
      ).protocols(buildHttpConf(config.baseUrl))
    )
  }

  if (config.model == "open") {
    setUp(
      scn.inject(
        nothingFor(4 seconds), // 1
        atOnceUsers(10), // 2
        rampUsers(5) during (20 seconds), // 3
        constantUsersPerSec(2) during (15 seconds), // 4
        constantUsersPerSec(2) during (15 seconds) randomized, // 5
        rampUsersPerSec(2) to 5 during (1 minutes), // 6
        rampUsersPerSec(2) to 5 during (1 minutes) randomized, // 7
        heavisideUsers(100) during (20 seconds) // 8
      ).protocols(buildHttpConf(config.baseUrl))
    )
  }
}constantUsersPerSec(2) during (15 seconds) randomized, // 5
        rampUsersPerSec(2) to 5 during (1 minutes), // 6
        rampUsersPerSec(2) to 5 during (1 minutes) randomized, // 7
        heavisideUsers(100) during (20 seconds) // 8
      ).protocols(buildHttpConf(config.baseUrl))
    )
  }
}

SampleTestRunner.scala

package com.performance.SampleTest

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder

object SampleTestRunner {



  def main(args: Array[String]): Unit = {
    System.setProperty("baseUrl", "https://SomeUrl")

    System.setProperty("Name", "SampleTest")
  
    System.setProperty("requestsInterval", "1000")

    val simulationClass = classOf[SampleTestPlayer].getName

    val props = new GatlingPropertiesBuilder
    props.simulationClass(simulationClass)

    Gatling.fromMap(props.build)
  }
}

步骤:2 创建launch.sh文件以运行这些测试.

Step:2 Create a launch.sh file to run these test.

launch.sh

#!/bin/sh
USER_ARGS="-Dsomething=$1"
COMPILATION_CLASSPATH=`find -L . -maxdepth 1 -name "*.jar" -type f -exec printf :{} ';'`
JAVA_OPTS="-server -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms512M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:+AggressiveOpts -XX:+OptimizeStringConcat -XX:+UseFastAccessorMethods -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false ${JAVA_OPTS} -DName=sampletest -DbaseUrl=https://SomeUrl -DnumPlays=100 -Dmodel=closed -DnumUsers=1000 -DrequestsInterval=10000 -DrampUpDuration=3000"
java $JAVA_OPTS $USER_ARGS -cp $COMPILATION_CLASSPATH io.gatling.app.Gatling -s com.performance.sampletest.SampleTestPlayer 

推荐答案

我使用以下代码在缺少-jar jar_name命令的情况下开始测试.

I used the following to start the tests where the -jar jar_name command was missing.

注意:首先是环境变量(以-D开头),然后是jar,然后是Player(java< environment_variables> -jar perf_tests.jar -s PlayerClass

Note: That the environment variables (starting with -D) come first and then it’s the jar and then the Player (java <environment_variables> -jar perf_tests.jar -s PlayerClass

#!/bin/sh
USER_ARGS="-Dsomething=$1"
COMPILATION_CLASSPATH=`find -L . -maxdepth 1 -name "*.jar" -type f -exec printf :{} ';'`
JAVA_OPTS="-server -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms512M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:+AggressiveOpts -XX:+OptimizeStringConcat -XX:+UseFastAccessorMethods -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false 
java -DbaseUrl=https://SomeUrl -DnumPlays=100 -Dmodel=closed -DnumUsers=1000 -DrequestsInterval=3000 -jar performance-tests-1.0.0-SNAPSHOT.jar -s com.performance.sampletest.SampleTestPlayer

这篇关于错误:找不到或加载主类io.gatling.app.Gatling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆