From cfe53616c8ff9f79d614f3fddc5426ac60eb36ee Mon Sep 17 00:00:00 2001 From: prabatuty Date: Sat, 6 Nov 2010 05:52:18 +0000 Subject: [PATCH] adding test scripts --- test/load/Makefile | 47 ++++++++++++++ test/load/SQLAdapterTest.c | 77 ++++++++++++++++++++++ test/soakTest/Makefile | 58 +++++++++++++++++ test/soakTest/README | 38 +++++++++++ test/soakTest/create.sql | 1 + test/soakTest/csql.conf | 141 +++++++++++++++++++++++++++++++++++++++++ test/soakTest/csqlInsert.c | 89 ++++++++++++++++++++++++++ test/soakTest/jdbcDelete.java | 63 ++++++++++++++++++ test/soakTest/jdbcSelect.java | 39 ++++++++++++ test/soakTest/jdbcSelect1.java | 66 +++++++++++++++++++ test/soakTest/jdbcUpdate.java | 73 +++++++++++++++++++++ test/soakTest/odbcInsert.c | 111 ++++++++++++++++++++++++++++++++ test/soakTest/schema.sql | 3 + test/soakTest/setupenv.ksh | 5 ++ test/soakTest/start.ksh | 3 + 15 files changed, 814 insertions(+) create mode 100644 test/load/Makefile create mode 100644 test/load/SQLAdapterTest.c create mode 100644 test/soakTest/Makefile create mode 100644 test/soakTest/README create mode 100644 test/soakTest/create.sql create mode 100644 test/soakTest/csql.conf create mode 100644 test/soakTest/csqlInsert.c create mode 100644 test/soakTest/jdbcDelete.java create mode 100644 test/soakTest/jdbcSelect.java create mode 100644 test/soakTest/jdbcSelect1.java create mode 100644 test/soakTest/jdbcUpdate.java create mode 100644 test/soakTest/odbcInsert.c create mode 100644 test/soakTest/schema.sql create mode 100644 test/soakTest/setupenv.ksh create mode 100755 test/soakTest/start.ksh diff --git a/test/load/Makefile b/test/load/Makefile new file mode 100644 index 00000000..e1605528 --- /dev/null +++ b/test/load/Makefile @@ -0,0 +1,47 @@ + +OSNAME = $(shell uname -s) +PlatForm=notsupported + +ifeq ($(OSNAME), SunOS) +CPlus = CC +CPlusFlags = -O2 -w $(COMPILER_FLAG) +SYSLIBS=-ldl -lnsl -lsocket -lposix4 +PlatForm=supported +endif +ifeq ($(OSNAME), Linux) +CPlus = g++ +CPlusFlags = -O2 -w +SYSLIBS= -rdynamic -lrt -lpthread -lcrypt +PlatForm=supported +endif + +ifeq ($(OSNAME), FreeBSD) +CPlus = g++ +CPlusFlags = -O2 -w +SYSLIBS= -rdynamic -lrt -lpthread -lcrypt +PlatForm=supported +endif + + +JAVAC = javac -g:none +INCL= -I$(CSQL_INSTALL_ROOT)/include -I../../include +LIBS= -L/home/prabatuty/myroot/lib -L$(CSQL_INSTALL_ROOT)/lib -L/usr/local/lib -lcsqlsql -lcsqlsqllog -lcsql -lcsqlnw -lodbc -lcsqlgw -lcacheload -lcsqlsqlnw -lcsqlodbcadapter + +TARGETS = \ + SQLAdapterTest + + +ifeq ($(PlatForm), supported) +all: $(TARGETS) +else +all: + echo "CSQL is not supported on $(OSNAME) platform" +endif + + +SQLAdapterTest: SQLAdapterTest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) + +clean: + rm -f $(TARGETS) *.class + diff --git a/test/load/SQLAdapterTest.c b/test/load/SQLAdapterTest.c new file mode 100644 index 00000000..bff022e0 --- /dev/null +++ b/test/load/SQLAdapterTest.c @@ -0,0 +1,77 @@ +#include +#include +#include +#define ITERATIONS 10000 +int main() +{ + DbRetVal rv = OK; + AbsSqlConnection *con = SqlFactory::createConnection(CSqlGateway); + rv = con->connect("root", "manager"); + if (rv != OK) return 1; + AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlGateway); + stmt->setConnection(con); + char statement[1024]; + int id1 =10; + int newVal = 1000; + int count =0, rows=0; + /* + strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);"); + rv = stmt->prepare(statement); + if (rv != OK) {delete stmt; delete con; return -1; } + for (int i = 0 ; i < ITERATIONS ; i++) + { + rv = con->beginTrans(); + if (rv != OK) break; + id1 = i; + stmt->setIntParam(1, id1); + stmt->setIntParam(2, id1); + rv = stmt->execute(rows); + if (rv != OK) break; + rv = con->commit(); + if (rv != OK) break; + count++; + } + stmt->free(); + */ + + /*strcpy(statement, "UPDATE t1 set f2=? where f1=?;"); + rv = stmt->prepare(statement); + if (rv != OK) {delete stmt; delete con; return -1; } + count =0; + for (int i = 0 ; i < ITERATIONS ; i++) + { + rv = con->beginTrans(); + if (rv != OK) break; + stmt->setIntParam(2, i); + stmt->setIntParam(1, newVal); + rv = stmt->execute(rows); + if (rv != OK && rows !=1) break; + rv = con->commit(); + if (rv != OK) break; + count++; + } + stmt->free(); + */ + + strcpy(statement, "DELETE FROM t1 where f1=?;"); + rv = stmt->prepare(statement); + if (rv != OK) {delete stmt; delete con; return -1; } + stmt->bindField(1, &id1); + count =0; + for (int i = 0 ; i < ITERATIONS ; i++) + { + rv = con->beginTrans(); + if (rv != OK) break; + stmt->setIntParam(1, i+100000); + rv = stmt->execute(rows); + if (rv != OK && rows != 1) break; + rv = con->commit(); + if (rv != OK) break; + count++; + } + stmt->free(); + + delete stmt; + delete con; + return 0; +} diff --git a/test/soakTest/Makefile b/test/soakTest/Makefile new file mode 100644 index 00000000..e1c9dfaf --- /dev/null +++ b/test/soakTest/Makefile @@ -0,0 +1,58 @@ +OSNAME = $(shell uname -s) +PlatForm=notsupported +ifeq ($(OSNAME), SunOS) + CPlus = CC + CPlusFlags = -O2 -w $(COMPILER_FLAG) + SYSLIBS=-ldl -lnsl -lsocket -lposix4 + PlatForm=supported +endif +ifeq ($(OSNAME), Linux) + CPlus = g++ + CPlusFlags = -g -w + SYSLIBS= -rdynamic -lrt -lpthread -lcrypt + PlatForm=supported +endif +ifeq ($(OSNAME), FreeBSD) + CPlus = g++ + CPlusFlags = -g -w + SYSLIBS= -rdynamic -lrt -lpthread -lcrypt + PlatForm=supported +endif + + + +JAVAC = javac -g:none +INCL= -I$(CSQL_INSTALL_ROOT)/include -I../../include +LIBS= -L$(CSQL_INSTALL_ROOT)/lib -lcsqlodbc -lcsqlsql -lcsqlsqllog -lcsql -lcsqlnw -lcsqlodbcadapter + +TARGETS = \ + csqlInsert \ + odbcInsert \ + jdbcDelete \ + jdbcUpdate \ + jdbcSelect\ + jdbcSelect1 + +ifeq ($(PlatForm), supported) +all: $(TARGETS) +else +all: + echo "CSQL is not supported on $(OSNAME) platform" +endif + +csqlInsert: csqlInsert.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +odbcInsert: odbcInsert.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +jdbcDelete: jdbcDelete.java + $(JAVAC) jdbcDelete.java +jdbcUpdate: jdbcUpdate.java + $(JAVAC) jdbcUpdate.java +jdbcSelect: jdbcSelect.java + $(JAVAC) jdbcSelect.java +jdbcSelect1: jdbcSelect1.java + $(JAVAC) jdbcSelect1.java + +clean: + rm -f $(TARGETS) *.class + diff --git a/test/soakTest/README b/test/soakTest/README new file mode 100644 index 00000000..0769d7c0 --- /dev/null +++ b/test/soakTest/README @@ -0,0 +1,38 @@ +SET the following +------------------ +Set missing configuration parameters in csql.conf file in this directory. + +LOG_FILE= +DATABASE_FILE +STDERR_FILE +TABLE_CONFIG_FILE +DS_CONFIG_FILE + +Make sure that the directory and files created be present before running the server. + +Run +$ . ./setupenv.ksh + +This is a soak test suit where csqlserver will run forever. +The size of USERDB is 1073741824 bytes. (1GB); + +Set kernel.shmmax=1610612736 (1.5GB) +Table of the following schema should be created in csql and TDB + +CREATE TABLE soakTable(f1 smallint, f2 int, f3 bigint, f4 char(28), primary key(f2)); + +Size of each record will be 64kB. +The total number of pages = 131068. +One page will have 127 records. +Hence there can be (131068 * 127) = 16645636 records in the database. + +There will be following processes that will be working on the 't1' table doing vvarious operations. + +1. csqlInsert: (SqlApi Script) + This process will be inserting a record every 200 ms picking a random integer the value between 1 and 16645636. + +2. odbcInsert: (odbc script) + This process will be inserting a record every 200 ms picking a random integer between 1 and 100000. + +3. jdbcDelete: (jdbc script) + This process will delete first record fetched in the table every 200 ms. diff --git a/test/soakTest/create.sql b/test/soakTest/create.sql new file mode 100644 index 00000000..19eea79f --- /dev/null +++ b/test/soakTest/create.sql @@ -0,0 +1 @@ +CREATE TABLE soakTable(f1 smallint, f2 int, f3 bigint, f6 char(28), primary key(f2)); diff --git a/test/soakTest/csql.conf b/test/soakTest/csql.conf new file mode 100644 index 00000000..6a16d74f --- /dev/null +++ b/test/soakTest/csql.conf @@ -0,0 +1,141 @@ +# CSQL System Configuration File + +#####################################Server Section######################## + +# Site ID for this CSQL server +SITE_ID=1 + +#Important: For Server section parameters, make sure that the value is same for the +# server process and all the csql client process which connects to it. otherwise, +# behavior is undefined + +# Page size. Each database is logically divided into pages and allocation happens +# in this unit of pages. Increasing this value will reduce frequent allocation of pages. +PAGE_SIZE= 8192 + +#Total number of client process which can connect and work with the +# database concurrently +MAX_PROCS = 100 + +# Maximum size of the system database. +MAX_SYS_DB_SIZE=1048576 + +#Maximum size of the user database file. +MAX_DB_SIZE=1073741824 + +#Shared memory key to be used by the system to create and locate system database. +SYS_DB_KEY=2892 + +#Shared memory key to be used by the system to create and locate user database. +USER_DB_KEY=3754 + +#Log level 0->no logging 1->Fine 2->Finer 3->Finest +LOG_LEVEL=0 + +#Give full path for the log file where important system actions are stored. +LOG_FILE=/tmp/soaktest/log/log.out + +#The virtual memory start address at which the shared memory segment +# will be created and attached. +MAP_ADDRESS=400000000 + +# Whether to enable durability +DURABILITY=true + +# Whether to enable memory map architecture for user database +MMAP=false + +# Specifies the durability mode for redo log generation +# Valid values are +# 1 ->uses standard redo logging with O_APPEND mode +# 2 ->uses standard logging with serialization +# 3 ->uses O_SYNC flag +# 4 ->uses O_DIRECT flag + +DURABLE_MODE=1 + +#Give full path for the database file where table and record information will +#be stored for durability +DATABASE_FILE=/tmp/soaktest/db + +#Important: For Server section parameters, make sure that the value is same for the server process and all the csql client process which connects to it. otherwise, behavior is undefined + +# Give full path for the std error file to store all the errors during database operations +STDERR_FILE=/tmp/soaktest/stderr.txt + +#####################################Client Section######################## + +#Mutex timeout interval seconds +MUTEX_TIMEOUT_SECS=0 +MUTEX_TIMEOUT_USECS=5000 +MUTEX_TIMEOUT_RETRIES=10 + +#Lock timeout interval seconds +LOCK_TIMEOUT_SECS=0 +LOCK_TIMEOUT_USECS=5000 +LOCK_TIMEOUT_RETRIES=10 + +#####################################Cache Section######################## + +#Whether to enable caching of tables from target database +CACHE_TABLE=true + +#DSN Name to connect to the target database. +#This should be present in ~/odbc.ini file +DSN=myodbc3 + +# Whethere to enable bidirectional updates for cached tables. +ENABLE_BIDIRECTIONAL_CACHE=false + +CACHE_RECEIVER_WAIT_SECS=10 + +#Mode of operation SYNC or ASYNC +CACHE_MODE=SYNC + +##########################SqlNetworkServer Section######################## + +# Whether to enable SqlNetwork server +CSQL_SQL_SERVER=true + +#Set port for Network access +PORT=2009 + +# Max number of seconds that the network layer waits to receive a pkt +NETWORK_RESPONSE_TIMEOUT=3 + +# Max number of seconds that the network layer waits to connect to sql server +NETWORK_CONNECT_TIMEOUT=5 + +#Whether to enable Replication across the sites +REPLICATION=false + +#No of sites to replicate +REPLICATION_SITES=16 + +#Give full path for the file where all the table information is stored +TABLE_CONFIG_FILE=/tmp/soaktest/csqltable.conf + +#Give full path of the file where all the DSN information is stored +DS_CONFIG_FILE=/tmp/soaktest/csqlds.conf + +#Give full path for the file where all the peer site information is stored +NETWORK_CONFIG_FILE=/tmp/soaktest/csqlnw.conf + +# Give full path for conflict Resolution file +CONFL_RESOL_FILE=/tmp/soaktest/conflResoFile.sql + +# MSGKEY for creating msg queue for MsgQueue Server +MSG_KEY=2255 + +# Maximum message that the message queue server is able to handle for +# asynchronous updates. This value is is default value of 'kernel.msgmax' +# parameter. +ASYNC_MSGMAX=8192 + +# Maximum number of messages that the message queue server will hold for a site +# that is down in the replication group. +MAX_QUEUE_LOGS=100 + +# Shared memory key for id generators +ID_SHM_KEY=1933 +#####################################End Section######################## diff --git a/test/soakTest/csqlInsert.c b/test/soakTest/csqlInsert.c new file mode 100644 index 00000000..ea5ec3b0 --- /dev/null +++ b/test/soakTest/csqlInsert.c @@ -0,0 +1,89 @@ +// This case inserts records in csql every 200 ms based on the random numbers it finds. + +#include +#include +#define TS 1000 +//TS -> micro secs to sleep between transaction + +int main(int argc, char **argv) +{ + DbRetVal rv = OK; + if (argv[1] == NULL) { + fprintf(stderr, "Usage: csqlInsert \n"); + return 1; + } + FILE *fp = fopen(argv[1], "a"); + struct timeval timeout; + struct timeval timeStamp; + char msgBuf[25]; + AbsSqlConnection *con = SqlFactory::createConnection(CSql); + AbsSqlConnection *adCon = SqlFactory::createConnection(CSqlAdapter); + rv = con->connect("root","manager"); + if(rv!=OK)return 1; + rv = adCon->connect("root", "manager"); + if(rv!=OK)return 1; + AbsSqlStatement *stmt = SqlFactory::createStatement(CSql); + AbsSqlStatement *adStmt = SqlFactory::createStatement(CSqlAdapter); + stmt->setConnection(con); + adStmt->setConnection(adCon); + char statement[200]; + int rows = 0; + // insert into table + strcpy(statement,"INSERT INTO soakTable VALUES(1234,?,654323,'LAKSHYA_CSQL');"); + rv = stmt->prepare(statement); + if(rv!=OK) { delete stmt; delete con; return 4; } + rv = adStmt->prepare(statement); + if(rv!=OK) { delete stmt; delete con; return 4; } + int rnd = 0; + int i = 0; + while (1) { + if (rv == OK) { + timeout.tv_sec = 0; + timeout.tv_usec = TS; + os::select(0, 0, 0, 0, &timeout); + srand(time(0)); + } + /*if (i == 0) rnd = rand() % 16645635; + else if (i == 1) rnd = (rand() / 3) % 16645635; + else if (i == 2) rnd = (rand() / 7) % 16645635; + else if (i == 3) rnd = (rand() / 11) % 16645635; + else if (i == 4) { i = 0; rnd = (rand() / 13) % 16645635; } + */ + i++; + rv = con->beginTrans(); + if (rv != OK) continue; + //stmt->setIntParam(1, rnd); + stmt->setIntParam(1, i); + rv = stmt->execute(rows); + if (rv == ErrUnique) { + printf("Unique Key Violation Error\n"); + con->rollback(); continue; + } else if (rv != OK) { + printError(rv, "Insert failed with ret val %d", rv); + con->rollback(); continue; + } + else con->commit(); + rv = adCon->beginTrans(); + //adStmt->setIntParam(1,rnd); + adStmt->setIntParam(1,i); + rv = adStmt->execute(rows); + if (rv != OK) { + printError(rv, "Adapter:execute failed with rv = %d"); + adCon->rollback(); + continue; + } + else adCon->commit(); + if (i% 10000 == 0) { + os::gettimeofday(&timeStamp); + struct tm *tempTm = os::localtime(&timeStamp.tv_sec); + strftime(msgBuf, 25, "%d/%m/%Y %H:%M:%S", tempTm); + fprintf(fp, "Inserted PK: %8d %s\n", rnd, msgBuf); + fflush(fp); + } + } + fclose(fp); + adStmt->free(); stmt->free(); + adCon->disconnect(); con->disconnect(); + delete adStmt; delete adCon; + delete stmt; delete con; +} diff --git a/test/soakTest/jdbcDelete.java b/test/soakTest/jdbcDelete.java new file mode 100644 index 00000000..619952f3 --- /dev/null +++ b/test/soakTest/jdbcDelete.java @@ -0,0 +1,63 @@ +import java.sql.*; +import java.io.*; +import java.util.Calendar; +import java.text.SimpleDateFormat; + +public class jdbcDelete +{ + public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; + public static final int TS = 1; + + public static String now() { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); + return sdf.format(cal.getTime()); + } + + public static void main(String[] args) + { + try { + if (args.length != 1) { + System.out.println("Usage: java jdbcDelete \n"); + return; + } + Class.forName("csql.jdbc.JdbcSqlDriver"); + Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager"); + Connection adCon = DriverManager.getConnection("jdbc:Adapter", "root", "manager"); + PreparedStatement stmt = null, selStmt= null, delStmt = null, adSelStmt=null, adDelStmt=null; + selStmt = con.prepareStatement("select f2 from soakTable limit 1;"); + delStmt = con.prepareStatement("delete from soakTable where f2 = ?;"); +// adSelStmt = adCon.prepareStatement("select f2 from soakTable limit 1;"); + adDelStmt = adCon.prepareStatement("delete from soakTable where f2 = ?;"); + ResultSet rs = null, adrs = null; int f2var = 0; + FileWriter fstream = new FileWriter(args[0], true); + BufferedWriter out = new BufferedWriter(fstream); + while (true) { + try { + Thread.sleep(jdbcDelete.TS); + rs = selStmt.executeQuery(); + if(rs.next()) { f2var = rs.getInt(1); } + rs.close(); + // adrs = adSelStmt.executeQuery(); + // if(adrs.next()) { f2var = adrs.getInt(1); } + // adrs.close(); + delStmt.setInt(1,f2var); + delStmt.execute(); + con.commit(); + adDelStmt.setInt(1,f2var); + adDelStmt.execute(); + adCon.commit(); + //System.out.println("f2var = "+f2var+" "+jdbcDelete.now()); + out.write("deleted PK: " +f2var + " "+jdbcDelete.now()+"\n"); + out.flush(); + } catch(Exception ex) { + System.out.println("Exception: "+ ex); + System.out.println("jdbcDelete fail f2 = "+f2var+" "+jdbcDelete.now()); + } + } + } catch (Exception e) { + System.out.println("Exception: "+ e); + } + } +} + diff --git a/test/soakTest/jdbcSelect.java b/test/soakTest/jdbcSelect.java new file mode 100644 index 00000000..37dd3ecf --- /dev/null +++ b/test/soakTest/jdbcSelect.java @@ -0,0 +1,39 @@ +import java.sql.*; +public class jdbcSelect +{ + public static void main(String[] args) + { + try { + Class.forName("csql.jdbc.JdbcSqlDriver"); + Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager"); + PreparedStatement stmt = null, selStmt= null; + selStmt=con.prepareStatement("select * from t1 limit 50 offset 5;"); + ResultSet rs = null; int f1var=0, f2var=0, f3var=0; + float f4var=0; + double f5var=0; + String f6var=""; + + while(true){ + rs=selStmt.executeQuery(); + if(rs.next()){ + f1var=rs.getInt(1); + f2var=rs.getInt(2); + f3var=rs.getInt(3); + f4var=rs.getFloat(4); + f5var=rs.getDouble(5); + f6var=rs.getString(6); + } + System.out.println("Selected value: " +f1var +" " +f2var +" " +f3var +" " +f4var +" " +f5var +" " +f6var); + con.commit(); + Thread.sleep(5000); + } + } + catch (Exception e) { + System.out.println("Exception: "+ e); + } + } +} + + + + diff --git a/test/soakTest/jdbcSelect1.java b/test/soakTest/jdbcSelect1.java new file mode 100644 index 00000000..20e610b1 --- /dev/null +++ b/test/soakTest/jdbcSelect1.java @@ -0,0 +1,66 @@ +import java.sql.*; +import java.io.*; +import java.util.Calendar; +import java.text.SimpleDateFormat; + +public class jdbcSelect1 +{ + public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; + + public static String now() { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); + return sdf.format(cal.getTime()); + } + + public static void main(String[] args) + { + try { + if (args.length != 1) { + System.out.println("Usage: java jdbcSelect1 \n"); + return; + } + + Class.forName("csql.jdbc.JdbcSqlDriver"); + Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager"); + Connection adCon = DriverManager.getConnection("jdbc:Adapter", "root", "manager"); + PreparedStatement stmt = null, selStmt= null; + PreparedStatement adStmt = null, adSelStmt= null; + selStmt=con.prepareStatement("select count(f1) from soakTable;"); + adSelStmt=adCon.prepareStatement("select count(f1) from soakTable;"); + ResultSet rs = null, adrs =null; int f1var=0, f2var=0, f3var=0; + FileWriter fstream = new FileWriter(args[0], true); + BufferedWriter out = new BufferedWriter(fstream); + + while(true){ + try { + rs= selStmt.executeQuery(); + if(rs.next()){ + f1var=rs.getInt(1); + } + rs.close(); + adrs=adSelStmt.executeQuery(); + if(adrs.next()){ + f2var=adrs.getInt(1); + } + adrs.close(); + con.commit(); + adCon.commit(); + out.write("Total Records in CSQL: " +f1var+" "+jdbcDelete.now()+"\n"); + out.write("Total Records in DRDB: " +f2var+" "+jdbcDelete.now()+"\n"); + out.flush(); + Thread.sleep(60000); + } catch(Exception ex) { + System.out.println("Exception: "+ ex); + System.out.println("jdbcSelect1 failed at "+jdbcDelete.now()); + } + } + } catch (Exception e) { + System.out.println("Exception: "+ e); + } + } +} + + + + diff --git a/test/soakTest/jdbcUpdate.java b/test/soakTest/jdbcUpdate.java new file mode 100644 index 00000000..5d651df0 --- /dev/null +++ b/test/soakTest/jdbcUpdate.java @@ -0,0 +1,73 @@ +import java.sql.*; +import java.io.*; +import java.util.Calendar; +import java.text.SimpleDateFormat; + +public class jdbcUpdate +{ + public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; + + public static String now() { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); + return sdf.format(cal.getTime()); + } + + + public static void main(String[] args) + { + + try{ + if (args.length != 1) { + System.out.println("Usage: java jdbcDelete \n"); + return; + } + + Class.forName("csql.jdbc.JdbcSqlDriver"); + Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager"); + Connection adCon = DriverManager.getConnection("jdbc:Adapter", "root", "manager"); + + PreparedStatement selStmt = null, updStmt = null; + PreparedStatement adSelStmt = null, adUpdStmt = null; + + selStmt = con.prepareStatement("select f2 from soakTable limit 1 offset 50;"); + updStmt = con.prepareStatement("update soakTable set f1=? where f2=?;"); +// adSelStmt = adCon.prepareStatement("select f2 from soakTable limit 1 offset 50;"); + adUpdStmt = adCon.prepareStatement("update soakTable set f1=? where f2=?;"); + ResultSet rs = null, adrs=null; int f1var=111, f2var=0, adf2var=0; + FileWriter fstream = new FileWriter(args[0], true); + BufferedWriter out = new BufferedWriter(fstream); + + while(true){ + try { + rs = selStmt.executeQuery(); + if(rs.next()) f2var=rs.getInt(1); + rs.close(); +// adrs = adSelStmt.executeQuery(); + // if(adrs.next()) adf2var=adrs.getInt(1); + // adrs.close(); + updStmt.setInt(1,f1var); + updStmt.setInt(2,adf2var); + updStmt.executeUpdate(); + con.commit(); + adUpdStmt.setInt(1,f1var); + adUpdStmt.setInt(2,adf2var); + adUpdStmt.executeUpdate(); + // System.out.println("Updated value: " +f1var); + adCon.commit(); + out.write("Updated PK: " + adf2var + " "+jdbcDelete.now()+"\n"); + out.flush(); + Thread.sleep(5000); + + } catch (Exception ex) { + System.out.println("Exception: "+ ex); + System.out.println("jdbcUpdate fail f2 = "+f2var+" "+jdbcDelete.now()); + } + } + } + catch (Exception e) { + System.out.println("Exception: "+ e); + } + } +} + diff --git a/test/soakTest/odbcInsert.c b/test/soakTest/odbcInsert.c new file mode 100644 index 00000000..c7568f6e --- /dev/null +++ b/test/soakTest/odbcInsert.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#define TS 1000 + +int main(int argc, char **argv) +{ + SQLHENV env; + SQLHDBC dbc; + SQLHSTMT stmt; + SQLRETURN ret; + SQLCHAR outstr[1024]; + SQLSMALLINT outstrlen; + + SQLHDBC adDbc; + SQLHSTMT adStmt; + + struct timeval timeout; + struct timeval timeStamp; + char msgBuf[25]; + + if (argv[1] == NULL) { + fprintf(stderr, "Usage: csqlInsert \n"); + return 1; + } + + FILE *fp = fopen(argv[1], "a"); + + // Aloocate an environment handle + ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env); + + //we need odbc3 support + SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0); + + //ALLOCATE A Connection handle + ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc); + ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&adDbc); + + // connect to the DSN mydsn + ret = SQLConnect (dbc, + (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"), + (SQLCHAR *) "root", + (SQLSMALLINT) strlen ("root"), + (SQLCHAR *) "manager", + (SQLSMALLINT) strlen ("")); + + if(SQL_SUCCEEDED(ret)) printf("\nConnected to the csql Data Source..\n"); + else + { + printf("error in conenction\n"); + ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc); + ret = SQLFreeHandle(SQL_HANDLE_ENV,env); + return 1; + } + ret = SQLConnect (adDbc, + (SQLCHAR *) "DSN=mycsql;MODE=ADAPTER;SERVER=localhost;PORT=5678;", (SQLSMALLINT) strlen ("test"), + (SQLCHAR *) "root", + (SQLSMALLINT) strlen ("root"), + (SQLCHAR *) "manager", + (SQLSMALLINT) strlen ("")); + + if(SQL_SUCCEEDED(ret)) printf("\nConnected to the msql Data Source..\n"); + else + { + printf("error in conenction\n"); + ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc); + ret = SQLFreeHandle(SQL_HANDLE_ENV,env); + return 1; + } + + ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt); + ret = SQLAllocHandle(SQL_HANDLE_STMT,adDbc,&adStmt); + int rnd = 0; + ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO soakTable VALUES(1234,?,93333993,'CSQL_LAKSHYA');",SQL_NTS); + ret = SQLPrepare(adStmt,(unsigned char*)"INSERT INTO soakTable VALUES(1234,?,93333993,'CSQL_LAKSHYA');",SQL_NTS); + ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&rnd,0,NULL); + ret = SQLBindParameter(adStmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&rnd,0,NULL); + int i = 0; + while (1) { + if (ret == 0) { + timeout.tv_sec = 0; + timeout.tv_usec = TS; + os::select(0, 0, 0, 0, &timeout); + } + srand(time(0)); + if (i == 0) rnd = rand() % 16645635; + else if (i == 1) rnd = (rand() / 17) % 16645635; + else if (i == 2) rnd = (rand() / 19) % 16645635; + else if (i == 3) rnd = (rand() / 23) % 16645635; + else if (i == 4) { i = 0; rnd = (rand() / 29) % 16645635; } + i++; + ret = SQLExecute(stmt); + if (ret == SQL_ERROR) SQLTransact(env, dbc, SQL_ROLLBACK); + else ret = SQLTransact(env,dbc,SQL_COMMIT); + ret = SQLExecute(adStmt); + if (ret == SQL_ERROR) SQLTransact(env, adDbc, SQL_ROLLBACK); + else ret = SQLTransact(env,adDbc,SQL_COMMIT); + os::gettimeofday(&timeStamp); + struct tm *tempTm = os::localtime(&timeStamp.tv_sec); + strftime(msgBuf, 25, "%d/%m/%Y %H:%M:%S", tempTm); + fprintf(fp, "Inserted PK: %8d %s\n", rnd, msgBuf); + fflush(fp); + } + ret = SQLFreeHandle(SQL_HANDLE_STMT,stmt); + ret = SQLDisconnect(dbc); + ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc); + ret = SQLFreeHandle(SQL_HANDLE_ENV,env); + return 0; +} diff --git a/test/soakTest/schema.sql b/test/soakTest/schema.sql new file mode 100644 index 00000000..227e8565 --- /dev/null +++ b/test/soakTest/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE soakTable (f1 SMALLINT , f2 INT NOT NULL , f3 BIGINT , f4 CHAR (28)); +CREATE INDEX indx on soakTable ( f2 ) TREE UNIQUE ; +SET AUTOCOMMIT OFF; diff --git a/test/soakTest/setupenv.ksh b/test/soakTest/setupenv.ksh new file mode 100644 index 00000000..a73da167 --- /dev/null +++ b/test/soakTest/setupenv.ksh @@ -0,0 +1,5 @@ +export CSQL_CONFIG_FILE=`pwd`/csql.conf +export CSQL_INSTALL_ROOT=$CSQL_SRCROOT/install +export PATH=$CSQL_INSTALL_ROOT/bin:$PATH +export LD_LIBRARY_PATH=$CSQL_INSTALL_ROOT/lib:/usr/local/lib:$LD_LIBRARY_PATH +export CLASSPATH=$CSQL_INSTALL_ROOT/lib/CSqlJdbcDriver.jar:.:$CLASSPATH diff --git a/test/soakTest/start.ksh b/test/soakTest/start.ksh new file mode 100755 index 00000000..ca6aaaff --- /dev/null +++ b/test/soakTest/start.ksh @@ -0,0 +1,3 @@ +nohup ./csqlInsert ./csql.out >/dev/null 2>/dev/null & +#nohup ./odbcInsert ./odbc.out >/dev/null 2>/dev/null & +nohup java jdbcDelete ./jdbc.out >/dev/null 2>/dev/null & -- 2.11.4.GIT