smsService介面(dubbo介面)
阿新 • • 發佈:2018-11-12
package com.lakala.crosspay.jmeter.client.integration; import com.lakala.crosspay.sms.api.SmsService; import com.lakala.crosspay.sms.api.dto.SmsDTO; import com.lakala.sh.framework.core.error.Result; import com.lakala.sh.framework.core.utils.DateUtil; import org.apache.commons.lang3.RandomStringUtils;import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.config.Arguments; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.Date; /** * SmsServiceSampleClient * * @author makarov * @desc * @date 2018/8/24 */ public class SmsServiceSampleClient extends AbstractJavaSamplerClient { private ApplicationContext applicationContext; private long startTimestamp; private long endTimestamp; @Overridepublic Arguments getDefaultParameters() { Arguments args = new Arguments(); args.addArgument("Sid", ""); args.addArgument("mobile",""); args.addArgument("templateNo",""); return args; } public void setupTest(JavaSamplerContext context) { applicationContext = new ClassPathXmlApplicationContext("classpath:remote-consumer.xml"); } public SampleResult runTest(JavaSamplerContext javaSamplerContext) { SmsService smsService = (SmsService) applicationContext.getBean("smsService"); getNewLogger().info("smsService:{}", smsService); SampleResult sampleResult = new SampleResult(); sampleResult.sampleStart(); try { startTimestamp = System.currentTimeMillis(); SmsDTO smsDTO = new SmsDTO(); smsDTO.setSid(RandomStringUtils.randomAlphanumeric(32)); smsDTO.setMessage("{\"BATCH_NO\":\"" + DateUtil.format(new Date(), "yyyyMMdd") + RandomStringUtils.randomNumeric(6) + "\",\"CUSTOMER_NO\":\"CUST00000001\"}"); smsDTO.setMobile("18516235811"); smsDTO.setTemplateNo("481869683453067264"); smsDTO.setType("01"); Result<SmsDTO> result = smsService.sendSms(smsDTO); if (result.isSuccess()) { sampleResult.setSuccessful(true); } else { sampleResult.setSuccessful(false); } } catch (Exception e) { sampleResult.setSuccessful(false); getNewLogger().error("呼叫服務介面異常:", e); } sampleResult.sampleEnd(); return sampleResult; } @Override public void teardownTest(JavaSamplerContext context) { endTimestamp = System.currentTimeMillis(); getNewLogger().info("呼叫介面耗時:{}ms", endTimestamp - startTimestamp); } }