Attached is a patch which adds more tests and test support for network
client. There is no change to the actual function of the tests but
direct references to the IBM Driver have been taken out of the tests
themselves. With this patch, there are methods in TestUtil which will
perform the desired action based on the framework.
public static void loadDriver() throws Exception
public static String getJdbcUrlPrefix()
public static javax.sql.DataSource getDataSource(Properties attrs)
public static javax.sql.XADataSource getXADatasource(Properties attrs)
public static javax.sql.ConnectionPoolDataSource
getConnectionPoolDataSource(Properties attrs)
This change also adds a new property to RunTest to determine whether the
test will start newtork server.
startServer={true|false}
Defaults to true for DerbyNet and DerbyNetClient. Not relevant for the
embedded framework.
This property is useful for tests which require the framework in order
to load the right driver but start their own server.
If I hear no objections I'll check this in in the morning.
Thanks
Kathey
Index:
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourcePermissions.java
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourcePermissions.java
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourcePermissions.java
(working copy)
@@ -148,7 +148,7 @@
} catch (SQLException sqle) {
System.out.println("EXPECTED CONNFAIL " +
sqle.getMessage());
}
-
+
checkConnection(ds.getConnection("EDWARD", "noodle"));
checkConnection(ds.getConnection("FRANCES", "isabella"));
if (supportsUnicodeNames()) {
Index:
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM_app.properties
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM_app.properties
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM_app.properties
(working copy)
@@ -1,3 +1,4 @@
-#Don't want harness to start up network server. It will be started
-#in test, so we set framework to embedded
-framework=embedded
+#Don't want harness to start up network server.
+#It will be started in test
+startServer=false
+
Index:
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net_app.properties
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net_app.properties
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net_app.properties
(working copy)
@@ -19,9 +19,9 @@
#
#
excludeJCC=1.1
+startServer=false
database=wombat;create=true
derby.optimizer.noTimeout=true
-
ij.defaultResourcePackage=/org/apache/derbyTesting/functionTests/tests/lang/
ij.showNoConnectionsAtStart=true
ij.showNoCountForSelect=true
Index:
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
(working copy)
@@ -45,9 +45,11 @@
import org.apache.derby.tools.JDBCDisplayUtil;
import org.apache.derby.tools.ij;
import org.apache.derby.drda.NetworkServerControl;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
import java.io.*;
import java.net.InetAddress;
import java.util.Hashtable;
+import java.util.Properties;
import javax.naming.*;
import javax.naming.directory.*;
@@ -71,7 +73,7 @@
// start the server on that port before calling runTest.
try {
-
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
+ TestUtil.loadDriver();
} catch (Exception e) {
e.printStackTrace();
}
@@ -119,8 +121,10 @@
public void setProperties() {
// Set required server properties.
- System.setProperty("database", "jdbc:derby:net://localhost:"
- + NETWORKSERVER_PORT + "/wombat;create=true");
+ System.setProperty("database",
+
TestUtil.getJdbcUrlPrefix("localhost",
+
NETWORKSERVER_PORT) +
+ "wombat;create=true");
System.setProperty("ij.user", "EDWARD");
System.setProperty("ij.password", "noodle");
@@ -128,10 +132,11 @@
public String getJDBCUrl(String db, String attrs) {
- String s = "jdbc:derby:net://localhost:" + NETWORKSERVER_PORT +
"/" + db;
+ String s = TestUtil.getJdbcUrlPrefix("localhost",
NETWORKSERVER_PORT)
+ + db;
if (attrs != null)
s = s + ":" + attrs + ";";
-
+ //System.out.println("getJDBCUrl:" + s);
return s;
}
@@ -139,65 +144,36 @@
public javax.sql.DataSource getDS(String database, String user, String
password)
{
- return (javax.sql.DataSource)
getDataSourceWithReflection("com.ibm.db2.jcc.DB2SimpleDataSource",
-
database,user,password);
-
+ Properties attrs = new Properties();
+ attrs.setProperty("databaseName", database);
+ if (user != null)
+ attrs.setProperty("user", user);
+ if (password != null)
+ attrs.setProperty("password", password);
+ attrs = addRequiredAttributes(attrs);
+ return TestUtil.getDataSource(attrs);
}
+
- public Object getDataSourceWithReflection(String classname, String
database,
-
String user, String password)
- {
- Class[] STRING_ARG_TYPE = {String.class};
- Class[] INT_ARG_TYPE = {Integer.TYPE};
- Object[] args = null;
- Object ds = null;
- Method sh = null;
- try {
- ds = Class.forName(classname).newInstance();
-
- // Need to use reflection to load indirectly
- // setDatabaseName
- sh = ds.getClass().getMethod("setDatabaseName",
STRING_ARG_TYPE);
- args = new String[] {database};
- sh.invoke(ds, args);
- if (user != null) {
- // setUser
- sh = ds.getClass().getMethod("setUser",
STRING_ARG_TYPE);
- args = new String[] {user};
- sh.invoke(ds, args);
- // setPassword
- sh = ds.getClass().getMethod("setPassword",
STRING_ARG_TYPE);
- args = new String[] {password};
- sh.invoke(ds, args);
- }
-
- // setServerName
- sh = ds.getClass().getMethod("setServerName",
STRING_ARG_TYPE);
- args = new String[] {"localhost"};
- sh.invoke(ds, args);
- //setPortNumber
- sh = ds.getClass().getMethod("setPortNumber",
INT_ARG_TYPE);
- args = new Integer[] {new Integer(NETWORKSERVER_PORT)};
- sh.invoke(ds, args);
-
- //setDriverType
- sh = ds.getClass().getMethod("setDriverType",
INT_ARG_TYPE);
- args = new Integer[] {new Integer(4)};
- sh.invoke(ds, args);
-
- } catch (Exception e)
- {
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
- return ds;
+ public javax.sql.ConnectionPoolDataSource getCPDS(String database,
String user, String password) {
+ Properties attrs = new Properties();
+ attrs.setProperty("databaseName", database);
+ if (user != null)
+ attrs.setProperty("user", user);
+ if (password != null)
+ attrs.setProperty("password", password);
+ attrs = addRequiredAttributes(attrs);
+ return TestUtil.getConnectionPoolDataSource(attrs);
}
- public javax.sql.ConnectionPoolDataSource getCPDS(String database,
String user, String password) {
-
- return (javax.sql.ConnectionPoolDataSource)
getDataSourceWithReflection("com.ibm.db2.jcc.DB2ConnectionPoolDataSource",database,user,password);
-
+ private Properties addRequiredAttributes(Properties attrs)
+ {
+ attrs.setProperty("driverType","4");
+ attrs.setProperty("serverName","localhost");
+ attrs.setProperty("portNumber","20000");
+
//attrs.setProperty("retrieveMessagesFromServerOnGetMessage","true");
+ return attrs;
}
public boolean supportsUnicodeNames() {
@@ -217,8 +193,9 @@
public void shutdown() {
try {
-
DriverManager.getConnection("jdbc:derby:net://localhost:" +
- NETWORKSERVER_PORT + "/wombat;shutdown=true",
+
DriverManager.getConnection(TestUtil.getJdbcUrlPrefix("localhost",
+
NETWORKSERVER_PORT) +
+
"wombat;shutdown=true",
"EDWARD", "noodle");
System.out.println("FAIL - Shutdown returned
connection");
Index: java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
(revision 151739)
+++ java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
(working copy)
@@ -119,6 +119,7 @@
static String commonDBHome = "testCSHome";
static boolean dbIsNew = true;
static String runwithjvm="true";
+ static boolean startServer=true; // should test harness start the server
// Other test variables for directories, files, output
static String scriptName = ""; // testname as passed in
@@ -255,7 +256,7 @@
if ((driverName != null) && (!skiptest) )
{
System.out.println("Initialize for framework: "+ framework );
- if (jvmnet && (framework.equals("DB2jNet") ||
framework.startsWith("DerbyNet")))
+ if (jvmnet && framework.startsWith("DerbyNet"))
{
// first check to see if properties were set to use a
different jvm for server/client
String jvmnetjvm = System.getProperty("serverJvmName");
@@ -265,10 +266,12 @@
jvmnetjvm = "j9_22";
}
- ns = new NetServer(baseDir, jvmnetjvm, classpathServer, null,
jvmflags,framework);
+ ns = new NetServer(baseDir, jvmnetjvm, classpathServer, null,
+
jvmflags,framework, startServer);
}
else
- ns = new NetServer(baseDir, jvmName,
classpathServer, javaCmd, jvmflags,framework);
+ ns = new NetServer(baseDir, jvmName,
classpathServer,
+ javaCmd,
jvmflags,framework, startServer);
ns.start();
frameworkInitialized = true;
}
@@ -298,8 +301,6 @@
// Stop the Network server if necessary
if (frameworkInitialized)
{
- System.out.println("Attempt to shutdown framework: "
- + framework);
ns.stop();
}
@@ -1461,7 +1462,13 @@
addSkiptestReason("Test skipped: test cannot
run with jvm: " +
jvmName + ".
" + scriptFileName);
}
-
+ // startServer will determine whether the server will
be started
+ // for network server tests or that will be left to the
test.
+ String startServerProp = ap.getProperty("startServer");
+ if (startServerProp != null &&
+ startServerProp.equalsIgnoreCase("false"))
+ startServer =false;
+
// Check for jvmflags (like "-nojit -ms32M -mx32M")
// These may have been set as a system property already
if (jvmflags == null)
Index: java/testing/org/apache/derbyTesting/functionTests/harness/NetServer.java
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/harness/NetServer.java
(revision 151739)
+++ java/testing/org/apache/derbyTesting/functionTests/harness/NetServer.java
(working copy)
@@ -47,6 +47,7 @@
BackgroundStreamSaver outSaver, errSaver;
FileOutputStream fosOut, fosErr;
private String java;
+ private boolean startServer; // whether test will start it's own server
// Variables for test connection
Object networkServer; // Server needs to be created with reflection
@@ -112,7 +113,7 @@
}
public NetServer(File homeDir, String jvmName, String clPath, String
- javaCmd, String jvmflags, String framework)
+ javaCmd, String jvmflags, String framework, boolean
startServer)
throws Exception
{
this.homeDir = homeDir;
@@ -124,12 +125,18 @@
frameworkInfo = (Object[]) m.get(framework);
this.port = Integer.parseInt((String) frameworkInfo[PORT_POS]);
-
+ this.startServer = startServer;
// System.out.println("framework: " + this.framework + "port: " +
this.port);
}
public void start() throws Exception
{
+ if (! startServer)
+ {
+ System.out.println("startServer = false. Bypass server
startup");
+ return;
+ }
+
// Create the Server directory under the server dir
(new File(homeDir, framework + "Server")).mkdir();
String[] startcmd = (String[]) frameworkInfo[START_CMD_POS];
@@ -232,6 +239,12 @@
public boolean testNetworkServerConnection() throws Exception
{
+ if (! startServer)
+ {
+ System.out.println("startServer = false. Bypass server
check");
+ return true;
+ }
+
Object[] testConnectionArg = null;
if (networkServer == null)
{
@@ -249,6 +262,13 @@
// stop the Server
public void stop() throws Exception
{
+ if (! startServer)
+ {
+ return;
+ }
+
+ System.out.println("Attempt to shutdown framework: "
+ + framework);
jvm jvm = null; // to quiet the compiler
jvm = jvm.getJvm(jvmName);
Vector jvmCmd = jvm.getCommandLine();
Index:
java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/sysinfo.out
(working copy)
@@ -12,7 +12,6 @@
derby.drda.host=localhost
derby.drda.traceAll=false
----- Derby Information --------
-JRE - JDBC: J2SE 1.4 - JDBC 3.0
-----
----- Locale Information -----------------
Current Locale : [English/United States [en_US]]
@@ -41,7 +40,6 @@
derby.drda.host=localhost
derby.drda.traceAll=false
----- Derby Information --------
-JRE - JDBC: J2SE 1.4 - JDBC 3.0
-----
----- Locale Information -----------------
Current Locale : [English/United States [en_US]]
Index:
java/testing/org/apache/derbyTesting/functionTests/suites/noDerbyNetClient.runall
===================================================================
---
java/testing/org/apache/derbyTesting/functionTests/suites/noDerbyNetClient.runall
(revision 151739)
+++
java/testing/org/apache/derbyTesting/functionTests/suites/noDerbyNetClient.runall
(working copy)
@@ -1,4 +1,3 @@
-derbynet/dataSourcePermissions_net.java
# excluding resultsetStream.java because this test uses
java.io.FileInputStream throughout the test
# excluding scrollCursors2.java because updatable resultsets & scroll
sensitive cursors are not supported
# excluding batchUpdate.java for it hits a problem in networkserver ('beetle'
5561)
Index: java/testing/org/apache/derbyTesting/functionTests/util/build.xml
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/util/build.xml
(revision 151739)
+++ java/testing/org/apache/derbyTesting/functionTests/util/build.xml
(working copy)
@@ -60,7 +60,25 @@
<include name="${this.dir}/*.java"/>
<include name="${this.dir}/StaticInitializers/*.java"/>
<include name="${this.dir}/VTIClasses/*.java"/>
+ <exclude name="${this.dir}/TestUtil.java"/>
</javac>
+<javac
+ bootclasspath="${empty}"
+ nowarn="on"
+ debug="${debug}"
+ depend="${depend}"
+ deprecation="${deprecation}"
+ optimize="${optimize}"
+ proceed="${proceed}"
+ verbose="${verbose}"
+ srcdir="${derby.testing.src.dir}"
+ destdir="${out.dir}">
+ <classpath>
+ <pathelement path="${java14compile.classpath}"/>
+ </classpath>
+ <!--exclude name=""/-->
+ <include name="${this.dir}/TestUtil.java"/>
+ </javac>
</target>
Index: java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
(revision 151739)
+++ java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
(working copy)
@@ -23,7 +23,11 @@
import java.sql.*;
import java.io.*;
+import java.lang.reflect.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.Locale;
+import java.util.Properties;
import org.apache.derby.iapi.reference.JDBC30Translation;
@@ -69,6 +73,13 @@
private static int framework = UNKNOWN_FRAMEWORK;
+
+ // DataSource Type strings used to build up datasource names.
+ // e.g. "Embed" + XA_DATASOURCE_STRING + "DataSource
+ private static String XA_DATASOURCE_STRING = "XA";
+ private static String CONNECTION_POOL_DATASOURCE_STRING =
"ConnectionPool";
+ private static String REGULAR_DATASOURCE_STRING = "";
+
// Methods for making framework dependent decisions in tests.
/**
@@ -207,6 +218,151 @@
Class.forName(driverName).newInstance();
}
+
+ /**
+ * Get a data source for the appropriate framework
+ * @param attrs A set of attribute values to set on the datasource.
+ * The appropriate setter method wil b
+ * For example the property databaseName with value
wombat,
+ * will mean ds.setDatabaseName("wombat") will be called
+ * @return datasource for current framework
+ */
+ public static javax.sql.DataSource getDataSource(Properties attrs)
+ {
+
+ String classname = getDataSourcePrefix() +
REGULAR_DATASOURCE_STRING + "DataSource";
+ return (javax.sql.DataSource)
getDataSourceWithReflection(classname, attrs);
+ }
+
+ /**
+ * Get an xa data source for the appropriate framework
+ * @param attrs A set of attribute values to set on the datasource.
+ * The appropriate setter method wil b
+ * For example the property databaseName with value
wombat,
+ * will mean ds.setDatabaseName("wombat") will be called
+ * @return datasource for current framework
+ */
+ public static javax.sql.XADataSource getXADatasource(Properties attrs)
+ {
+
+ String classname = getDataSourcePrefix() + XA_DATASOURCE_STRING
+ "DataSource";
+ return (javax.sql.XADataSource)
getDataSourceWithReflection(classname, attrs);
+ }
+
+
+ /**
+ * Get a ConnectionPoolDataSource for the appropriate framework
+ * @param attrs A set of attribute values to set on the datasource.
+ * The appropriate setter method wil b
+ * For example the property databaseName with value
wombat,
+ * will mean ds.setDatabaseName("wombat") will be called
+ * @return datasource for current framework
+ */
+ public static javax.sql.ConnectionPoolDataSource
getConnectionPoolDataSource(Properties attrs)
+ {
+
+ String classname = getDataSourcePrefix() +
CONNECTION_POOL_DATASOURCE_STRING + "DataSource";
+ return (javax.sql.ConnectionPoolDataSource)
getDataSourceWithReflection(classname, attrs);
+ }
+
+ private static String getDataSourcePrefix()
+ {
+ framework = getFramework();
+ switch(framework)
+ {
+ case OLD_NET_FRAMEWORK:
+ case DERBY_NET_FRAMEWORK:
+ case DB2JCC_FRAMEWORK:
+ return "com.ibm.db2.jcc.DB2";
+ case DERBY_NET_CLIENT_FRAMEWORK:
+ return "org.apache.derby.jdbc.Client";
+ case EMBEDDED_FRAMEWORK:
+ return "org.apache.derby.jdbc.Embed";
+ default:
+ Exception e = new Exception("FAIL: No
DataSource Prefix for framework: " + framework);
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ static private Class[] STRING_ARG_TYPE = {String.class};
+ static private Class[] INT_ARG_TYPE = {Integer.TYPE};
+ static private Class[] BOOLEAN_ARG_TYPE = { Boolean.TYPE };
+ // A hashtable of special non-string attributes.
+ private static Hashtable specialAttributes = null;
+
+
+ private static Object getDataSourceWithReflection(String classname,
Properties attrs)
+ {
+ Object[] args = null;
+ Object ds = null;
+ Method sh = null;
+
+
+ if (specialAttributes == null)
+ {
+ specialAttributes = new Hashtable();
+ specialAttributes.put("portNumber",INT_ARG_TYPE);
+ specialAttributes.put("driverType",INT_ARG_TYPE);
+
specialAttributes.put("retrieveMessagesFromServerOnGetMessage",
+
BOOLEAN_ARG_TYPE);
+ }
+
+ try {
+ ds = Class.forName(classname).newInstance();
+
+ for (Enumeration propNames = attrs.propertyNames();
+ propNames.hasMoreElements();)
+ {
+ String key = (String) propNames.nextElement();
+ Class[] argType = (Class[]) specialAttributes.get(key);
+ if (argType == null)
+ argType = STRING_ARG_TYPE;
+ String value = attrs.getProperty(key);
+ if (argType == INT_ARG_TYPE)
+ {
+ args = new Integer[]
+ { new Integer(Integer.parseInt(value)) };
+ }
+ else if (argType == BOOLEAN_ARG_TYPE)
+ {
+ args = new Boolean[] { new Boolean(value) };
+ }
+ else if (argType == STRING_ARG_TYPE)
+ {
+ args = new String[] { value };
+ }
+ else // No other property types supported right now
+ {
+ throw new Exception("FAIL:
getDataSourceWithReflection: Argument type " + argType[0].getName() + " not
supportted for attribute: " +
+ " key:"
+ key + " value:" +value);
+
+ }
+ String methodName = getSetterName(key);
+
+
+ // Need to use reflection to load indirectly
+ // setDatabaseName
+ sh = ds.getClass().getMethod(methodName, argType);
+ sh.invoke(ds, args);
+ }
+
+ } catch (Exception e)
+ {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ return ds;
+ }
+
+
+ private static String getSetterName(String attribute)
+ {
+ return "set" + Character.toUpperCase(attribute.charAt(0)) +
attribute.substring(1);
+ }
+
+
+ // Some methods for test output.
public static void dumpSQLExceptions(SQLException sqle) {
TestUtil.dumpSQLExceptions(sqle, false);
}
@@ -467,8 +623,3 @@
-
-
-
-
-