fix(接口测试): 修复空指针bug

This commit is contained in:
q4speed 2020-11-12 10:21:42 +08:00
parent fecc4c4a7e
commit 759e6e7f0d
5 changed files with 77 additions and 54 deletions

View File

@ -4,16 +4,16 @@ import lombok.Data;
@Data @Data
public class TCPConfig { public class TCPConfig {
private String classname; private String classname = "";
private String server; private String server = "";
private String port; private String port = "";
private String ctimeout; private String ctimeout = "";
private String timeout; private String timeout = "";
private boolean reUseConnection; private boolean reUseConnection = true;
private boolean nodelay; private boolean nodelay;
private boolean closeConnection; private boolean closeConnection;
private String soLinger; private String soLinger = "";
private String eolByte; private String eolByte = "";
private String username; private String username = "";
private String password; private String password = "";
} }

View File

@ -12,15 +12,15 @@ public class TCPRequest extends Request {
// type 必须放最前面以便能够转换正确的类 // type 必须放最前面以便能够转换正确的类
private String type = RequestType.TCP; private String type = RequestType.TCP;
@JSONField(ordinal = 51) @JSONField(ordinal = 51)
private String classname; private String classname = "";
@JSONField(ordinal = 52) @JSONField(ordinal = 52)
private String server; private String server = "";
@JSONField(ordinal = 53) @JSONField(ordinal = 53)
private String port; private String port = "";
@JSONField(ordinal = 54) @JSONField(ordinal = 54)
private String ctimeout; private String ctimeout = "";
@JSONField(ordinal = 55) @JSONField(ordinal = 55)
private String timeout; private String timeout = "";
@JSONField(ordinal = 56) @JSONField(ordinal = 56)
private boolean reUseConnection; private boolean reUseConnection;
@JSONField(ordinal = 57) @JSONField(ordinal = 57)
@ -28,13 +28,13 @@ public class TCPRequest extends Request {
@JSONField(ordinal = 58) @JSONField(ordinal = 58)
private boolean closeConnection; private boolean closeConnection;
@JSONField(ordinal = 59) @JSONField(ordinal = 59)
private String soLinger; private String soLinger = "";
@JSONField(ordinal = 60) @JSONField(ordinal = 60)
private String eolByte; private String eolByte = "";
@JSONField(ordinal = 61) @JSONField(ordinal = 61)
private String request; private String request = "";
@JSONField(ordinal = 62) @JSONField(ordinal = 62)
private String username; private String username = "";
@JSONField(ordinal = 63) @JSONField(ordinal = 63)
private String password; private String password = "";
} }

View File

