parent
0fea955db9
commit
33e50a1fae
@ -1,44 +0,0 @@ |
|||||||
# 固定不变,不能改 |
|
||||||
spring.application.name=sop-gateway |
|
||||||
# 入口地址,不用改,默认是/zuul |
|
||||||
zuul.servlet-path=/api |
|
||||||
# 禁用默认的过滤器,不能删,不用改 |
|
||||||
zuul.FormBodyWrapperFilter.pre.disable=true |
|
||||||
zuul.Servlet30WrapperFilter.pre.disable=true |
|
||||||
# 不用改,如果要改,请全局替换修改 |
|
||||||
sop.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC |
|
||||||
|
|
||||||
# zuul优化配置 |
|
||||||
zuul.host.max-per-route-connections=1000 |
|
||||||
zuul.host.max-total-connections=1000 |
|
||||||
zuul.semaphore.max-semaphores=1000 |
|
||||||
|
|
||||||
# nacos cloud配置 |
|
||||||
spring.cloud.nacos.discovery.server-addr=${nacos.url} |
|
||||||
|
|
||||||
# 数据库配置 |
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver |
|
||||||
spring.datasource.url=jdbc:mysql://${mysql.host}/sop?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai |
|
||||||
spring.datasource.username=${mysql.username} |
|
||||||
spring.datasource.password=${mysql.password} |
|
||||||
|
|
||||||
# https://blog.csdn.net/qq_36872046/article/details/81058045 |
|
||||||
# 路由转发超时时间,毫秒,默认值1000,详见:RibbonClientConfiguration.DEFAULT_READ_TIMEOUT。 |
|
||||||
# 如果微服务端 处理时间过长,会导致ribbon read超时,解决办法将这个值调大一点 |
|
||||||
ribbon.ReadTimeout=5000 |
|
||||||
# 设置为true(默认false),则所有请求都重试,默认只支持get请求重试 |
|
||||||
# 请谨慎设置,因为post请求大多都是写入请求,如果要支持重试,确保服务的幂等性 |
|
||||||
ribbon.OkToRetryOnAllOperations=false |
|
||||||
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=13000 |
|
||||||
|
|
||||||
# 不用改 |
|
||||||
mybatis.fill.com.gitee.fastmybatis.core.support.DateFillInsert=gmt_create |
|
||||||
mybatis.fill.com.gitee.fastmybatis.core.support.DateFillUpdate=gmt_modified |
|
||||||
|
|
||||||
# 文件上传配置 |
|
||||||
spring.servlet.multipart.enabled=true |
|
||||||
# 这里设置大一点没关系,真实大小由upload.max-file-size控制 |
|
||||||
spring.servlet.multipart.max-file-size=50MB |
|
||||||
|
|
||||||
# 允许上传文件大小,不能超过这个值,单位:B,KB,MB |
|
||||||
upload.max-file-size=2MB |
|
@ -0,0 +1,43 @@ |
|||||||
|
package com.gitee.app.config; |
||||||
|
|
||||||
|
import org.springframework.beans.BeansException; |
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
||||||
|
import org.springframework.context.EnvironmentAware; |
||||||
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
||||||
|
import org.springframework.core.env.Environment; |
||||||
|
import org.springframework.core.env.PropertySource; |
||||||
|
import org.springframework.core.env.PropertySources; |
||||||
|
import org.springframework.web.context.support.StandardServletEnvironment; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author tanghc |
||||||
|
*/ |
||||||
|
public class MyPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements EnvironmentAware { |
||||||
|
|
||||||
|
private Environment environment; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setEnvironment(Environment environment) { |
||||||
|
this.environment = environment; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
||||||
|
super.postProcessBeanFactory(beanFactory); |
||||||
|
if (environment instanceof StandardServletEnvironment) { |
||||||
|
PropertySources appliedPropertySources = this.getAppliedPropertySources(); |
||||||
|
for (PropertySource<?> propertySource : appliedPropertySources) { |
||||||
|
Object source = propertySource.getSource(); |
||||||
|
if (source instanceof Map) { |
||||||
|
Map map = (Map)source; |
||||||
|
map.forEach((key, value)-> { |
||||||
|
System.setProperty(key.toString(), value.toString()); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
spring.application.name=sop-springmvc |
||||||
|
server.port=2223 |
||||||
|
server.servlet.context-path=/sop-springmvc |
||||||
|
|
||||||
|
nacos.server-addr=127.0.0.1:8848 |
@ -1,64 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 使用支付宝工具生成签名,这里演示的是PKCS1(非java) |
|
||||||
*/ |
|
||||||
public class AlipayToolPKCS1Test extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "201904035630907729292csharp"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEowIBAAKCAQEA5+OvJxeSzf44NxQ/cl7Ii+BzPg2k6sRcvH4ffOtU5Dzq1/oEvg02nxIhmwOHBZmjbmuUu0aLsfglUTAwqfXftfAKZidshsgj9NNh0/kxk0avRZ1UoljWGz/FxVZA0ogbxxhohPZ9jWcD+eBQcIwF2DtHfAJqWWZrYFnCMeHD8mPzxo2kwXSvDzi0vf9I2tKiYvNG26a9FqeYtPOoi81sdS3+70HOMdxP8ejXtyfnKpKz7Dx506LCIRS5moWS3Q5eTLV3NGX/1CSJ8wpQA2DAQTjVhX5eVu7Yqz12t8W+sjWM/tHUR6cgwYYR10p7tSCeCPzkigjGxKm4cYXWtATQJQIDAQABAoIBAHFDsgrrJca+NKEan77ycwx3jnKx4WrWjOF4zVKL9AQjiSYDNgvKknJyPb3kpC/lEoHdxGERHSzJoxib7DkoIqRQYhPxj73pxj5QfYk3P7LLJNNg/LTrpXDb3nL8JV9wIflGf87qQvstZTDJEy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
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
|
|
||||||
{ |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
// 手动改下这里的时间,改成当前时间
|
|
||||||
params.put("timestamp", "2019-12-28 11:23:29"); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 第一步:生成请求参数。 |
|
||||||
* 生成后的字符串放到支付宝工具【请求参数】中,将上面的privateKey放到【商户应用私钥】中 |
|
||||||
* 点击【开始签名】 |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testFirst() { |
|
||||||
System.out.println("请求参数:"); |
|
||||||
System.out.println(buildParamQuery(params)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 第二步:将生成到签名放到sign变量中,然后运行本方法 |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSecond() { |
|
||||||
String sign = "sOK1Kwoq6OmjFoneb6LRgUpX+/uQ9D9gsV1Cgi6aw/ErUWLYqMkESuJ148uV1rk5ms8ok9n4T4LpM7aJEYLo9IguW5eVCQ+ePe3ea6gjEQIZm2fiymfSdasSrrBDN/oLqhFwWRGzTQ5TWAgxpNCLH2zKMc+Z5ir7W6xeA0CcEmhZYXC3fB4MSnPcCbHj4V0LLAoQZZQ3voHpdh+6OYNzMKcrwJTTbukI6LbVPopO44ZanV11ehytKLJB71wGJlvFIMK+N3Gph01JKFvfzOlMmndGiDodOjgSz+aQBIjlcyCea/PXSzr2fa5efvWDX/5QayhWkWQ3/1ocBMj7/d4pMA=="; |
|
||||||
// 这里用支付宝工具生成
|
|
||||||
params.put("sign", sign); |
|
||||||
System.out.println("----------- 返回结果 -----------"); |
|
||||||
String responseData = get(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,64 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 使用支付宝工具生成签名,这里演示的是PKCS8(java) |
|
||||||
*/ |
|
||||||
public class AlipayToolPKCS8Test extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w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
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
|
|
||||||
{ |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
// 手动改下这里的时间,改成当前时间
|
|
||||||
params.put("timestamp", "2019-12-28 11:23:29"); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 第一步:生成请求参数。 |
|
||||||
* 生成后的字符串放到支付宝工具【请求参数】中,将上面的privateKey放到【商户应用私钥】中 |
|
||||||
* 点击【开始签名】 |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testFirst() { |
|
||||||
System.out.println("请求参数:"); |
|
||||||
System.out.println(buildParamQuery(params)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 第二步:将生成到签名放到sign变量中,然后运行本方法 |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSecond() { |
|
||||||
String sign = "Wt80mV3ojQ4++19yUhG1pjElGc5rWRJ0udoPv6yHjDG9h0Ai8/sQx9XaWBfiPR3YU6ZzTznr1gEYeXpJg3X9ptLjkMG3xx5NRkCMTYi9eZ40c8RU13O/mQDDr8can59jYgG3PUCTBSpymBnZsTxAzCuho3p26vm64napu+XlKiWEU1yQz46Ga8hW9EBRFFBWvwSsXqp0ZUuddXIj4nhuRr/miSsGgtGXByRMgOh+FLivZnIZJmjP1fS3Veq4Qp2Pv/V+7r+3DBBclos2OF72O1lrALWA8qrHhyjWyFPuNJv6b7PA0vKUenthSPeKH1qJTmMIqlokRrrrD5Ubt1pDJg=="; |
|
||||||
// 这里用支付宝工具生成
|
|
||||||
params.put("sign", sign); |
|
||||||
System.out.println("----------- 返回结果 -----------"); |
|
||||||
String responseData = get(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,58 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
public class JSR303DemoTest extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5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
@Test |
|
||||||
public void testGoodsAdd() throws Exception { |
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "goods.add"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
// 对应校验规则查看GoodsParam.java
|
|
||||||
// bizContent.put("goods_name", "iphone6");
|
|
||||||
// bizContent.put("goods_remark", "iphone6");
|
|
||||||
// bizContent.put("goods_comment", "1");
|
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
System.out.println("----------- 请求信息 -----------"); |
|
||||||
System.out.println("请求参数:" + buildParamQuery(params)); |
|
||||||
System.out.println("商户秘钥:" + privateKey); |
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
System.out.println("待签名内容:" + content); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
System.out.println("签名(sign):" + sign); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
System.out.println("----------- 返回结果 -----------"); |
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,86 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据路由id限流 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
boolean result = doBusiness(Thread.currentThread().getName()); |
|
||||||
if (result) { |
|
||||||
success.incrementAndGet(); |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public boolean doBusiness(String threadName) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.2"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
JSONObject jsonObject = JSON.parseObject(responseData).getJSONObject("alipay_story_get_response"); |
|
||||||
return "10000".equals(jsonObject.getString("code")); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,95 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据【路由ID + appKey】限流 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest2 extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
// 这个appKey会被限流
|
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; |
|
||||||
|
|
||||||
// 这个appKey不会被限流
|
|
||||||
String appId2 = "20190401562373672858288128"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey2 = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI6BKjoZ/Azxr6tRPibrWdlrurlwmmMvuW7FAq4m+QyX9DJ1WvNE+KcKHrOqAEkNrthjZfrPlPJOSNi4ORgyt3Idxi8IO4nQ2lE9kxH5AMTvTKn3An6Q6pNrxt6km3HO4JgvEXP7BGwgW3ScjELq20Joz04TD8F+WHCzfFzPDi6pAgMBAAECgYA/zuQ6ieILZbjUDBe5U46yxQMh/6KRoQ/14m81zauckPm+EkA8R3jTSru+lPN1wpO0vqUuLf6ylI0XxT2DcUokOgY07ZdE54pu5XAsyY0eanFwt6C1LrHYpORV3Mp9XuI3fXrxYqVlxLuj1N7MGinXUuW7aZCHaEuSnZ55OL9dkQJBANKOeFiYDISSuIFHSrndSgr+a8E44jS/2/7lE49p5l3WVOFTHh0IZQNTs/IKsKJkUnYDE4W/Ab7NTnWZpXYeM30CQQCtQrtxPEzLl4dtupPOBJJoApj2lq7Q6tIGx178K6wS9Rz3GEvkA7fz1Tpm+nmPZflWZ9mVmEaVuMTMpl3HN/edAkBylyzx8lYltIALg5QskT1hvFNChkW9tYjyMROzIkxIV4Q8WPLzlAT9iYlOOfkld/nU1hnC2VAG2k9P+z2sigU1AkBAl1AptsEqZSMn1RalBy9NdypvQ12IpQIHZOwUNnO/3YEe3P/t0TUSwbs0CMyomOuLOsvy6QHnbypu4Na1HjhBAkAWjtdhuvU15HAa5jMgiUVfQM3YFuz2k3QkRagtZZ33bqnYs4wNxEZqB5t+vEj+8r3fmSN0BpNR1VW71j53Ir0H"; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
doTest(appId, privateKey); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testNotLimit() throws InterruptedException { |
|
||||||
doTest(appId2, privateKey2); |
|
||||||
} |
|
||||||
|
|
||||||
protected void doTest(String appId, String privateKey) throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
doBusiness(Thread.currentThread().getName(), appId, privateKey); |
|
||||||
success.incrementAndGet(); |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public void doBusiness(String threadName, String appKey, String priKey) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appKey); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, priKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,80 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据appKey限流 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest3 extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "20190401562373796095328256"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJvGfQSfZyPb23yL6bV1Pux4X1dDHdwRqgKVcVOWZzvxjVm5AVvJj31VLC/wlu2kbE+8FJUP1I+ZdY0FEFtIdP6DFK1x1cP1B4PeScYXL/VX7PcTZGP/osiUWaBOUaHV+YSC20+OxRbUOPvTj/J3IivD4IDIAwpDKsWDTBiY1b5RAgMBAAECgYAE27/ycPZKjATgcYyseCeqQGbY1eMMhhCDXB3YuYwmtnXuInMEZdjv08Q5CovqhYJLSlZp/8BlaifcahgEgNIFQXmxAF0U0HsNC6W4Dk1gGgQaVmYaZv5ex7uIcFB1qFvlO60kWf82YeRnO5KsFBODOJ1XSNwqjL2GeLSHBSVyQQJBAOsvDmClBsETSdiNSFMz+D9WCnCh1Ip4AoCzA/yG+PRSwYjZDdceP2DXieiZXPlxTFZ7MIXxAafgeyeQA2hpkQUCQQCpkCUSbrZ+nd4BYdnxZOSf0//cUT0o6+3kROX7gsXV7zRAWWxojT6DkGVlduDLZM/hjWeHRjWUxKC/jgbzvundAkBckhUSrWJPNQxoFJRXS6l3JKLPWqOSLVKu3ce/6lCrurc66lSsS9eegrhhuZwDAzmNAMhEsGx6a72OAP2WZ5cRAkBd8cT4X2qw4BpePa6YdcPNYZHCqSfvgje9XwbkwGGH1A3pESJlEsxt7BShkKmfRu1+E/AmHJoXIJHHT5M+fKnpAkA+VfyAAviKeCwUSq+5oUa0B+ozEA3frp/40cKQP7k02aamocAQCDRaC1ZlWffeQqYMnYe1/Mjr/SdX/Ut3X0CC"; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
doBusiness(Thread.currentThread().getName()); |
|
||||||
success.incrementAndGet(); |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public void doBusiness(String threadName) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.2"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,80 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据【ip】限流 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest4 extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "20190513577548661718777856"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJ0aPPcgTZVC14ONBoVpxcsIAip0QghVx/stbt/XjZXnlDTG1yMNM4eMEcTFmwbrj9jlYrPihBVYadfC2uV53xCDRgADu55q3yYTw3MlKb23Ft9T2HBcHvucnFWQXJpIbWnQhkWs1ClttTFNf3vnl14/sN1xIXXjwsuvT3VX75LdAgMBAAECgYB68z/nQDa3q/oykDocS21qujfHtfi/wTKjVylAsdezC+wnab6RRhGf8XUuhGARiGWpn8whcBNjCTC8lVju4vQ5IIx4Hb74vwDDMtNXeqwkLmARLYu2ELibauezSeqom8/J8cR3ho7Hr4VHPTiC8qvePRmu8AvXVQz2T7SOhEjDGQJBAOm8XOivr+atiknLbQhmo508ON3sjoN9VMwK9cmnup+ZPCsurJTHRja0MJQNdOXObUVJ6wJhs1PHWT+vITfXGJ8CQQCsESzxOYTkZaqBUFjbWVf1rSwjOOsylweTuq44YIJkHhwMjHf3kN/UTXbxsBPUGeT7/+2K5UwQ9snUPr0yTBcDAkA0FMezBWqxgNu+g7iA1bYBVCjrskkzHVsmuA56Z4hbBZ71lEnaQOjxSYdFhhYVGsEYXlciSbjWoyXM3e4N7jzLAkB0ejv+H33CTsAZQZalBdnxSQTz4vf0CyDp9BkzuMELnQZHyF79i2i5gqbd/N+vWMgVfq4CtC3F3gnKT54rii6ZAkAMBIvHriT5Zbs1fW+oxBP1rHqdsRvqs1zEyIadvJgKAFwFEisryfdw2mWm3vxQQ22RlOquBiZEDIlyM0z2m9PJ"; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
doBusiness(Thread.currentThread().getName()); |
|
||||||
success.incrementAndGet(); |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public void doBusiness(String threadName) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,80 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据【ip + 路由id】限流 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest5 extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "20190513577548661718777856"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJ0aPPcgTZVC14ONBoVpxcsIAip0QghVx/stbt/XjZXnlDTG1yMNM4eMEcTFmwbrj9jlYrPihBVYadfC2uV53xCDRgADu55q3yYTw3MlKb23Ft9T2HBcHvucnFWQXJpIbWnQhkWs1ClttTFNf3vnl14/sN1xIXXjwsuvT3VX75LdAgMBAAECgYB68z/nQDa3q/oykDocS21qujfHtfi/wTKjVylAsdezC+wnab6RRhGf8XUuhGARiGWpn8whcBNjCTC8lVju4vQ5IIx4Hb74vwDDMtNXeqwkLmARLYu2ELibauezSeqom8/J8cR3ho7Hr4VHPTiC8qvePRmu8AvXVQz2T7SOhEjDGQJBAOm8XOivr+atiknLbQhmo508ON3sjoN9VMwK9cmnup+ZPCsurJTHRja0MJQNdOXObUVJ6wJhs1PHWT+vITfXGJ8CQQCsESzxOYTkZaqBUFjbWVf1rSwjOOsylweTuq44YIJkHhwMjHf3kN/UTXbxsBPUGeT7/+2K5UwQ9snUPr0yTBcDAkA0FMezBWqxgNu+g7iA1bYBVCjrskkzHVsmuA56Z4hbBZ71lEnaQOjxSYdFhhYVGsEYXlciSbjWoyXM3e4N7jzLAkB0ejv+H33CTsAZQZalBdnxSQTz4vf0CyDp9BkzuMELnQZHyF79i2i5gqbd/N+vWMgVfq4CtC3F3gnKT54rii6ZAkAMBIvHriT5Zbs1fW+oxBP1rHqdsRvqs1zEyIadvJgKAFwFEisryfdw2mWm3vxQQ22RlOquBiZEDIlyM0z2m9PJ"; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
doBusiness(Thread.currentThread().getName()); |
|
||||||
success.incrementAndGet(); |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public void doBusiness(String threadName) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.1"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,81 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.CountDownLatch; |
|
||||||
import java.util.concurrent.atomic.AtomicInteger; |
|
||||||
|
|
||||||
/** |
|
||||||
* 限流测试,根据【ip + appKey】限流 |
|
||||||
* 这条规则实际没什么用,因为确定了appKey,ip也就不重要了。这里作为测试演示一下 |
|
||||||
*/ |
|
||||||
public class LimitDemoPostTest6 extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "20190513577548661718777857"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJ0aPPcgTZVC14ONBoVpxcsIAip0QghVx/stbt/XjZXnlDTG1yMNM4eMEcTFmwbrj9jlYrPihBVYadfC2uV53xCDRgADu55q3yYTw3MlKb23Ft9T2HBcHvucnFWQXJpIbWnQhkWs1ClttTFNf3vnl14/sN1xIXXjwsuvT3VX75LdAgMBAAECgYB68z/nQDa3q/oykDocS21qujfHtfi/wTKjVylAsdezC+wnab6RRhGf8XUuhGARiGWpn8whcBNjCTC8lVju4vQ5IIx4Hb74vwDDMtNXeqwkLmARLYu2ELibauezSeqom8/J8cR3ho7Hr4VHPTiC8qvePRmu8AvXVQz2T7SOhEjDGQJBAOm8XOivr+atiknLbQhmo508ON3sjoN9VMwK9cmnup+ZPCsurJTHRja0MJQNdOXObUVJ6wJhs1PHWT+vITfXGJ8CQQCsESzxOYTkZaqBUFjbWVf1rSwjOOsylweTuq44YIJkHhwMjHf3kN/UTXbxsBPUGeT7/+2K5UwQ9snUPr0yTBcDAkA0FMezBWqxgNu+g7iA1bYBVCjrskkzHVsmuA56Z4hbBZ71lEnaQOjxSYdFhhYVGsEYXlciSbjWoyXM3e4N7jzLAkB0ejv+H33CTsAZQZalBdnxSQTz4vf0CyDp9BkzuMELnQZHyF79i2i5gqbd/N+vWMgVfq4CtC3F3gnKT54rii6ZAkAMBIvHriT5Zbs1fW+oxBP1rHqdsRvqs1zEyIadvJgKAFwFEisryfdw2mWm3vxQQ22RlOquBiZEDIlyM0z2m9PJ"; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLimit() throws InterruptedException { |
|
||||||
int threadsCount = 10; // threadsCount个线程同时提交
|
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
||||||
final CountDownLatch count = new CountDownLatch(threadsCount); |
|
||||||
final AtomicInteger success = new AtomicInteger(); |
|
||||||
for (int i = 0; i < threadsCount; i++) { |
|
||||||
new Thread(new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
try { |
|
||||||
countDownLatch.await(); // 等在这里,执行countDownLatch.countDown();集体触发
|
|
||||||
// 业务方法
|
|
||||||
doBusiness(Thread.currentThread().getName()); |
|
||||||
success.incrementAndGet(); |
|
||||||
} catch (Exception e) { |
|
||||||
} finally { |
|
||||||
count.countDown(); |
|
||||||
} |
|
||||||
} |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
countDownLatch.countDown(); |
|
||||||
count.await(); |
|
||||||
System.out.println("成功次数:" + success); |
|
||||||
} |
|
||||||
|
|
||||||
// 这个请求会路由到story服务
|
|
||||||
public void doBusiness(String threadName) throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.1"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,64 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipayApiException; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
|
|
||||||
public class LoadBalanceTest extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2t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qku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; |
|
||||||
|
|
||||||
// 测试稳定性
|
|
||||||
@Test |
|
||||||
public void testLoadBalance() throws Exception { |
|
||||||
int i = 0; |
|
||||||
while (i++ < 50) { |
|
||||||
doTest(); |
|
||||||
Thread.sleep(3000); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void doTest() throws AlipayApiException { |
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "alipay.story.get"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
bizContent.put("id", "1"); |
|
||||||
bizContent.put("name", "葫芦娃"); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
// System.out.println("----------- 请求信息 -----------");
|
|
||||||
// System.out.println("请求参数:" + buildParamQuery(params));
|
|
||||||
// System.out.println("商户秘钥:" + privateKey);
|
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
// System.out.println("待签名内容:" + content);
|
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
// System.out.println("签名(sign):" + sign);
|
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
// System.out.println("----------- 返回结果 -----------");
|
|
||||||
String responseData = get(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,55 +0,0 @@ |
|||||||
package com.gitee.sop.test; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 测试是否有权限访问,可在sop-admin中设置权限 |
|
||||||
*/ |
|
||||||
public class PermissionDemoPostTest extends TestBase { |
|
||||||
|
|
||||||
String url = "http://localhost:8081"; |
|
||||||
String appId = "2019032617262200001"; |
|
||||||
// 平台提供的私钥
|
|
||||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testPost() throws Exception { |
|
||||||
|
|
||||||
// 公共请求参数
|
|
||||||
Map<String, String> params = new HashMap<String, String>(); |
|
||||||
params.put("app_id", appId); |
|
||||||
params.put("method", "story.get.permission"); |
|
||||||
params.put("format", "json"); |
|
||||||
params.put("charset", "utf-8"); |
|
||||||
params.put("sign_type", "RSA2"); |
|
||||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
|
||||||
params.put("version", "1.0"); |
|
||||||
|
|
||||||
// 业务参数
|
|
||||||
Map<String, String> bizContent = new HashMap<>(); |
|
||||||
|
|
||||||
params.put("biz_content", JSON.toJSONString(bizContent)); |
|
||||||
|
|
||||||
System.out.println("----------- 请求信息 -----------"); |
|
||||||
System.out.println("请求参数:" + buildParamQuery(params)); |
|
||||||
System.out.println("商户秘钥:" + privateKey); |
|
||||||
String content = AlipaySignature.getSignContent(params); |
|
||||||
System.out.println("待签名内容:" + content); |
|
||||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); |
|
||||||
System.out.println("签名(sign):" + sign); |
|
||||||
|
|
||||||
params.put("sign", sign); |
|
||||||
|
|
||||||
System.out.println("----------- 返回结果 -----------"); |
|
||||||
String responseData = post(url, params);// 发送请求
|
|
||||||
System.out.println(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue