Jmeter--thrift接口压测

1. 安装thrift

2. 新建maven工程,代码结构如下

Jmeter--thrift接口压测_第1张图片

3. pom设置,按配置存放thrift文件和打包描述文件(具体代码见附件,根据需要改变配置信息)

Jmeter--thrift接口压测_第2张图片

 Jmeter--thrift接口压测_第3张图片

4. thrift需要手动添加namespace

Jmeter--thrift接口压测_第4张图片

5. mvn clean install -Dmaven.test.skip=true生成java文件

6.新建类继承AbstractJavaSamplerClient

7. 按需求重写getDefaultParameters, setupTest, runTest, teardownTest

8. 改变settings.xml的地址,如下图所示(快捷键:command + ,)(具体代码见附件,根据需要改变文件中的配置信息)

Jmeter--thrift接口压测_第5张图片

8. 使用Junit调试

9. mvn clean install重新打jar包

10. ${JMETER_HOME}/lib/ext/x.jar存放位置

11. JMeter调试

 

ps:附件pom.xml

xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>clair.testergroupId>
    <artifactId>clair.thriftartifactId>
    <version>1.0version>
    <dependencies>

        <dependency>
            <groupId>org.apache.jmetergroupId>
            <artifactId>ApacheJMeter_coreartifactId>
            <version>2.13version>
        dependency>

        <dependency>
            <groupId>org.apache.jmetergroupId>
            <artifactId>ApacheJMeter_javaartifactId>
            <version>2.13version>
        dependency>

        <dependency>
            <groupId>org.apache.thrift.toolsgroupId>
            <artifactId>maven-thrift-pluginartifactId>
            <version>0.1.11version>
        dependency>

        <dependency>
            <groupId>org.apache.thriftgroupId>
            <artifactId>libthriftartifactId>
            <version>0.9.2version>
        dependency>

        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>4.12version>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
            <plugin>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <finalName>${project.artifactId}finalName>
                    <descriptors>
                        <descriptor>src/assembly/package.xmldescriptor>
                    descriptors>
                    <appendAssemblyId>falseappendAssemblyId>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        
                        <phase>packagephase>
                        
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>

            <plugin>
                <groupId>org.apache.thrift.toolsgroupId>
                <artifactId>maven-thrift-pluginartifactId>
                <version>0.1.11version>
                <configuration>
                    <thriftExecutable>/usr/local/bin/thriftthriftExecutable>
                    <thriftSourceRoot>src/main/resourcesthriftSourceRoot>
                    <generator>javagenerator>
                configuration>
                <executions>
                    <execution>
                        <id>thrift-sourcesid>
                        <phase>generate-sourcesphase>
                        <goals>
                            <goal>compilegoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>
project>

 

 ps: 附件settings.xml

xml version="1.0" encoding="UTF-8"?>




<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  

  

  

  
  <pluginGroups>
    
  pluginGroups>

  
  <proxies>
    
  proxies>

  
  <servers>

    <server>
        <id>archjavaid>
        <username>archjavausername>
        <password>archjava123password>
    server>

    <server>
      <id>eleme-pubid>
      <configuration>
        <wagonProvider>httpclientwagonProvider>
        <httpConfiguration>
          <all>
            <connectionTimeout>600000connectionTimeout>
            <readTimeout>600000readTimeout>
            <usePreemptive>trueusePreemptive>
          all>
        httpConfiguration>
      configuration>
    server>

    

    
  servers>

  
  <mirrors>
    

   <mirror>
      <id>eleme-pubid>
      <name>eleme-pubname>
      <url>http://maven.dev.xxx.me/nexus/content/groups/public/url>
      <mirrorOf>*mirrorOf>
    mirror>


  mirrors>


  
  <profiles>
    

    <profile>
     <id>ele-repo-profileid>
     <repositories>
      <repository>
       <id>snapshot-repoid>
       <url>http://maven.dev.elenet.me/nexus/content/groups/snapshots/url>
       <releases>
        <enabled>falseenabled>
       releases>
       <snapshots>
        <enabled>trueenabled>
        <updatePolicy>alwaysupdatePolicy>
       snapshots>
      repository>
     repositories>
     <pluginRepositories>
       <pluginRepository>
         <id>plugin-repoid>
         <name>plugin-reponame>
         <url>http://maven.dev.elenet.me/nexus/content/groups/public/url>
         <releases>
           <enabled>trueenabled>
           <updatePolicy>alwaysupdatePolicy>
         releases>
         <snapshots>
           <enabled>falseenabled>
         snapshots>
       pluginRepository>
     pluginRepositories>
    profile>

    
  profiles>

  

  <activeProfiles>
    <activeProfile>xxxxxactiveProfile>
  activeProfiles>

settings>

 

转载于:https://www.cnblogs.com/sunshine2016/p/5949395.html

你可能感兴趣的:(Jmeter--thrift接口压测)