gatling、scala、svn 测试案例

package svnperformance

import akka.actor.Props
import akka.actor.ActorRef
import io.gatling.core.scenario.configuration.Simulation
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.structure.ChainBuilder
import io.gatling.core.config.ProtocolConfigurationRegistry
import io.gatling.core.Predef._
import io.gatling.core.action.Action
import io.gatling.core.action.system
import io.gatling.core.result.writer.DataWriter
import io.gatling.core.result.message.RequestMessage
import io.gatling.core.result.message.{ KO, OK }
import org.tmatesoft.svn.core.SVNURL
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory
import org.tmatesoft.svn.core.wc.SVNWCUtil
import org.tmatesoft.svn.core.io.SVNRepositoryFactory
import org.tmatesoft.svn.core.wc.SVNClientManager
import org.tmatesoft.svn.core.wc.SVNRevision
import org.tmatesoft.svn.core.ISVNLogEntryHandler
import java.io.File
import java.util.Date
import scala.util.Random

class SVNTest extends Simulation {
  val checkout = new ActionBuilder {
    override def build(next: ActorRef, protocolConfigurationRegistry: ProtocolConfigurationRegistry) = system.actorOf(Props(new CheckoutAction(next)))
  }
  val checkoutList = List(checkout)
  val checktry = new ChainBuilder(checkoutList)

  val importfiles = new ActionBuilder {
    override def build(next: ActorRef, protocolConfigurationRegistry: ProtocolConfigurationRegistry) = system.actorOf(Props(new ImportAction(next)))
  }
  val importfilesList = List(importfiles)
  val importtry = new ChainBuilder(importfilesList)
 
  val logcheck = new ActionBuilder {
    override def build(next: ActorRef, protocolConfigurationRegistry: ProtocolConfigurationRegistry) = system.actorOf(Props(new LogAction(next)))
  }
  val logcheckList = List(logcheck)
  val logtry = new ChainBuilder(logcheckList)
 
  //val scn_checkout = scenario("checkout").during(60,"",false){checktry} // error!
  //val scn_checkout = scenario("checkout").tryMax(10) { checktry } // cant stop!
  //val scn_checkout = scenario("checkout").exitBlockOnFail(checktry) // cant stop!
  //val scn_checkout = scenario("checkout").repeat(5){checktry}.exitHereIfFailed
  val scn_checkout = scenario("checkout").repeat(10) { checktry } //repeat 5 times
  val scn_import = scenario("importfiles").repeat(10) { importtry } //repeat 5 times
  val scn_log = scenario("logcheck").repeat(10) { logtry } //repeat 5 times

  setUp(scn_checkout.inject(ramp(20 users).over(10)),
    scn_import.inject(ramp(20 users).over(10)),
    scn_log.inject(ramp(10 users).over(10))
  )
}

class CheckoutAction(val next: ActorRef) extends Action() {
  /*val svnhost = "http://svn-dr.paic.com.cn/svn/svntest/trunk/smallDir2/"
  val user = "svntest002"
  val pass = "Paic1234"*/
  val svnhost = "https://192.168.1.199/svn/projects/trunk/Data2/"
  val user = "orj"
  val pass = "123"

  override def execute(session: Session) {
    try {
      var start = new Date().getTime

      val aa = new Random().nextInt(10) + 1
      val bb = new Random().nextInt(10) + 1
      val url0 = svnhost + "tmp" + aa.toString + "/tmp" + bb.toString //
      println(url0)
      val url = SVNURL.parseURIEncoded(url0) //svnurl

      val cc = new Random().nextInt(100000) + 1
      val desDir0 = "D:/tmp/tmp00/tmp" + start + cc.toString //
      println(desDir0)
      val desDir = new File(desDir0) //local path

      DAVRepositoryFactory.setup
      val options = SVNWCUtil.createDefaultOptions(true)
      val authManager = SVNWCUtil.createDefaultAuthenticationManager(user, pass)
      val repos = SVNRepositoryFactory.create(url)
      repos.setAuthenticationManager(authManager)
      val svnclient = SVNClientManager.newInstance
      val updateclient = svnclient.getUpdateClient
      updateclient.setIgnoreExternals(false)
      val revision = repos.getLatestRevision
      println(revision);

      println("checkout")
      val checkout = updateclient.doCheckout(url, desDir, SVNRevision.UNDEFINED, SVNRevision.HEAD, true)
      println(checkout.toString());
      var end = new Date().getTime
      DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "checkout", start, end, end, end, OK, None, Nil))
    } catch {
      case e: Throwable => {
        var start = new Date().getTime
        e.printStackTrace
        var end = new Date().getTime
        DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "checkout", start, end, end, end, KO, None, Nil))
      }
    }
    next ! session
  }
}

class ImportAction(val next: ActorRef) extends Action() {
  /*val svnhost = "http://svn-dr.paic.com.cn/svn/svntest/trunk/commit/tmp0/"
  val user = "svntest002"
  val pass = "Paic1234"*/
  val svnhost = "https://192.168.1.199/svn/projects/trunk/Data3/"
  val user = "orj"
  val pass = "123"

