Oracle Load Testing

Source: Internet
Author: User
Tags readline

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 prevent multiple threads from repeatedly loading

public static synchronized void Initdatabank (String filecsv) throws exception{

if (dblist.size () > 0) return;//has loaded data to prevent multiple loads under multi-threading

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.