feat(接口测试): TCPSampler 增加环境配置和场景配置

This commit is contained in:
q4speed 2020-10-12 17:23:18 +08:00
parent 43c05ee5fd
commit f2bf1e0d21
9 changed files with 114 additions and 79 deletions

View File

@ -49,9 +49,9 @@
<div class="dubbo-config-title">Consumer & Service</div> <div class="dubbo-config-title">Consumer & Service</div>
<ms-dubbo-consumer-service :consumer="scenario.dubboConfig.consumerAndService" :is-read-only="isReadOnly"/> <ms-dubbo-consumer-service :consumer="scenario.dubboConfig.consumerAndService" :is-read-only="isReadOnly"/>
</el-tab-pane> </el-tab-pane>
<!-- <el-tab-pane :label="$t('api_test.environment.tcp_config')" name="tcp">--> <el-tab-pane :label="$t('api_test.environment.tcp_config')" name="tcp">
<!-- <ms-tcp-config :config="scenario.tcpConfig" :is-read-only="isReadOnly"/>--> <ms-tcp-config :config="scenario.tcpConfig" :is-read-only="isReadOnly"/>
<!-- </el-tab-pane>--> </el-tab-pane>
</el-tabs> </el-tabs>
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/> <api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>

View File

@ -20,6 +20,9 @@
<el-tab-pane :label="$t('api_test.environment.database_config')" name="sql"> <el-tab-pane :label="$t('api_test.environment.database_config')" name="sql">
<ms-database-config :configs="environment.config.databaseConfigs"/> <ms-database-config :configs="environment.config.databaseConfigs"/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('api_test.environment.tcp_config')" name="tcp">
<ms-tcp-config :config="environment.config.tcpConfig"/>
</el-tab-pane>
</el-tabs> </el-tabs>
<div class="environment-footer"> <div class="environment-footer">
@ -35,16 +38,18 @@
import MsApiScenarioVariables from "../ApiScenarioVariables"; import MsApiScenarioVariables from "../ApiScenarioVariables";
import MsApiKeyValue from "../ApiKeyValue"; import MsApiKeyValue from "../ApiKeyValue";
import MsDialogFooter from "../../../../common/components/MsDialogFooter"; import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import {REQUEST_HEADERS} from "../../../../../../common/js/constants"; import {REQUEST_HEADERS} from "@/common/js/constants";
import {Environment} from "../../model/EnvironmentModel"; import {Environment} from "../../model/EnvironmentModel";
import MsApiHostTable from "../ApiHostTable"; import MsApiHostTable from "../ApiHostTable";
import MsDatabaseConfig from "../request/database/DatabaseConfig"; import MsDatabaseConfig from "../request/database/DatabaseConfig";
import MsEnvironmentHttpConfig from "./EnvironmentHttpConfig"; import MsEnvironmentHttpConfig from "./EnvironmentHttpConfig";
import MsEnvironmentCommonConfig from "./EnvironmentCommonConfig"; import MsEnvironmentCommonConfig from "./EnvironmentCommonConfig";
import MsTcpConfig from "@/business/components/api/test/components/request/tcp/TcpConfig";
export default { export default {
name: "EnvironmentEdit", name: "EnvironmentEdit",
components: { components: {
MsTcpConfig,
MsEnvironmentCommonConfig, MsEnvironmentCommonConfig,
MsEnvironmentHttpConfig, MsEnvironmentHttpConfig,
MsDatabaseConfig, MsApiHostTable, MsDialogFooter, MsApiKeyValue, MsApiScenarioVariables}, MsDatabaseConfig, MsApiHostTable, MsDialogFooter, MsApiKeyValue, MsApiScenarioVariables},

View File

@ -11,31 +11,44 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-row type="flex" justify="space-between"> <el-row :gutter="10">
<el-col :lg="8"> <el-col :span="16">
<el-form-item :label="$t('api_test.request.tcp.server')" prop="server"> <el-form-item :label="$t('api_test.request.tcp.server')" prop="server">
<el-input v-model="request.server" maxlength="300" show-word-limit/> <el-input v-model="request.server" maxlength="300" show-word-limit/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :lg="6"> <el-col :span="8">
<el-form-item :label="$t('api_test.request.tcp.port')" prop="port" label-width="60px"> <el-form-item :label="$t('api_test.request.tcp.port')" prop="port" label-width="60px">
<el-input-number v-model="request.port" controls-position="right" :min="0" :max="65535"/> <el-input-number v-model="request.port" controls-position="right" :min="0" :max="65535"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :lg="6"> </el-row>
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout" label-width="80px">
<el-row :gutter="10">
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout">
<el-input-number v-model="request.ctimeout" controls-position="right" :min="0"/> <el-input-number v-model="request.ctimeout" controls-position="right" :min="0"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :lg="6"> <el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout" label-width="80px"> <el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout">
<el-input-number v-model="request.timeout" controls-position="right" :min="0"/> <el-input-number v-model="request.timeout" controls-position="right" :min="0"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
<el-input v-model="request.soLinger"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
<el-input v-model="request.eolByte"/>
</el-form-item>
</el-col>
</el-row> </el-row>
<el-row type="flex" justify="space-between"> <el-row :gutter="10">
<el-col> <el-col :span="6">
<el-form-item> <el-form-item>
<el-switch <el-switch
v-model="request.useEnvironment" v-model="request.useEnvironment"
@ -44,40 +57,30 @@
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col> <el-col :span="6">
<el-form-item label-width="0"> <el-form-item>
<el-switch <el-switch
v-model="request.reUseConnection" v-model="request.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')"> :active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col> <el-col :span="6">
<el-form-item label-width="0"> <el-form-item>
<el-switch <el-switch
v-model="request.closeConnection" v-model="request.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')"> :active-text="$t('api_test.request.tcp.close_connection')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col> <el-col :span="6">
<el-form-item label-width="0"> <el-form-item>
<el-switch <el-switch
v-model="request.nodelay" v-model="request.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')"> :active-text="$t('api_test.request.tcp.no_delay')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col>
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
<el-input v-model="request.soLinger"/>
</el-form-item>
</el-col>
<el-col>
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
<el-input v-model="request.eolByte"/>
</el-form-item>
</el-col>
</el-row> </el-row>
<el-form-item :label="$t('api_test.request.tcp.request')" prop="request"> <el-form-item :label="$t('api_test.request.tcp.request')" prop="request">

View File

@ -1,5 +1,6 @@
<template> <template>
<el-form class="tcp" :model="config" :rules="rules" ref="request" label-width="auto" :disabled="isReadOnly"> <el-form class="tcp" :model="config" :rules="rules" ref="config" label-width="120px" :disabled="isReadOnly"
size="small">
<el-form-item label="TCPClient" prop="classname"> <el-form-item label="TCPClient" prop="classname">
<el-select v-model="config.classname" style="width: 100%"> <el-select v-model="config.classname" style="width: 100%">
@ -7,64 +8,67 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-row type="flex" justify="space-between"> <el-row :gutter="10">
<el-col :lg="8"> <el-col :span="16">
<el-form-item :label="$t('api_test.request.tcp.server')" prop="server"> <el-form-item :label="$t('api_test.request.tcp.server')" prop="server">
<el-input v-model="config.server" maxlength="300" show-word-limit/> <el-input v-model="config.server" maxlength="300" show-word-limit/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :lg="6"> <el-col :span="8">
<el-form-item :label="$t('api_test.request.tcp.port')" prop="port" label-width="60px"> <el-form-item :label="$t('api_test.request.tcp.port')" prop="port" label-width="60px">
<el-input-number v-model="config.port" controls-position="right" :min="0" :max="65535"/> <el-input-number v-model="config.port" controls-position="right" :min="0" :max="65535" :controls="false"/>
</el-form-item>
</el-col>
<el-col :lg="6">
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout" label-width="80px">
<el-input-number v-model="config.ctimeout" controls-position="right" :min="0"/>
</el-form-item>
</el-col>
<el-col :lg="6">
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout" label-width="80px">
<el-input-number v-model="config.timeout" controls-position="right" :min="0"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row type="flex" justify="space-between"> <el-row :gutter="10">
<el-col> <el-col :span="6">
<el-form-item label-width="0"> <el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout">
<el-input-number v-model="config.ctimeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout">
<el-input-number v-model="config.timeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
<el-input v-model="config.soLinger"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
<el-input v-model="config.eolByte"/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="8">
<el-form-item>
<el-switch <el-switch
v-model="config.reUseConnection" v-model="config.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')"> :active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col> <el-col :span="8">
<el-form-item label-width="0"> <el-form-item>
<el-switch <el-switch
v-model="config.closeConnection" v-model="config.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')"> :active-text="$t('api_test.request.tcp.close_connection')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col> <el-col :span="8">
<el-form-item label-width="0"> <el-form-item>
<el-switch <el-switch
v-model="config.nodelay" v-model="config.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')"> :active-text="$t('api_test.request.tcp.no_delay')">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col>
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
<el-input v-model="config.soLinger"/>
</el-form-item>
</el-col>
<el-col>
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
<el-input v-model="config.eolByte"/>
</el-form-item>
</el-col>
</el-row> </el-row>
<el-row :gutter="10"> <el-row :gutter="10">
@ -90,16 +94,15 @@ export default {
name: "MsTcpConfig", name: "MsTcpConfig",
props: { props: {
config: TCPConfig, config: TCPConfig,
rules: { isReadOnly: {
type: Object, type: Boolean,
default: () => { default: false
return {} },
}
}
}, },
data() { data() {
return { return {
classes: TCPConfig.CLASSES, classes: TCPConfig.CLASSES,
rules: {}
} }
}, },
} }

View File

@ -1,4 +1,5 @@
import {BaseConfig, DatabaseConfig, KeyValue} from "./ScenarioModel"; import {BaseConfig, DatabaseConfig, KeyValue} from "./ScenarioModel";
import {TCPConfig} from "@/business/components/api/test/model/ScenarioModel";
export class Environment extends BaseConfig { export class Environment extends BaseConfig {
constructor(options = {}) { constructor(options = {}) {
@ -26,14 +27,17 @@ export class Config extends BaseConfig {
this.commonConfig = undefined; this.commonConfig = undefined;
this.httpConfig = undefined; this.httpConfig = undefined;
this.databaseConfigs = []; this.databaseConfigs = [];
this.tcpConfig = undefined;
this.set(options); this.set(options);
this.sets({databaseConfigs: DatabaseConfig}, options); this.sets({databaseConfigs: DatabaseConfig}, options);
} }
initOptions(options = {}) { initOptions(options = {}) {
this.commonConfig = new CommonConfig(options.commonConfig); this.commonConfig = new CommonConfig(options.commonConfig);
this.httpConfig = new HttpConfig(options.httpConfig); this.httpConfig = new HttpConfig(options.httpConfig);
options.databaseConfigs = options.databaseConfigs || []; options.databaseConfigs = options.databaseConfigs || [];
options.tcpConfig = new TCPConfig(options.tcpConfig);
return options; return options;
} }
} }
@ -91,7 +95,6 @@ export class Host extends BaseConfig {
} }
/* ---------- Functions ------- */ /* ---------- Functions ------- */
export function compatibleWithEnvironment(environment) { export function compatibleWithEnvironment(environment) {

View File

@ -111,12 +111,16 @@ export const EXTRACT_TYPE = {
export class BaseConfig { export class BaseConfig {
set(options) { set(options, notUndefined) {
options = this.initOptions(options) options = this.initOptions(options)
for (let name in options) { for (let name in options) {
if (options.hasOwnProperty(name)) { if (options.hasOwnProperty(name)) {
if (!(this[name] instanceof Array)) { if (!(this[name] instanceof Array)) {
this[name] = options[name]; if (notUndefined === true) {
this[name] = options[name] === undefined ? this[name] : options[name];
} else {
this[name] = options[name];
}
} }
} }
} }
@ -219,6 +223,7 @@ export class Scenario extends BaseConfig {
this.enableCookieShare = false; this.enableCookieShare = false;
this.enable = true; this.enable = true;
this.databaseConfigs = []; this.databaseConfigs = [];
this.tcpConfig = undefined;
this.set(options); this.set(options);
this.sets({ this.sets({
@ -234,6 +239,7 @@ export class Scenario extends BaseConfig {
options.requests = options.requests || [new RequestFactory()]; options.requests = options.requests || [new RequestFactory()];
options.databaseConfigs = options.databaseConfigs || []; options.databaseConfigs = options.databaseConfigs || [];
options.dubboConfig = new DubboConfig(options.dubboConfig); options.dubboConfig = new DubboConfig(options.dubboConfig);
options.tcpConfig = new TCPConfig(options.tcpConfig);
return options; return options;
} }
@ -512,11 +518,11 @@ export class SqlRequest extends Request {
} }
} }
export class TCPConfig extends Request { export class TCPConfig extends BaseConfig {
static CLASSES = ["TCPClientImpl", "BinaryTCPClientImpl", "LengthPrefixedBinaryTCPClientImpl"] static CLASSES = ["TCPClientImpl", "BinaryTCPClientImpl", "LengthPrefixedBinaryTCPClientImpl"]
constructor(options = {}) { constructor(options = {}) {
super(RequestFactory.TYPES.TCP, options); super();
this.classname = options.classname || TCPConfig.CLASSES[0]; this.classname = options.classname || TCPConfig.CLASSES[0];
this.server = options.server; this.server = options.server;
this.port = options.port; this.port = options.port;
@ -532,18 +538,17 @@ export class TCPConfig extends Request {
this.username = options.username; this.username = options.username;
this.password = options.password; this.password = options.password;
} }
isValid() {
return !!this.classname || !!this.server;
}
} }
export class TCPRequest extends TCPConfig { export class TCPRequest extends Request {
constructor(options = {}) { constructor(options = {}) {
super(options); super(RequestFactory.TYPES.TCP, options);
this.useEnvironment = options.useEnvironment; this.useEnvironment = options.useEnvironment;
this.debugReport = undefined; this.debugReport = undefined;
//设置TCPConfig的属性
this.set(new TCPConfig(options));
this.request = options.request; this.request = options.request;
} }
@ -1040,6 +1045,19 @@ class JMXDubboRequest {
} }
} }
class JMXTCPRequest {
constructor(request, scenario) {
let obj = request.clone();
if (request.useEnvironment) {
obj.set(scenario.environment.config.tcpConfig, true);
return obj;
}
obj.set(scenario.tcpConfig, true);
return obj;
}
}
class JMeterTestPlan extends Element { class JMeterTestPlan extends Element {
constructor() { constructor() {
super('jmeterTestPlan', { super('jmeterTestPlan', {
@ -1098,7 +1116,7 @@ class JMXGenerator {
request.dataSource = scenario.databaseConfigMap.get(request.dataSource); request.dataSource = scenario.databaseConfigMap.get(request.dataSource);
sampler = new JDBCSampler(request.name || "", request); sampler = new JDBCSampler(request.name || "", request);
} else if (request instanceof TCPRequest) { } else if (request instanceof TCPRequest) {
sampler = new TCPSampler(request.name || "", request); sampler = new TCPSampler(request.name || "", new JMXTCPRequest(request, scenario));
} }
this.addDNSCacheManager(sampler, scenario.environment, request.useEnvironment); this.addDNSCacheManager(sampler, scenario.environment, request.useEnvironment);

View File

@ -436,6 +436,7 @@ export default {
common_config: "Common Config", common_config: "Common Config",
http_config: "HTTP Config", http_config: "HTTP Config",
database_config: "Database Config", database_config: "Database Config",
tcp_config: "TCP Config",
}, },
scenario: { scenario: {
scenario: "Scenario", scenario: "Scenario",

View File

@ -437,6 +437,7 @@ export default {
common_config: "通用配置", common_config: "通用配置",
http_config: "HTTP配置", http_config: "HTTP配置",
database_config: "数据库配置", database_config: "数据库配置",
tcp_config: "TCP配置",
}, },
scenario: { scenario: {
scenario: "场景", scenario: "场景",

View File

@ -437,6 +437,7 @@ export default {
common_config: "通用配置", common_config: "通用配置",
http_config: "HTTP配置", http_config: "HTTP配置",
database_config: "數據庫配置", database_config: "數據庫配置",
tcp_config: "TCP配置",
}, },
scenario: { scenario: {
scenario: "場景", scenario: "場景",