@ -10,6 +10,9 @@ import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.dto.scenario.environment.Host; import io.metersphere.api.dto.scenario.environment.Host;
import io.metersphere.api.dto.scenario.extract.*; import io.metersphere.api.dto.scenario.extract.*;
import io.metersphere.api.dto.scenario.request.*; import io.metersphere.api.dto.scenario.request.*;
import io.metersphere.api.dto.scenario.request.dubbo.ConfigCenter;
import io.metersphere.api.dto.scenario.request.dubbo.ConsumerAndService;
import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter;
import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -90,6 +93,8 @@ public class JMXGenerator {
databaseConfigMap.put(databaseConfig.getId(), databaseConfig.getName()); databaseConfigMap.put(databaseConfig.getId(), databaseConfig.getName());
}); });
} }
// DUBBO Config
threadGroupHashTree.add(dubboConfig(scenario.getName() + "DUBBO Config", scenario.getDubboConfig()));
// 场景TCP Config // 场景TCP Config
threadGroupHashTree.add(tcpConfig(scenario.getName() + "TCP Config", scenario.getTcpConfig())); threadGroupHashTree.add(tcpConfig(scenario.getName() + "TCP Config", scenario.getTcpConfig()));
@ -356,6 +361,53 @@ public class JMXGenerator {
return dataSourceElement; return dataSourceElement;
} }
private ConfigTestElement dubboConfig(String name, DubboConfig dubboConfig) {
ConfigTestElement configTestElement = new ConfigTestElement();
configTestElement.setEnabled(true);
configTestElement.setName(name);
configTestElement.setProperty(TestElement.TEST_CLASS, ConfigTestElement.class.getName());
configTestElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboDefaultConfigGui"));
configTestElement.addConfigElement(configCenter(dubboConfig.getConfigCenter()));
configTestElement.addConfigElement(registryCenter(dubboConfig.getRegistryCenter()));
configTestElement.addConfigElement(consumerAndService(dubboConfig.getConsumerAndService()));
return configTestElement;
}
private ConfigTestElement configCenter(ConfigCenter configCenter) {
ConfigTestElement configTestElement = new ConfigTestElement();
Constants.setConfigCenterProtocol(configCenter.getProtocol(), configTestElement);
Constants.setConfigCenterGroup(configCenter.getGroup(), configTestElement);
Constants.setConfigCenterNamespace(configCenter.getNamespace(), configTestElement);
Constants.setConfigCenterUserName(configCenter.getUsername(), configTestElement);
Constants.setConfigCenterPassword(configCenter.getPassword(), configTestElement);
Constants.setConfigCenterAddress(configCenter.getAddress(), configTestElement);
Constants.setConfigCenterTimeout(configCenter.getTimeout(), configTestElement);
return configTestElement;
}
private ConfigTestElement registryCenter(RegistryCenter registryCenter) {
ConfigTestElement configTestElement = new ConfigTestElement();
Constants.setRegistryProtocol(registryCenter.getProtocol(), configTestElement);
Constants.setRegistryGroup(registryCenter.getGroup(), configTestElement);
Constants.setRegistryUserName(registryCenter.getUsername(), configTestElement);
Constants.setRegistryPassword(registryCenter.getPassword(), configTestElement);
Constants.setRegistryTimeout(registryCenter.getTimeout(), configTestElement);
Constants.setAddress(registryCenter.getAddress(), configTestElement);
return configTestElement;
}
private ConfigTestElement consumerAndService(ConsumerAndService consumerAndService) {
ConfigTestElement configTestElement = new ConfigTestElement();
Constants.setTimeout(consumerAndService.getTimeout(), configTestElement);
Constants.setVersion(consumerAndService.getVersion(), configTestElement);
Constants.setGroup(consumerAndService.getGroup(), configTestElement);
Constants.setConnections(consumerAndService.getConnections(), configTestElement);
Constants.setLoadbalance(consumerAndService.getLoadBalance(), configTestElement);
Constants.setAsync(consumerAndService.getAsync(), configTestElement);
Constants.setCluster(consumerAndService.getCluster(), configTestElement);
return configTestElement;
}
private ConfigTestElement tcpConfig(String name, TCPConfig tcpConfig) { private ConfigTestElement tcpConfig(String name, TCPConfig tcpConfig) {
ConfigTestElement configTestElement = new ConfigTestElement(); ConfigTestElement configTestElement = new ConfigTestElement();
configTestElement.setEnabled(true); configTestElement.setEnabled(true);
@ -537,28 +589,9 @@ public class JMXGenerator {
sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName()); sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui")); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
Constants.setConfigCenterProtocol(request.getConfigCenter().getProtocol(), sampler); sampler.addTestElement(configCenter(request.getConfigCenter()));
Constants.setConfigCenterGroup(request.getConfigCenter().getGroup(), sampler); sampler.addTestElement(registryCenter(request.getRegistryCenter()));
Constants.setConfigCenterNamespace(request.getConfigCenter().getNamespace(), sampler); sampler.addTestElement(consumerAndService(request.getConsumerAndService()));
Constants.setConfigCenterUserName(request.getConfigCenter().getUsername(), sampler);
Constants.setConfigCenterPassword(request.getConfigCenter().getPassword(), sampler);
Constants.setConfigCenterAddress(request.getConfigCenter().getAddress(), sampler);
Constants.setConfigCenterTimeout(request.getConfigCenter().getTimeout(), sampler);
Constants.setRegistryProtocol(request.getRegistryCenter().getProtocol(), sampler);
Constants.setRegistryGroup(request.getRegistryCenter().getGroup(), sampler);
Constants.setRegistryUserName(request.getRegistryCenter().getUsername(), sampler);
Constants.setRegistryPassword(request.getRegistryCenter().getPassword(), sampler);
Constants.setRegistryTimeout(request.getRegistryCenter().getTimeout(), sampler);
Constants.setAddress(request.getRegistryCenter().getAddress(), sampler);
Constants.setTimeout(request.getConsumerAndService().getTimeout(), sampler);
Constants.setVersion(request.getConsumerAndService().getVersion(), sampler);
Constants.setGroup(request.getConsumerAndService().getGroup(), sampler);
Constants.setConnections(request.getConsumerAndService().getConnections(), sampler);
Constants.setLoadbalance(request.getConsumerAndService().getLoadBalance(), sampler);
Constants.setAsync(request.getConsumerAndService().getAsync(), sampler);
Constants.setCluster(request.getConsumerAndService().getCluster(), sampler);
Constants.setRpcProtocol(request.getProtocol(), sampler); Constants.setRpcProtocol(request.getProtocol(), sampler);
Constants.setInterfaceName(request.get_interface(), sampler); Constants.setInterfaceName(request.get_interface(), sampler);

View File

@ -46,6 +46,7 @@ public class JMeterService {
public void run(String testId, String testName, List<Scenario> scenarios, String debugReportId) { public void run(String testId, String testName, List<Scenario> scenarios, String debugReportId) {
try { try {
init();
HashTree testPlan = getHashTree(testId, testName, scenarios); HashTree testPlan = getHashTree(testId, testName, scenarios);
JMeterVars.addJSR223PostProcessor(testPlan); JMeterVars.addJSR223PostProcessor(testPlan);
addBackendListener(testId, debugReportId, testPlan); addBackendListener(testId, debugReportId, testPlan);

View File

@ -1,7 +1,6 @@
#--------------------------------------------------------- #---------------------------------------------------------
# SAVESERVICE PROPERTIES - JMETER INTERNAL USE ONLY # SAVESERVICE PROPERTIES - JMETER INTERNAL USE ONLY
#--------------------------------------------------------- #---------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more ## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with ## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership. ## this work for additional information regarding copyright ownership.
@ -16,16 +15,11 @@
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and ## See the License for the specific language governing permissions and
## limitations under the License. ## limitations under the License.
# This file is used to define how XStream (de-)serializes classnames # This file is used to define how XStream (de-)serializes classnames
# in JMX test plan files. # in JMX test plan files.
# FOR JMETER INTERNAL USE ONLY # FOR JMETER INTERNAL USE ONLY
#--------------------------------------------------------- #---------------------------------------------------------
# N.B. To ensure backward compatibility, please do NOT change or delete any entries # N.B. To ensure backward compatibility, please do NOT change or delete any entries
# New entries can be added as necessary. # New entries can be added as necessary.
# #
# Note that keys starting with an underscore are special, # Note that keys starting with an underscore are special,
@ -134,6 +128,7 @@ DNSCacheManager=org.apache.jmeter.protocol.http.control.DNSCacheManager
DNSCachePanel=org.apache.jmeter.protocol.http.gui.DNSCachePanel DNSCachePanel=org.apache.jmeter.protocol.http.gui.DNSCachePanel
DubboSample=io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample DubboSample=io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample
DubboSampleGui=io.github.ningyu.jmeter.plugin.dubbo.gui.DubboSampleGui DubboSampleGui=io.github.ningyu.jmeter.plugin.dubbo.gui.DubboSampleGui
DubboDefaultConfigGui=io.github.ningyu.jmeter.plugin.dubbo.gui.DubboDefaultConfigGui
DurationAssertion=org.apache.jmeter.assertions.DurationAssertion DurationAssertion=org.apache.jmeter.assertions.DurationAssertion
DurationAssertionGui=org.apache.jmeter.assertions.gui.DurationAssertionGui DurationAssertionGui=org.apache.jmeter.assertions.gui.DurationAssertionGui
PreciseThroughputTimer=org.apache.jmeter.timers.poissonarrivals.PreciseThroughputTimer PreciseThroughputTimer=org.apache.jmeter.timers.poissonarrivals.PreciseThroughputTimer
@ -244,10 +239,8 @@ ModuleController=org.apache.jmeter.control.ModuleController
ModuleControllerGui=org.apache.jmeter.control.gui.ModuleControllerGui ModuleControllerGui=org.apache.jmeter.control.gui.ModuleControllerGui
MongoScriptSampler=org.apache.jmeter.protocol.mongodb.sampler.MongoScriptSampler MongoScriptSampler=org.apache.jmeter.protocol.mongodb.sampler.MongoScriptSampler
MongoSourceElement=org.apache.jmeter.protocol.mongodb.config.MongoSourceElement MongoSourceElement=org.apache.jmeter.protocol.mongodb.config.MongoSourceElement
# removed in 3.2, class was deleted in r # removed in 3.2, class was deleted in r
MonitorHealthVisualizer=org.apache.jmeter.visualizers.MonitorHealthVisualizer MonitorHealthVisualizer=org.apache.jmeter.visualizers.MonitorHealthVisualizer
NamePanel=org.apache.jmeter.gui.NamePanel NamePanel=org.apache.jmeter.gui.NamePanel
BoltSampler=org.apache.jmeter.protocol.bolt.sampler.BoltSampler BoltSampler=org.apache.jmeter.protocol.bolt.sampler.BoltSampler
BoltConnectionElement=org.apache.jmeter.protocol.bolt.config.BoltConnectionElement BoltConnectionElement=org.apache.jmeter.protocol.bolt.config.BoltConnectionElement
@ -303,12 +296,10 @@ SMIMEAssertion=org.apache.jmeter.assertions.SMIMEAssertionTestElement
SMIMEAssertionGui=org.apache.jmeter.assertions.gui.SMIMEAssertionGui SMIMEAssertionGui=org.apache.jmeter.assertions.gui.SMIMEAssertionGui
SmtpSampler=org.apache.jmeter.protocol.smtp.sampler.SmtpSampler SmtpSampler=org.apache.jmeter.protocol.smtp.sampler.SmtpSampler
SmtpSamplerGui=org.apache.jmeter.protocol.smtp.sampler.gui.SmtpSamplerGui SmtpSamplerGui=org.apache.jmeter.protocol.smtp.sampler.gui.SmtpSamplerGui
# removed in 3.2, class was deleted in r # removed in 3.2, class was deleted in r
SoapSampler=org.apache.jmeter.protocol.http.sampler.SoapSampler SoapSampler=org.apache.jmeter.protocol.http.sampler.SoapSampler
# removed in 3.2, class was deleted in r # removed in 3.2, class was deleted in r
SoapSamplerGui=org.apache.jmeter.protocol.http.control.gui.SoapSamplerGui SoapSamplerGui=org.apache.jmeter.protocol.http.control.gui.SoapSamplerGui
# removed in 3.1, class was deleted in r1763837 # removed in 3.1, class was deleted in r1763837
SplineVisualizer=org.apache.jmeter.visualizers.SplineVisualizer SplineVisualizer=org.apache.jmeter.visualizers.SplineVisualizer
# Originally deleted in r397955 as class is obsolete; needed for compat. # Originally deleted in r397955 as class is obsolete; needed for compat.
@ -377,7 +368,6 @@ XPathExtractor=org.apache.jmeter.extractor.XPathExtractor
XPathExtractorGui=org.apache.jmeter.extractor.gui.XPathExtractorGui XPathExtractorGui=org.apache.jmeter.extractor.gui.XPathExtractorGui
XPath2Extractor=org.apache.jmeter.extractor.XPath2Extractor XPath2Extractor=org.apache.jmeter.extractor.XPath2Extractor
XPath2ExtractorGui=org.apache.jmeter.extractor.gui.XPath2ExtractorGui XPath2ExtractorGui=org.apache.jmeter.extractor.gui.XPath2ExtractorGui
# Properties - all start with lower case letter and end with Prop # Properties - all start with lower case letter and end with Prop
# #
boolProp=org.apache.jmeter.testelement.property.BooleanProperty boolProp=org.apache.jmeter.testelement.property.BooleanProperty
@ -402,7 +392,6 @@ httpSample=org.apache.jmeter.protocol.http.sampler.HTTPSampleResult
statSample=org.apache.jmeter.samplers.StatisticalSampleResult statSample=org.apache.jmeter.samplers.StatisticalSampleResult
testResults=org.apache.jmeter.save.TestResultWrapper testResults=org.apache.jmeter.save.TestResultWrapper
assertionResult=org.apache.jmeter.assertions.AssertionResult assertionResult=org.apache.jmeter.assertions.AssertionResult
# removed in 3.2, class was deleted in r # removed in 3.2, class was deleted in r
monitorStats=org.apache.jmeter.visualizers.MonitorStats monitorStats=org.apache.jmeter.visualizers.MonitorStats
sampleEvent=org.apache.jmeter.samplers.SampleEvent sampleEvent=org.apache.jmeter.samplers.SampleEvent