Oracle Load Testing

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.