Oracle Load Testing

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle Load Testing相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Oracle Load Testing

tail查看oracle执行过的sql

navicat 连接Oracle 报错:Cannot load OCI DLL, 126

import cx_Oracle ImportError: DLL load failed: 找不到指定的模块。

Navicat连接Oracle报错_Cannot load OCI DLL 87

cannot load oci dll,193-navicate连接oracle的解决方法