  override def execute(session: Session) {
    try {
      var start = new Date().getTime
      val aa = new Random().nextInt(100000) + 1
      val svnurl0 = svnhost + "tmp" + start + aa.toString //
      println(svnurl0)
      val svnurl = SVNURL.parseURIEncoded(svnurl0) //svnurl

      val bb = new Random().nextInt(10) + 1
      val localDir0 = "D:/tmp/Data/tmp" + bb.toString //
      println(localDir0)
      val localDir = new File(localDir0)

      DAVRepositoryFactory.setup
      val options = SVNWCUtil.createDefaultOptions(true)
      val authManager = SVNWCUtil.createDefaultAuthenticationManager(user, pass)
      val repos = SVNRepositoryFactory.create(svnurl)
      repos.setAuthenticationManager(authManager)
      val svnClient = SVNClientManager.newInstance
      val importClient = svnClient.getCommitClient()
      importClient.setIgnoreExternals(false)
      val revision = repos.getLatestRevision
      println(revision);

      println("importFiles")
      val importFiles = importClient.doImport(localDir, svnurl, "", true)
      println(importFiles.toString());
      var end = new Date().getTime
      DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "importFiles", start, end, end, end, OK, None, Nil))
    } catch {
      case e: Throwable => {
        var start = new Date().getTime
        e.printStackTrace
        var end = new Date().getTime
        DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "importFiles", start, end, end, end, KO, None, Nil))
      }
    }
    next ! session
  }
}

class LogAction(val next: ActorRef) extends Action() {
  /*val svnhost = "http://svn-dr.paic.com.cn/svn/svntest/trunk/commit/tmp0/"
  val user = "svntest002"
  val pass = "Paic1234"*/
  val svnhost = "https://192.168.1.199/svn/projects/trunk/Data3/"
  val user = "orj"
  val pass = "123"

  override def execute(session: Session) {
    try {
      var start = new Date().getTime

      val svnurl = SVNURL.parseURIEncoded(svnhost) //svnurl

      val bb = new Random().nextInt(10) + 1
      val localDir0 = "D:/tmp/"
      println(localDir0)
      val localDir = new File(localDir0)

      DAVRepositoryFactory.setup
      val options = SVNWCUtil.createDefaultOptions(true)
      val authManager = SVNWCUtil.createDefaultAuthenticationManager(user, pass)
      val repos = SVNRepositoryFactory.create(svnurl)
      repos.setAuthenticationManager(authManager)
      val svnClient = SVNClientManager.newInstance
      val logClient = svnClient.getLogClient()
      logClient.setIgnoreExternals(false)
      val revision = repos.getLatestRevision
      println(revision);
      val r = SVNRevision.create(revision)

      println("importFiles")
      val logCheck = logClient.doLog(svnurl, new Array[String](0), r, r, r, false, false, true, 1, new Array[String](0), null)
      println(logCheck.toString());
      var end = new Date().getTime
      DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "logCheck", start, end, end, end, OK, None, Nil))
    } catch {
      case e: Throwable => {
        var start = new Date().getTime
        e.printStackTrace
        var end = new Date().getTime
        DataWriter.tell(RequestMessage(session.scenarioName, session.userId, Nil, "logCheck", start, end, end, end, KO, None, Nil))
      }
    }
    next ! session
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要获取两个版本之间的差异代码,可以使用Java SVNKit库中的SVNLogClient类的doLog方法。具体步骤如下: 1. 创建SVNClientManager对象和SVNLogClient对象。 ```java SVNClientManager cm = SVNClientManager.newInstance(); SVNLogClient logClient = cm.getLogClient(); ``` 2. 创建两个SVNRevision对象,分别表示要对比的两个版本。 ```java SVNRevision startRevision = SVNRevision.create(startRevNum); SVNRevision endRevision = SVNRevision.create(endRevNum); ``` 3. 调用doLog方法获取版本之间的差异日志信息。 ```java SVNURL url = SVNURL.parseURIEncoded(svnUrl); long limit = 0; boolean discoverChangedPaths = true; boolean strictNode = true; Collection<SVNLogEntry> logEntries = logClient.doLog(url, null, startRevision, endRevision, true, discoverChangedPaths, strictNode, limit, null); ``` 其中,参数说明: - url:SVN代码仓库的URL。 - null:表示获取全部日志信息,也可以设置为只获取某个文件夹或文件的日志信息。 - startRevision和endRevision:要对比的两个版本。 - true:表示获取变更路径信息。 - discoverChangedPaths:表示获取详细的变更路径信息。 - strictNode:表示在获取变更路径时是否严格匹配文件路径。 - limit:表示限制获取的日志数量,0表示不限制。 - null:表示不指定获取日志的回调函数。 4. 遍历所有日志条目,获取差异代码。 ```java for (SVNLogEntry logEntry : logEntries) { Map<String, SVNLogEntryPath> changedPaths = logEntry.getChangedPaths(); for (String path : changedPaths.keySet()) { SVNLogEntryPath entryPath = changedPaths.get(path); if (entryPath.getType() == SVNLogEntryPath.TYPE_MODIFIED) { String diffCode = getDiffCode(entryPath.getPath(), startRevNum, endRevNum); // 解析差异代码,获取对应的类和方法 } } } ``` 其中,getDiffCode方法用于获取指定文件或文件夹在两个版本之间的差异代码。具体实现可以使用SVNKit库中的SVNDiffClient类的doDiff方法。 ```java private String getDiffCode(String path, long startRevNum, long endRevNum) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); SVNURL url = SVNURL.parseURIEncoded(svnUrl + "/" + path); SVNRevision startRevision = SVNRevision.create(startRevNum); SVNRevision endRevision = SVNRevision.create(endRevNum); SVNDiffClient diffClient = cm.getDiffClient(); diffClient.doDiff(url, startRevision, url, endRevision, SVNDepth.INFINITY, true, outputStream); return outputStream.toString(); } ``` 最后,解析差异代码,获取对应的类和方法。可以使用Java代码解析库如javaparser或ANTLR等来实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值