Skip to content

Commit

Permalink
JDAS Test updates (#115)
Browse files Browse the repository at this point in the history
* Testcase updates

Signed-off-by: John Eberhard <[email protected]>

* Testcase cleanup

Signed-off-by: John Eberhard <[email protected]>

* More test cleanup

Signed-off-by: John Eberhard <[email protected]>

* Fixes for testcase updates

Signed-off-by: John Eberhard <[email protected]>

* JDASTestcase updates

Signed-off-by: John Eberhard <[email protected]>

* Use JTOpen 20.0.8 as base

---------

Signed-off-by: John Eberhard <[email protected]>
  • Loading branch information
jeber-ibm authored Dec 20, 2024
1 parent a53d39f commit 66d3990
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400</artifactId>
<version>20.0.7</version>
<version>20.0.8</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
124 changes: 97 additions & 27 deletions src/test/JD/AS/JDASTestcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public class JDASTestcase extends JDTestcase {

protected String url_;

public int killCount;

private boolean seamless_;

protected static String[] setupSql = {
"create or replace variable COLLECTION.GVCALTCINT INT",
"create or replace table COLLECTION.GVCALTCT1(C1 INT,C2 BIGINT)",
Expand Down Expand Up @@ -2644,6 +2648,7 @@ public void testDSPSTypeParameters(String[][] psTypeTransactions,
}

public Connection createDSConnectionFromURL(String url) throws Exception {

Hashtable h = getPropertiesFromUrl(url);
String system = (String) h.get("system");

Expand All @@ -2669,7 +2674,11 @@ public Connection createDSConnectionFromURL(String url) throws Exception {
} else {
throw new Exception("Unable to processing URL property : "+property+"="+value);
}

if (url.indexOf("Seamless") > 0) {
seamless_ = false;
} else {
seamless_ = true;
}
}


Expand Down Expand Up @@ -2747,20 +2756,21 @@ public void testPSTypeParameters(String[][] psTypeTransactions,
KillThread killThread, int runSeconds, StringBuffer sb) {

Random random = new Random(1);
int killCount = 0;
killCount = 0;
int killTime = MINIMUM_TRANSACTION_MILLISECONDS;
int minimumTransactionMilliseconds = MINIMUM_TRANSACTION_MILLISECONDS;
boolean passed = true;
infoAppend(sb, "testPSTypeParmeters");;
infoAppend(sb,"Test a connection with enableClientAffinitiesList\n");
infoAppend(sb,"Make sure the connection is re-established after it drops\n");
infoAppend(sb,"It will be dropped randomly\n");
infoAppend(sb,"This test uses prepared statements with type parameter markers\n");

infoAppend(sb,"killThread is "+killThread+"\n");
try {

if (checkToolboxFixDate(TOOLBOX_FIX_DATE)) {
PreparedStatement[][] psTransactions = new PreparedStatement[psTypeTransactions.length][];
for (int i = 0; i < psTypeTransactions.length; i++) {
for (int i = 0; i < psTypeTransactions.length; i++) {
String[] sqlInTransaction = psTypeTransactions[i];
PreparedStatement[] psInTransaction = new PreparedStatement[sqlInTransaction.length];
psTransactions[i] = psInTransaction;
Expand All @@ -2783,11 +2793,12 @@ public void testPSTypeParameters(String[][] psTypeTransactions,
}
long endMillis = System.currentTimeMillis() + runSeconds * 1000;
killThread.start();
killThread.waitUntilReady();
int transactionCount = 0;
int transactionsAttempted = 0;
while ( (killCount == 0 && passed) ||
(System.currentTimeMillis() < endMillis && passed
&& (transactionCount < RUN_TRANSACTIONS))){
int serverLocalPort = 0;
while (System.currentTimeMillis() < endMillis && passed
&& (transactionCount < RUN_TRANSACTIONS)) {
boolean retry = true;
int t = random.nextInt(psTransactions.length);
while (retry && (System.currentTimeMillis() < endMillis && passed)) {
Expand All @@ -2796,6 +2807,15 @@ public void testPSTypeParameters(String[][] psTypeTransactions,

synchronized (sb) {
infoAppend(sb,"TC=" + transactionCount + " T=" + t + "\n");
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("select REMOTE_PORT from qsys2.netstat_job_info a where a.JOB_NAME=qsys2.JOB_NAME and LOCAL_PORT=8471");
if (rs.next()) {
int currentServerLocalPort = rs.getInt(1);
if (currentServerLocalPort != serverLocalPort) {
serverLocalPort = currentServerLocalPort;
infoAppend(sb, "Server connection is "+serverLocalPort+"/8471\n");
}
}
}
PreparedStatement[] psInT = psTransactions[t];
String[][][] parameterSets = psTypeParms[t];
Expand Down Expand Up @@ -2978,6 +2998,10 @@ public void testPSTypeParameters(String[][] psTypeTransactions,
}
connection.close();
killerConnection.close();
if (killCount == 0 && !seamless_ ) {
sb.append("FAILED because kill count is zero\n");
passed = false;
}
assertCondition(passed, sb);

}
Expand Down Expand Up @@ -3057,9 +3081,10 @@ public void testCSTypeParameters(String[][] csTypeTransactions,
String[][][][] csTypeParms, int javaType, Connection connection, Connection killerConnection,
KillThread killThread, int runSeconds, StringBuffer sb) {
Random random = new Random();
int killCount = 0;
killCount = 0;
int killTime = 0;
boolean passed = true;
infoAppend(sb, "testCSTypeParameters\n");
infoAppend(sb,"Test a connection with enableClientAffinitiesList\n");
infoAppend(sb,"Make sure the connection is re-established after it drops\n");
infoAppend(sb,"It will be dropped randomly\n");
Expand Down Expand Up @@ -3447,34 +3472,51 @@ public SwitchKillThread(Connection c, String killjob,
}

public void run() {

// Make sure a proxy is enabled
int pick = random_.nextInt(proxies_.length);

// See if only one proxy is in use. If so, then use that one.
int pick = -1;
for (int i = 0; i < proxies_.length && pick != -2; i++) {
int count = proxies_[i].getConnectionCount();
if (count > 0) {
if (pick == -1) {
pick = i; /* Chose this if none selected */
} else {
pick = -2; /* -2 indicates we found multiple */
}
}
}
// Randomly pick one if none or many found
if (pick < 0) {
pick = random_.nextInt(proxies_.length);
sb_.append("SwitchKillThread: Chose random proxy\n");
} else {
sb_.append("SwitchKillThread: Using in-use proxy\n");
}

synchronized (sb_) {
sb_.append("Enabling proxy at index " + pick + " \n");
sb_.append("SwitchKillThread: Enabling proxy at index " + pick + " port= " +proxies_[pick].getPortNumber()+"/"+proxies_[pick].getServerLocalPort()+" c="+proxies_[pick].getConnectionCount()+ " \n");
}
proxies_[pick].enable(true);

// Make sure the rest are disabled
for (int i = 0; i < proxies_.length; i++) {
if (i != pick) {
proxies_[i].enable(false);
sb_.append("SwitchKillThread: disabling proxy at index " + i + " port= " +proxies_[i].getPortNumber()+"/"+proxies_[i].getServerLocalPort()+" c="+proxies_[i].getConnectionCount()+ " \n");
}
}

ready_ = true;
while (running_) {
synchronized (sb_) {

sb_.append("SwitchKillThread sleeping for " + sleepMilliseconds_
sb_.append("SwitchKillThread: sleeping for " + sleepMilliseconds_
+ "\n");
}
try {
Thread.sleep(sleepMilliseconds_);
} catch (InterruptedException e) {
}
synchronized (sb_) {
sb_.append("Ending proxy \n");
sb_.append("SwitchKillThread: Ending proxy \n");
}

int newPick = random_.nextInt(proxies_.length);
Expand All @@ -3483,7 +3525,7 @@ public void run() {
newPick = random_.nextInt(proxies_.length);
}
synchronized (sb_) {
sb_.append("Enabling proxy at index " + newPick + " \n");
sb_.append("SwitchKillthread: Enabling proxy at index " + newPick + " port= " +proxies_[newPick].getPortNumber()+"/"+proxies_[newPick].getServerLocalPort()+" c="+proxies_[newPick].getConnectionCount()+ " \n");
}
proxies_[newPick].enable(true);
// Allow time for the proxy to become active
Expand All @@ -3493,7 +3535,7 @@ public void run() {

}
synchronized (sb_) {
sb_.append("Ending proxy at index " + pick + "\n");
sb_.append("SwitchKillthread: Ending proxy at index " + pick + " port= " +proxies_[pick].getPortNumber()+"/"+proxies_[pick].getServerLocalPort()+" c="+proxies_[pick].getConnectionCount()+ "\n");
}

proxies_[pick].enable(false);
Expand All @@ -3504,41 +3546,69 @@ public void run() {
waiting_ = true;

// Now wait for reset before continuing
// sometimes the reset doesn't work. In that case, we keep going.
synchronized (this) {
while (waiting_ && running_) {
long timeoutTime = System.currentTimeMillis() + 10000; /* ten seconds should be long enough */
while (waiting_ && running_ & System.currentTimeMillis() < timeoutTime) {
try {
this.wait(250);
} catch (Exception e) {

}
}
if (waiting_ == true && running_ == true) {
sb_.append("SwitchKillThread: continuing because reset not found within 10 seconds\n");
waiting_ = false;
} else {
sb_.append("SwitchKillThread: loop bottom\n");
}
}

}
synchronized (sb_) {
sb_.append("Switchkill thread done\n");
sb_.append("SwitchKillThread done\n");
}

}

}

class KillThread extends Thread {

private Connection c_;
String killjob_;
int sleepMilliseconds_;
StringBuffer sb_;
boolean running_ = true;
boolean waiting_ = false;

boolean ready_ = false;

public KillThread(Connection c, String killjob, int sleepMilliseconds,
StringBuffer sb) {
c_ = c;
killjob_ = killjob;
sleepMilliseconds_ = sleepMilliseconds;
sb_ = sb;
}

public void waitUntilReady() throws InterruptedException {
infoAppend(sb_, "waiting for KillThread to be ready\n");
boolean ready = false;
synchronized(this) {
ready = ready_;
}
while (!ready) {
sleep(100);
synchronized(this) {
ready = ready_;
}
}

infoAppend(sb_, "waiting for KillThread complete\n");

}
public String toString() {
return(this.getClass().toString()+" sleepMilliseconds_ = "+sleepMilliseconds_+" killjob_ = "+killjob_+"\n");
}
public synchronized void reset(int sleepMilliseconds, String killjob) {
killjob_ = killjob;
sleepMilliseconds_ = sleepMilliseconds;
Expand All @@ -3554,22 +3624,22 @@ public synchronized void shutdown() {

public void run() {
while (running_) {
infoAppend(sb_, "KillThread sleeping for " + sleepMilliseconds_ + "\n");

infoAppend(sb_, "KillThread: sleeping for " + sleepMilliseconds_ + "\n");
ready_ = true;
try {
Thread.sleep(sleepMilliseconds_);
} catch (InterruptedException e) {
}
String sql = "call qsys2.qcmdexc('endjob job(" + killjob_
+ ") option(*immed)')";
infoAppend(sb_,"Killing job using " + sql + "\n");
infoAppend(sb_,"KillThread: Killing job using " + sql + "\n");
try {
Statement s = c_.createStatement();
s.executeUpdate(sql);
s.close();
} catch (SQLException e) {
synchronized (sb_) {
infoAppend(sb_, "Kill thread hit exception\n");
infoAppend(sb_, "KillThread: hit exception\n");
printStackTraceToStringBuffer(e, sb_);
}
}
Expand All @@ -3588,7 +3658,7 @@ public void run() {

}
synchronized (sb_) {
infoAppend(sb_, "Kill thread done\n");
infoAppend(sb_, "KillThread: done\n");
}

}
Expand Down
37 changes: 31 additions & 6 deletions src/test/SocketProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public static SocketProxy getSocketProxy(int startPort, String serverName, int s
InputStream inputStream_;
SocketProxyMasterThread masterThread;
boolean done;
ServerSocket serverSocket_;
ServerSocket serverSocket_;
private boolean masterThreadServiceEnded = false ;


public SocketProxy(PrintStream out, InputStream in, int proxyPort,
String serverName, int serverPort) throws IOException {
Expand Down Expand Up @@ -111,7 +113,7 @@ public SocketProxy(int proxyPort, String serverName, int serverPort) throws IOEx

masterThread =
new SocketProxyMasterThread(serverSocket_, serverName_, serverPort_, printWriter_, this);

}

public void run() {
Expand Down Expand Up @@ -139,7 +141,7 @@ public void run() {
try {
if (masterThread != null) {
masterThread.endService();
masterThread = null;
masterThreadServiceEnded = true;
}
} catch (Throwable t2) {
printWriter_.println("Throwable caught ending masterThread ");
Expand All @@ -153,7 +155,10 @@ public void run() {

public void endService() {
if (masterThread != null) {
masterThread.endService();
if (!masterThreadServiceEnded) {
masterThread.endService();
masterThreadServiceEnded = true;
}
masterThread = null;
}
done = true;
Expand All @@ -172,12 +177,33 @@ public int getPortNumber () {
return proxyPort_;
}

public long getActiveByteCount() {
public int getServerLocalPort() {
if (masterThread != null )
return masterThread.getServerLocalPort();
return -1;
}
public int getConnectionCount() {
if (masterThread != null) {
return masterThread.getConnectionCount();
}
return -1;
}


public long getActiveByteCount() {
if (masterThread != null) {
return masterThread.getActiveByteCount();
} else {
return -1;
}
}

public int getFailedConnectCount() {
if (masterThread != null) {
return masterThread.getFailedConnectCount();
} else {
return -1;
}
}

public void endActiveConnections() {
Expand All @@ -186,7 +212,6 @@ public void endActiveConnections() {

public void enable(boolean b) {
masterThread.enable(b);

}

public void setOutputFailedAttempts(PrintStream stream) {
Expand Down
Loading

0 comments on commit 66d3990

Please sign in to comment.