1. 程式人生 > >性能測試二十九:Dubbo框架測試腳本編寫

性能測試二十九:Dubbo框架測試腳本編寫

dom con products 啟動 .class stat out 技術 ext.get

測試腳本編寫

技術分享圖片

新建一個folder命名為lib,用於存放依賴包

技術分享圖片

把以下jar全部拷進lib下,並build path

技術分享圖片

找開發要 真正要測試的以jar包形式存在的代碼的類,

技術分享圖片

技術分享圖片

打開看一下

技術分享圖片

技術分享圖片

放到lib並build

技術分享圖片

所以說,要測試Dubbo框架下的接口,lib下要導入Dubbo框架的jar,還有需要測試的接口的jar包

導入配置文件

技術分享圖片

技術分享圖片

修改配置項,ip,接口

技術分享圖片

到這,準備工作就做好了,開始寫代碼訪問

技術分享圖片

package cn.test.dubbo;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.li.domain.Product;
import com.li.service.ProductService;

public class MyDubboTest {

public static void main(String[] args) {
//1、首先啟動Dubbo框架,並且加載applicationContext.xml配置文件
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

//2、直接獲取遠程接口的對象(由框架自動完成)
//後面那個productService為配置文件中zookeeper獲取的遠程接口對象的實例(id=“···”)
ProductService productService = (ProductService) context.getBean("productService");

//3、調用接口對象的方法
Product product = productService.getProductByPid(1);
if (product == null){
System.out.println("事物失敗");
}else{
System.out.println("事物成功");
System.out.println(product);
}
}
}

性能測試二十九:Dubbo框架測試腳本編寫