This commit is contained in:
shiziyuan9527 2020-10-12 17:37:42 +08:00
commit a4ee354778
9 changed files with 206 additions and 45 deletions

View File

@ -49,6 +49,9 @@
<div class="dubbo-config-title">Consumer & Service</div>
<ms-dubbo-consumer-service :consumer="scenario.dubboConfig.consumerAndService" :is-read-only="isReadOnly"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.environment.tcp_config')" name="tcp">
<ms-tcp-config :config="scenario.tcpConfig" :is-read-only="isReadOnly"/>
</el-tab-pane>
</el-tabs>
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
@ -68,10 +71,12 @@ import MsDubboConfigCenter from "@/business/components/api/test/components/reque
import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService";
import MsDatabaseConfig from "./request/database/DatabaseConfig";
import {parseEnvironment} from "../model/EnvironmentModel";
import MsTcpConfig from "@/business/components/api/test/components/request/tcp/TcpConfig";
export default {
name: "MsApiScenarioForm",
components: {
MsTcpConfig,
MsDatabaseConfig,
MsDubboConsumerService,
MsDubboConfigCenter, MsDubboRegistryCenter, ApiEnvironmentConfig, MsApiScenarioVariables, MsApiKeyValue

View File

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

View File

@ -1,5 +1,5 @@
<template>
<el-form class="tcp" :model="request" :rules="rules" ref="request" label-width="120px" :disabled="isReadOnly">
<el-form class="tcp" :model="request" :rules="rules" ref="request" label-width="auto" :disabled="isReadOnly">
<el-form-item :label="$t('api_test.request.name')" prop="name">
<el-input v-model="request.name" maxlength="300" show-word-limit/>
@ -12,30 +12,43 @@
</el-form-item>
<el-row :gutter="10">
<el-col :span="12">
<el-col :span="16">
<el-form-item :label="$t('api_test.request.tcp.server')" prop="server">
<el-input v-model="request.server" maxlength="300" show-word-limit/>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item :label="$t('api_test.request.tcp.port')" prop="port">
<el-col :span="8">
<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-form-item>
</el-col>
<el-col :span="4">
<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-form-item>
</el-col>
<el-col :span="4">
<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-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="4">
<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-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="request.timeout" controls-position="right" :min="0"/>
</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="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 :gutter="10">
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.useEnvironment"
@ -44,40 +57,30 @@
</el-switch>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item label-width="0">
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item label-width="0">
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item label-width="0">
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="4">
<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="4">
<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-form-item :label="$t('api_test.request.tcp.request')" prop="request">

View File

@ -0,0 +1,115 @@
<template>
<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-select v-model="config.classname" style="width: 100%">
<el-option v-for="c in classes" :key="c" :label="c" :value="c"/>
</el-select>
</el-form-item>
<el-row :gutter="10">
<el-col :span="16">
<el-form-item :label="$t('api_test.request.tcp.server')" prop="server">
<el-input v-model="config.server" maxlength="300" show-word-limit/>
</el-form-item>
</el-col>
<el-col :span="8">
<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" :controls="false"/>
</el-form-item>
</el-col>
</el-row>
<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="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
v-model="config.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item>
<el-switch
v-model="config.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item>
<el-switch
v-model="config.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')">
</el-switch>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.username')" prop="username">
<el-input v-model="config.username" maxlength="100" show-word-limit/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.password')" prop="password">
<el-input v-model="config.password" maxlength="30" show-word-limit show-password
autocomplete="new-password"/>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
<script>
import {TCPConfig} from "@/business/components/api/test/model/ScenarioModel";
export default {
name: "MsTcpConfig",
props: {
config: TCPConfig,
isReadOnly: {
type: Boolean,
default: false
},
},
data() {
return {
classes: TCPConfig.CLASSES,
rules: {}
}
},
}
</script>
<style scoped>
.tcp >>> .el-input-number {
width: 100%;
}
</style>

View File

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

View File

@ -111,12 +111,16 @@ export const EXTRACT_TYPE = {
export class BaseConfig {
set(options) {
set(options, notUndefined) {
options = this.initOptions(options)
for (let name in options) {
if (options.hasOwnProperty(name)) {
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.enable = true;
this.databaseConfigs = [];
this.tcpConfig = undefined;
this.set(options);
this.sets({
@ -234,6 +239,7 @@ export class Scenario extends BaseConfig {
options.requests = options.requests || [new RequestFactory()];
options.databaseConfigs = options.databaseConfigs || [];
options.dubboConfig = new DubboConfig(options.dubboConfig);
options.tcpConfig = new TCPConfig(options.tcpConfig);
return options;
}
@ -512,15 +518,12 @@ export class SqlRequest extends Request {
}
}
export class TCPRequest extends Request {
export class TCPConfig extends BaseConfig {
static CLASSES = ["TCPClientImpl", "BinaryTCPClientImpl", "LengthPrefixedBinaryTCPClientImpl"]
constructor(options = {}) {
super(RequestFactory.TYPES.TCP, options);
this.useEnvironment = options.useEnvironment;
this.debugReport = undefined;
this.classname = options.classname || TCPRequest.CLASSES[0];
super();
this.classname = options.classname || TCPConfig.CLASSES[0];
this.server = options.server;
this.port = options.port;
this.ctimeout = options.ctimeout; // Connect
@ -532,11 +535,22 @@ export class TCPRequest extends Request {
this.soLinger = options.soLinger;
this.eolByte = options.eolByte;
this.request = options.request;
this.username = options.username;
this.password = options.password;
}
}
export class TCPRequest extends Request {
constructor(options = {}) {
super(RequestFactory.TYPES.TCP, options);
this.useEnvironment = options.useEnvironment;
this.debugReport = undefined;
//设置TCPConfig的属性
this.set(new TCPConfig(options));
this.request = options.request;
}
isValid() {
if (this.enable) {
@ -1031,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 {
constructor() {
super('jmeterTestPlan', {
@ -1089,7 +1116,7 @@ class JMXGenerator {
request.dataSource = scenario.databaseConfigMap.get(request.dataSource);
sampler = new JDBCSampler(request.name || "", request);
} 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);
@ -1165,7 +1192,7 @@ class JMXGenerator {
let domain = environment.config.httpConfig.domain;
let validHosts = [];
hosts.forEach(item => {
if (item.domain != undefined && domain != undefined) {
if (item.domain !== undefined && domain !== undefined) {
let d = item.domain.trim().replace("http://", "").replace("https://", "");
if (d === domain.trim()) {
item.domain = d; // 域名去掉协议

View File

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

View File

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

View File

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