码迷,mamicode.com
首页 > 数据库 > 详细

Oracle Load Testing

时间:2016-11-03 23:20:03      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:lis   reader   gettime   readline   ext   ***   turn   head   acl   

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.util.ArrayList;

import java.util.Date;

import java.util.Enumeration;

import java.util.HashMap;

import java.util.List;

import java.util.Properties;

import oracle.oats.scripting.modules.basic.api.ScriptService;

 

/**

 *

 */

/**

* @author 420309

*

*/

public class MyDatabank {

private static HashMap<String,int[]> DBDesc = new HashMap<String,int[]>();

private static List<String[]> DBList = new ArrayList<String[]>();

private static String logFile = null;

private static OutputStreamWriter logger = null;

@ScriptService oracle.oats.scripting.modules.http.api.HTTPService http;

@ScriptService oracle.oats.scripting.modules.adfload.api.AdfLoadService adfload;

 

public static synchronized void setLog(String file)throws Exception{

if(logger != null) return;

logFile = file;

logger = new OutputStreamWriter(new FileOutputStream(file));

}

public static synchronized void log(String str)throws Exception{

if(logFile == null)return;

if(logger == null){

logger = new OutputStreamWriter(new FileOutputStream(logFile));

}

//String time = new Date().getTime();

logger.write(new Date().getTime() + ":" + str + "\r\n");

logger.flush();

}

// synchronized 防止多个线程重复加载

public static synchronized void initDatabank(String fileCSV)throws Exception{

if(DBList.size() > 0) return;//是否已经加载数据,防止多线程下多次加载

log("initDatabank:"+fileCSV);

BufferedReader br = new BufferedReader(new InputStreamReader(

new FileInputStream(fileCSV)));  

String rec = null;

try {

br.readLine();//Ignore CSV Header

while ((rec = br.readLine()) != null) {

//System.out.println("line:"+rec);

String[] cells = rec.split(",");

DBList.add(cells);  

}             

} catch (Exception e) {  

throw e;  

} finally {  

 if (br != null) {  

br.close();  

    }  

}

}

//LINE:based-1

public static synchronized void initDatabankDesc(String fileDesc)throws Exception{

if(DBDesc.size() > 0) return;

log("initDatabankDesc:"+fileDesc);

Properties props = new Properties();

props.load(new FileInputStream(fileDesc));

Enumeration<String> enums = (Enumeration<String>)props.propertyNames();

String name = null;

String value = null;

int idx = -1;

int s,e;

while(enums.hasMoreElements()){

name = enums.nextElement();

value = props.getProperty(name).trim();

idx = value.indexOf(‘,‘);

if(idx == -1) throw new Exception("File Format Error,‘,‘ Not Found");

s = Integer.parseInt(value.substring(0,idx)) - 1;//based-0

e = Integer.parseInt(value.substring(idx+1)) - 1;//based-0

int[] flag = new int[]{s,e,0};//[s,e]idx-0

//System.out.println("********s:"+s+",e:"+e);

//System.out.println("********name:"+name);

DBDesc.put(name, flag);

}

}

//col:based-0

public static String getNextDatabank(String name,int col)throws Exception{

int[] flag = DBDesc.get(name);

if(flag == null) throw new Exception("Name:["+name+"] Not Found");

Object obj = new Object();

int idx = -1;

synchronized(obj){

idx = flag[0]+flag[2];

if(idx > flag[1]) {

idx = flag[0];

flag[2] = 0;

}

flag[2]++;

}

String[] cells = DBList.get(idx);

if(cells == null)throw new Exception("Name:["+name+"],Row:["+(idx + 1)+"] Not Found");

log("getNextDatabank:name["+name+"],idx["+idx+"],col["+col+"] = ["+cells[col]+"]");

            return cells[col];

}

public static int getDatabankCount(String name)throws Exception{

int[] flag = DBDesc.get(name);

if(flag == null) throw new Exception("Name:["+name+"] Not Found");

int count = flag[1] - flag[0] + 1;

log("getDatabankCount:"+count);

return count;

}

}

Oracle Load Testing

标签:lis   reader   gettime   readline   ext   ***   turn   head   acl   

原文地址:http://www.cnblogs.com/qizhelongdeyang/p/5845071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!