Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/test/JD/JDDataAreaLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public JDDataAreaLock(Statement s, String library, String dataArea) throws SQLEx

public void lock(String comment, int waitTime) throws SQLException {



String sql="CALL QSYS2.QCMDEXC(' CRTDTAARA DTAARA("+library_+"/"+dataArea_+") TYPE(*CHAR) LEN(2000)')";
try {
s_.execute(sql);
Expand All @@ -68,8 +66,13 @@ public void lock(String comment, int waitTime) throws SQLException {
}
// Lock exclusive on the system and delay one second
try {
sql="CALL SYSTOOLS.LPRINTF('ALLOCATING ("+library_+"/"+dataArea_+" *DTAARA *EXCLRD)')";
s_.execute(sql);
sql="CALL QSYS2.QCMDEXC(' ALCOBJ OBJ(("+library_+"/"+dataArea_+" *DTAARA *EXCLRD)) WAIT("+waitTime+") ')";
s_.execute(sql);
sql="CALL SYSTOOLS.LPRINTF('ALLOCATED ("+library_+"/"+dataArea_+" *DTAARA *EXCLRD)')";
s_.execute(sql);

// Look at the data area to make sure it isn't already locked
sql="select JOB_NAME, TRIM(INTERPRET(REPLACE(BINARY(DATA_AREA_VALUE),BX'00',BX'40') AS CHAR(2000) CCSID 37)) "
+ "from qsys2.data_area_info where DATA_AREA_LIBRARY='" + library_
Expand Down Expand Up @@ -145,6 +148,9 @@ public void unlock(String comment, Timestamp ts) throws SQLException {

String sql="NOTSET";
try {
sql="CALL SYSTOOLS.LPRINTF('UNLOCKING ("+library_+"/"+dataArea_+" *DTAARA *EXCLRD)')";
s_.execute(sql);

if (ts == null)
ts = new Timestamp(System.currentTimeMillis());
String callerString = getCallString();
Expand All @@ -155,6 +161,7 @@ public void unlock(String comment, Timestamp ts) throws SQLException {
sql = "CALL QSYS2.QCMDEXC(' DLCOBJ OBJ((" + library_ + "/" + dataArea_
+ " *DTAARA *EXCLRD)) ')";
s_.execute(sql);
sql="CALL SYSTOOLS.LPRINTF('UNLOCKED ("+library_+"/"+dataArea_+" *DTAARA *EXCLRD)')";

} catch (SQLException e) {
System.out.println("Error on " + sql);
Expand Down
52 changes: 30 additions & 22 deletions src/test/JDJSTPTestcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class JDJSTPTestcase
private static String HCLIConnect_ = null;
private static String ZCLIConnect_ = null;
private static String LCLIConnect_ = null;
@SuppressWarnings("resource")
static FileSystem fsDefault = FileSystems.getDefault();

public static String getGCLIConnect() {
if (GCLIConnect_ == null) {
Expand Down Expand Up @@ -2649,7 +2651,7 @@ public static void refreshLocalFile(String localFile) throws Exception {
// Determine if the local file needs to be extracted from the classpath
//
// Get the URL of the resource inside the JAR file
URL url = JDJSTPTestcase.class.getResource(localFile);
URL url = JDJSTPTestcase.class.getResource("/"+localFile);
File file = new File(localFile);
long currentTime = file.lastModified();
long lastJarModifiedMs = 0;
Expand All @@ -2658,9 +2660,10 @@ public static void refreshLocalFile(String localFile) throws Exception {
if (url.getProtocol().equals("jar")) {
URLConnection connection = url.openConnection();
lastJarModifiedMs = connection.getLastModified();
if (debug) System.out.println("Resource "+localFile+" found in jar.");
}
} else {
System.out.println("Resource not found.");
if (debug) System.out.println("Resource "+localFile+" not found in jar.");
}
if (lastJarModifiedMs > currentTime) {
int lastSlashIndex = localFile.lastIndexOf('/');
Expand All @@ -2673,9 +2676,7 @@ public static void refreshLocalFile(String localFile) throws Exception {
}

InputStream is = url.openStream();
FileSystem fsDefault = FileSystems.getDefault();
Files.copy(is, fsDefault.getPath(localFile), StandardCopyOption.REPLACE_EXISTING);
fsDefault.close();
is.close();
currentTime = file.lastModified();
}
Expand All @@ -2698,7 +2699,7 @@ public static boolean updateServerFile(String localFile, String serverPf, String
// Determine if the local file needs to be extracted from the classpath
//
// Get the URL of the resource inside the JAR file
URL url = JDJSTPTestcase.class.getResource(localFile);
URL url = JDJSTPTestcase.class.getResource("/"+localFile);
File file = new File(localFile);
long currentTime = file.lastModified();
long lastJarModifiedMs = 0;
Expand All @@ -2707,9 +2708,10 @@ public static boolean updateServerFile(String localFile, String serverPf, String
if (url.getProtocol().equals("jar")) {
URLConnection connection = url.openConnection();
lastJarModifiedMs = connection.getLastModified();
if (debug) System.out.println("Resource "+localFile+" copied from jar file.");
}
} else {
System.out.println("Resource not found.");
if (debug) System.out.println("Resource "+localFile+" not found.");
}
if (lastJarModifiedMs > currentTime) {
int lastSlashIndex = localFile.lastIndexOf('/');
Expand Down Expand Up @@ -5321,21 +5323,30 @@ public static String getJdkString(int jdk, int vrm1) throws Exception {
throw new Exception("Unrecognized jdk"+jdk);
}
}


public static boolean resourceExists(String filename) {
File checkFile = new File(filename);
if (checkFile.exists()) {
return true;
}
URL url = JDJSTPTestcase.class.getResource("/"+filename);
if (url != null) return true;
return false;
}

public static String getExpectedOutputFile(
String testbase,
String inVariation,
StringBuffer possibleOutputFiles) throws Exception {


String expectedOutput;
File checkFile;
String variationString="."+inVariation;
if (inVariation.length() == 0) variationString = "";

expectedOutput = exppath + "/" + testbase + variationString + ".rxp" + vrm
+ ".jdkXX";
checkFile = new File(expectedOutput);
if (!checkFile.exists()) {

if (!resourceExists(expectedOutput)) {
possibleOutputFiles.append(" " + expectedOutput);
}

Expand All @@ -5345,13 +5356,13 @@ public static String getExpectedOutputFile(
int currentJdk = JVMInfo.getJDK();


for (int i = 0; i < vrms.length && !checkFile.exists(); i++) {
for (int i = 0; i < vrms.length && !resourceExists(expectedOutput); i++) {
if (vrm >= vrms[i]) { /* current vrm greater than loop vrm */
String vrmString = ""+vrms[i];
if (vrms[i] == 0) {
vrmString="";
}
for (int j = 0; j < jdks.length && !checkFile.exists(); j++) {
for (int j = 0; j < jdks.length && !resourceExists(expectedOutput); j++) {
if (currentJdk >= jdks[j]) {
String jdkString = getJdkString(jdks[j], vrms[i]); /*
* return .jdk
Expand All @@ -5361,26 +5372,23 @@ public static String getExpectedOutputFile(
// check for J9
expectedOutput = exppath + "/" + testbase + variationString
+ ".rxp" + vrmString + jdkString + ".j9";
checkFile = new File(expectedOutput);
if (!checkFile.exists()) {
if (!resourceExists(expectedOutput)) {
possibleOutputFiles.append(" " + expectedOutput);
}
if (!checkFile.exists()) {
if (!resourceExists(expectedOutput)) {
if (isToolbox) {
// check for toolbox
expectedOutput = exppath + "/" + testbase + variationString
+ ".rxpt" + vrmString + jdkString;
checkFile = new File(expectedOutput);
if (!checkFile.exists()) {
if (resourceExists(expectedOutput)) {
possibleOutputFiles.append(" " + expectedOutput);
}
}
if (!checkFile.exists()) {
if (!resourceExists(expectedOutput)) {

expectedOutput = exppath + "/" + testbase + variationString
+ ".rxp" + vrmString + jdkString;
checkFile = new File(expectedOutput);
if (!checkFile.exists()) {
if (!resourceExists(expectedOutput)) {
/* Do not list old releases as possible output files */
if (vrmString.equals("610") || vrmString.equals("550")
|| vrmString.equals("540")
Expand All @@ -5401,7 +5409,7 @@ public static String getExpectedOutputFile(
} /* current vrm not less than loop vrm */
} /* for i -- vrms */

if (!checkFile.exists()) {
if (!resourceExists(expectedOutput)) {
System.out.println("Did not find file: Tried :"+possibleOutputFiles.toString());
}
return expectedOutput;
Expand Down
51 changes: 24 additions & 27 deletions src/test/JDRunit.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public class JDRunit {
public static String JCIFS_JAR="jcifs-3.0.2.jar";

public static final String TMP = "/tmp";
public static String testcaseCode = JTOpenTestEnvironment.testcaseHomeDirectory;

public static String testcaseHome = JTOpenTestEnvironment.testcaseHomeDirectory;
public static String testcaseClasspath = testcaseHome+":"+testcaseHome+"/JTOpen-test.jar";
static Hashtable<String, String> rdbToCreatedUserid = new Hashtable<String, String>();
static Hashtable<String, String> rdbToCreatedPassword = new Hashtable<String, String>();
static boolean debug = false;
Expand Down Expand Up @@ -216,10 +216,6 @@ public class JDRunit {
on400open = JTOpenTestEnvironment.isOS400open;
onLinux = JTOpenTestEnvironment.isLinux;

property = System.getProperty("useTestJar");
if (property != null && (property.toUpperCase().indexOf('N')< 0)) {
testcaseCode = "JTOpen-test.jar";
}
}

//
Expand Down Expand Up @@ -976,7 +972,7 @@ public static void sendEMail(String toAddress, String fromAddress,
String[] activationJarLocations = {
userDir + sep + "jars" + sep + "activation.jar",
"C:" + sep + "activation.jar",
testcaseCode+"/jars/activation.jar",
testcaseHome+"/jars/activation.jar",
"/qibm/proddata/os400/java400/ext/activation.jar",
"C:\\Documents and Settings\\Administrator\\workspace\\lib\\activation.jar", };

Expand All @@ -1002,7 +998,7 @@ public static void sendEMail(String toAddress, String fromAddress,
String[] mailJarLocations = {
userDir + sep + "jars" + sep + "mail.jar",
"C:" + sep + "mail.jar",
testcaseCode+"/jars/mail.jar",
testcaseHome+"/jars/mail.jar",
"/qibm/proddata/os400/java400/ext/mail.jar",
"C:\\Documents and Settings\\Administrator\\workspace\\lib\\mail.jar", };
for (int i = 0; i < mailJarLocations.length && urls[1] == null; i++) {
Expand Down Expand Up @@ -2128,13 +2124,13 @@ public void readIni(StringBuffer iniInfo) throws Exception {

if (useJaCoCo) {
if (toolboxJar.indexOf("java6") > 0) {
toolboxJar = testcaseCode+"/jacoco/java6/jt400.jar";
toolboxJar = testcaseHome+"/jacoco/java6/jt400.jar";
} else if (toolboxJar.indexOf("java8") > 0) {
toolboxJar = testcaseCode+"/jacoco/java8/jt400.jar";
toolboxJar = testcaseHome+"/jacoco/java8/jt400.jar";
} else if (toolboxJar.indexOf("java9") > 0) {
toolboxJar = testcaseCode+"/jacoco/java9/jt400.jar";
toolboxJar = testcaseHome+"/jacoco/java9/jt400.jar";
} else {
toolboxJar = testcaseCode+"/jacoco/java0/jt400.jar";
toolboxJar = testcaseHome+"/jacoco/java0/jt400.jar";
}
}

Expand Down Expand Up @@ -2270,7 +2266,8 @@ public JDRunitGoOutput go() throws Exception {

if (JTOpenTestEnvironment.isWindows && (vmInitials.endsWith("3") || vmInitials.endsWith("6"))) {
runNativeTestFromWindows = true;
testcaseCode="/home/jdbctest";
testcaseHome="/home/jdbctest";
testcaseClasspath="/home/jdbctest";
}


Expand All @@ -2280,8 +2277,8 @@ public JDRunitGoOutput go() throws Exception {
inputVector.addElement("echo input is " + runitInputFile);
inputVector.addElement("echo output is " + runitOutputFile);
inputVector.addElement(iniInfo.toString());
inputVector.addElement("echo cd "+testcaseCode);
inputVector.addElement("cd "+testcaseCode);
inputVector.addElement("echo cd "+testcaseHome);
inputVector.addElement("cd "+testcaseHome);

String javaExecPath = javaHome;
//
Expand Down Expand Up @@ -2326,18 +2323,18 @@ public JDRunitGoOutput go() throws Exception {

String newTestJar = iniProperties.getProperty("testJar");
if (newTestJar != null) {
testcaseCode = newTestJar;
testcaseClasspath = newTestJar;
}

/* Use JTOpen-test.jar if exists in the classpath. */
/* Assume that the JTOpen-test.jar is in the current directory */
String currentClassPath=System.getProperty("java.class.path");
if (currentClassPath.indexOf("JTOpen-test.jar") >= 0) {
testcaseCode = "JTOpen-test.jar";
testcaseClasspath = "JTOpen-test.jar";
}


String setClasspath = "CLASSPATH="+toolboxJar+":"+testcaseCode+":"
String setClasspath = "CLASSPATH="+toolboxJar+":"+testcaseClasspath+":"
+ ":/qibm/proddata/java400/ext/translator.zip:"
+ toolsJar
+ ":jars/googleauth-1.5.0.jar:jars/commons-codec-1.16.0.jar"
Expand Down Expand Up @@ -2439,12 +2436,12 @@ public JDRunitGoOutput go() throws Exception {
String currentClasspath = System.getProperty("java.class.path");


if (testcaseCode.indexOf(".jar") < 0) {
testcaseCode=System.getProperty("user.dir");
if (testcaseClasspath.indexOf(".jar") < 0) {
testcaseClasspath=System.getProperty("user.dir");
} else {
testcaseCode=System.getProperty("user.dir") +File.separator+testcaseCode;
testcaseClasspath=System.getProperty("user.dir") +File.separator+testcaseClasspath;
}
setClasspath = "CLASSPATH=\"" + toolboxJar + ";" + testcaseCode+ ";"
setClasspath = "CLASSPATH=\"" + toolboxJar + ";" + testcaseClasspath+ ";"
+ currentClasspath+";"
+ toolsJar + ";" +
System.getProperty("user.dir") + ""+File.separator+"jars"+File.separator+"db2_classes.jar;" +
Expand Down Expand Up @@ -2475,7 +2472,7 @@ public JDRunitGoOutput go() throws Exception {
}


setClasspath = "CLASSPATH=\""+testcaseCode+":" + toolboxJar + ":"
setClasspath = "CLASSPATH=\""+testcaseClasspath+":" + toolboxJar + ":"
+ toolsJar + ":"
+ System.getProperty("user.dir") + "/jars/fscontext.jar:"
+ System.getProperty("user.dir") + "/jars/providerutil.jar:"
Expand Down Expand Up @@ -2742,11 +2739,11 @@ public JDRunitGoOutput go() throws Exception {
+ savefileName + " -Dtest.parentJob=" + parentJob + " " + javaArgs;

if (useJaCoCo) {
File destDir = new File(testcaseCode+"/jacoco/"+initials);
File destDir = new File(testcaseHome+"/jacoco/"+initials);
if (!destDir.exists()) {
destDir.mkdir();
}
javaArgs = "-javaagent:"+testcaseCode+"/jacoco/lib/jacocoagent.jar=destfile="+testcaseCode+"/jacoco/"+initials+"/"+test+".exec,includes=com.ibm.as400.access.* " + javaArgs;
javaArgs = "-javaagent:"+testcaseHome+"/jacoco/lib/jacocoagent.jar=destfile="+testcaseHome+"/jacoco/"+initials+"/"+test+".exec,includes=com.ibm.as400.access.* " + javaArgs;
}

String javaCommand = "java " + javaArgs + " " + testArgs + " -lib "
Expand Down Expand Up @@ -2967,7 +2964,7 @@ public JDRunitGoOutput go() throws Exception {
// any environment variables.
// This scenario should only typically happened on V6R1
if ((System.getProperty("java.home").indexOf("QOpenSys") > 0) && (javaHome.indexOf("QOpenSys") == -1)) {
String[] envp = { "PATH=/usr/bin:", "HOME=" + testcaseCode, };
String[] envp = { "PATH=/usr/bin:", "HOME=" + testcaseHome, };
if (debug)
System.out.println("Calling exec1 with envp and cmdArray[0]=" + cmdArray1[0]);
shellTestProcess = runtime.exec(cmdArray1, envp);
Expand Down Expand Up @@ -4288,7 +4285,7 @@ static void startProxyServer(String jt400jar) {
try {


String command = "java -classpath "+testcaseCode+":"+jt400jar+" com.ibm.as400.access.ProxyServer";
String command = "java -classpath "+testcaseClasspath+":"+jt400jar+" com.ibm.as400.access.ProxyServer";
System.out.println("JDRunit: starting ProxyServer on default port using: "+command);
// Need to include testcaseCode because the source for the serialized
// lobs is located there.
Expand Down
Loading