1.脚本
package com.***.****.perf;
import com. ***.****.client.GCException;
import com. ***.****.client.domain.article.ArticleDTO;
import com. ***.****.client.service.inner.ArticleReadService;
import com. ***.****.hsfunit.HSFEasyStarter;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Author: wuche
* Date: 12-3-31
* Time: 下午4:32
*/
public class GetArticleByIdAPI {
private ArticleReadService articleReadService;
private static GetArticleByIdAPI _instance = null;
public static GetArticleByIdAPI getInstance() {
if (_instance == null)
_instance = new GetArticleByIdAPI();
return _instance;
}
private GetArticleByIdAPI() {
HSFEasyStarter.start();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"itemcenter-client.perf.context.xml");
articleReadService = (ArticleReadService) context
.getBean("articleReadService");
}
public boolean getArticleById(long articleId) throws Exception{
articleId = 22104195L;
ArticleDTO result = null;
try {
result = articleReadService.getArticleById(articleId);
} catch (GCException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
if (null == result)
return false;
else
return true;
}
public static void main(String[] args) throws Exception {
long article = 22104195L;
GetArticleByIdAPI api = GetArticleByIdAPI.getInstance();
// for(int i=0 ;i<1000;i++){
System.out.println(api.getArticleById(article)?"TRUE":"FALSE");
// System.out.println(byIdApi.testGetArticleByCode(code)?"TRUE":"FALSE");
//
// }
}
import com. ***.****.client.GCException;
import com. ***.****.client.domain.article.ArticleDTO;
import com. ***.****.client.service.inner.ArticleReadService;
import com. ***.****.hsfunit.HSFEasyStarter;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Author: wuche
* Date: 12-3-31
* Time: 下午4:32
*/
public class GetArticleByIdAPI {
private ArticleReadService articleReadService;
private static GetArticleByIdAPI _instance = null;
public static GetArticleByIdAPI getInstance() {
if (_instance == null)
_instance = new GetArticleByIdAPI();
return _instance;
}
private GetArticleByIdAPI() {
HSFEasyStarter.start();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"itemcenter-client.perf.context.xml");
articleReadService = (ArticleReadService) context
.getBean("articleReadService");
}
public boolean getArticleById(long articleId) throws Exception{
articleId = 22104195L;
ArticleDTO result = null;
try {
result = articleReadService.getArticleById(articleId);
} catch (GCException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
if (null == result)
return false;
else
return true;
}
public static void main(String[] args) throws Exception {
long article = 22104195L;
GetArticleByIdAPI api = GetArticleByIdAPI.getInstance();
// for(int i=0 ;i<1000;i++){
System.out.println(api.getArticleById(article)?"TRUE":"FALSE");
// System.out.println(byIdApi.testGetArticleByCode(code)?"TRUE":"FALSE");
//
// }
}
}
2.配置文件
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<!--<bean name="articleReadService" class="com. ***.****.app.spring.util.HSFSpringConsumerBean" init-method="init">-->
<!--<property name="interfaceName" value="com. ***.****.client.service.inner.ArticleReadService" />-->
<!--<property name="version" value="1.0.0.perf" />-->
<!--<property name="group" value="HSF" />-->
<!--</bean>-->
<bean name="itemReadService" class=" ***.****.app.spring.util.HSFSpringConsumerBean" init-method="init">
<property name="interfaceName" value=" ***.****.client.service.inner.ItemReadService" />
<property name="version" value="1.0.0.perf" />
<property name="group" value="HSF" />
</bean>
</beans>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<!--<bean name="articleReadService" class="com. ***.****.app.spring.util.HSFSpringConsumerBean" init-method="init">-->
<!--<property name="interfaceName" value="com. ***.****.client.service.inner.ArticleReadService" />-->
<!--<property name="version" value="1.0.0.perf" />-->
<!--<property name="group" value="HSF" />-->
<!--</bean>-->
<bean name="itemReadService" class=" ***.****.app.spring.util.HSFSpringConsumerBean" init-method="init">
<property name="interfaceName" value=" ***.****.client.service.inner.ItemReadService" />
<property name="version" value="1.0.0.perf" />
<property name="group" value="HSF" />
</bean>
</beans>
3. 用 mvn install. 打包
4. 把打好的包和依赖的jar包放在grinder/lib目录下
5. 修改grinder.properties文件
grinder.jvm.classpath 增加/home/wuche/grinder-3.7.1/lib/app/itemcenter-perf-1.0.jar jar包
6.编辑grinder脚本
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.script import Test
#import 这个测试类
from com.taobao.itemcenter.perf import UpdateItemQuantityAPI
from com.taobao.itemcenter.perf import UpdateItemQuantityAPI
#创建一个test,number+description
test1 = Test(1, "updateQuantity")
# Wrap the log() method with our Test and call the result logWrapper.
# Calls to logWrapper() will be recorded and forwarded on to the real
# log() method.
# Calls to logWrapper() will be recorded and forwarded on to the real
# log() method.
updateQuantity = test1.wrap(api.testUpdateItemQuantityForSubStockAtBuyAndSkuId)
# A TestRunner instance is created for each thread. It can be used to
# store thread-specific data.
class TestRunner:
# This method is called for every run.
def __call__(self):
grinder.statistics.delayReports = 1
#tid = grinder.getThreadNumber()
#itemId = 2791425
#skuId = 0
itemId = 6144
#itemId = 2791425
skuId = 4459
#if(0 == (tid % 3)):
# success = updateQuantityForSub(itemid)
#else:
success = updateQuantity(itemId,skuId)
#success = updateQuantity(itemId)
#grinder.sleep(1000)
if(not success):
grinder.statistics.forLastTest.success = 0
grinder.statistics.report()
grinder.statistics.delayReports = 0
# store thread-specific data.
class TestRunner:
# This method is called for every run.
def __call__(self):
grinder.statistics.delayReports = 1
#tid = grinder.getThreadNumber()
#itemId = 2791425
#skuId = 0
itemId = 6144
#itemId = 2791425
skuId = 4459
#if(0 == (tid % 3)):
# success = updateQuantityForSub(itemid)
#else:
success = updateQuantity(itemId,skuId)
#success = updateQuantity(itemId)
#grinder.sleep(1000)
if(not success):
grinder.statistics.forLastTest.success = 0
grinder.statistics.report()
grinder.statistics.delayReports = 0