db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r636417 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/management/JDBCMBeanTest.java functionTests/tests/management/MBeanTest.java junit/NetworkServerTestSetup.java junit/Utilities.java
Date Wed, 12 Mar 2008 17:02:51 GMT
Author: djd
Date: Wed Mar 12 10:02:44 2008
New Revision: 636417

URL: http://svn.apache.org/viewvc?rev=636417&view=rev
Log:
DERBY-3385 This patch modifies the JDBCMBeanTest so that the expected values for the MajorVersion
and MinorVersion attributes are obtained from the embedded driver instead of the client driver.

The patch also moves the two generic utility methods for fetching sysinfo output from MBeanTest.java
to org.apache.derbyTesting.junit.Utilities.java. In addition, the patch revises some Javadoc
comments in NetworkServerTestSetup.java. 
Contributed by John H. Embretsen Email: John dot Embretsen at Sun dot com

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JDBCMBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JDBCMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JDBCMBeanTest.java?rev=636417&r1=636416&r2=636417&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JDBCMBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JDBCMBeanTest.java
Wed Mar 12 10:02:44 2008
@@ -22,10 +22,13 @@
 package org.apache.derbyTesting.functionTests.tests.management;
 
 import java.io.BufferedReader;
-import java.sql.DatabaseMetaData;
+import java.sql.Driver;
 import java.util.Hashtable;
 import javax.management.ObjectName;
 import junit.framework.Test;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.Utilities;
 
 
 /**
@@ -92,7 +95,7 @@
     public void testAttributeDriverLevel() throws Exception {
         String expected = "[Unable to get driver level from sysinfo]";
         // Get the expected value from sysinfo
-        BufferedReader sysinfoOutput = getSysinfoFromServer();
+        BufferedReader sysinfoOutput = Utilities.getSysinfoFromServer();
         String line = null;
         while ((line = sysinfoOutput.readLine()) != null) {
             /* Looking for:
@@ -109,15 +112,53 @@
         assertStringAttribute(expected,getJdbcMBeanObjectName(), "DriverLevel");
     }
     
+    /**
+     * <p>
+     * Tests the MajorVersion attribute of the JDBCMBean. Will test that there
+     * exists an attribute with that name that we are able to read, that it 
+     * returns the correct type, and that the return value is as expected.</p>
+     * <p>
+     * The expected value is retreived from the embedded driver that is directly
+     * accessible to this JVM, making the assumption that this driver's version
+     * information is the same as the version information of the embedded driver
+     * used in the JVM being instrumented using JMX (this may or may not be the
+     * same JVM).</p>
+     * 
+     * @throws java.lang.Exception if an error occurs, or if the test fails.
+     */
     public void testAttributeMajorVersion() throws Exception {
-        DatabaseMetaData dbmd = getConnection().getMetaData();
-        int expected = dbmd.getDriverMajorVersion();
+        /* since the JDBCMBean instruments the embedded driver (InternalDriver),
+         * we need to get expected values from the embedded driver even if
+         * this test configuration is client/server.
+         * Assuming that the embedded driver is available in the classpath.
+         */
+        Driver d = new org.apache.derby.jdbc.EmbeddedDriver();
+        int expected = d.getMajorVersion();
         assertIntAttribute(expected, getJdbcMBeanObjectName(), "MajorVersion");
     }
     
+    /**
+     * <p>
+     * Tests the MinorVersion attribute of the JDBCMBean. Will test that there
+     * exists an attribute with that name that we are able to read, that it 
+     * returns the correct type, and that the return value is as expected.</p>
+     * <p>
+     * The expected value is retreived from the embedded driver that is directly
+     * accessible to this JVM, making the assumption that this driver's version
+     * information is the same as the version information of the embedded driver
+     * used in the JVM being instrumented using JMX (this may or may not be the
+     * same JVM).</p>
+     * 
+     * @throws java.lang.Exception if an error occurs, or if the test fails.
+     */
     public void testAttributeMinorVersion() throws Exception {
-        DatabaseMetaData dbmd = getConnection().getMetaData();
-        int expected = dbmd.getDriverMinorVersion();
+        /* since the JDBCMBean instruments the embedded driver (InternalDriver),
+         * we need to get expected values from the embedded driver even if
+         * this test configuration is client/server.
+         * Assuming that DriverManager is available in the classpath.
+         */
+        Driver d = new org.apache.derby.jdbc.EmbeddedDriver();
+        int expected = d.getMinorVersion();
         assertIntAttribute(expected, getJdbcMBeanObjectName(), "MinorVersion");
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java?rev=636417&r1=636416&r2=636417&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
Wed Mar 12 10:02:44 2008
@@ -21,13 +21,7 @@
 
 package org.apache.derbyTesting.functionTests.tests.management;
 
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringReader;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
@@ -490,46 +484,4 @@
         println(name + " = " + value); // for debugging
     }
     
-    
-    /**
-     * Calls the public method <code>getInfo</code> of the sysinfo tool within
-     * this JVM and returns a <code>BufferedReader</code> for reading its 
-     * output. This is useful for obtaining system information that could be 
-     * used to verify (for example) values returned by Derby MBeans.
-     * 
-     * @return a buffering character-input stream containing the output from
-     *         sysinfo
-     * @see org.apache.derby.tools.sysinfo#getInfo(java.io.PrintWriter out)
-     */
-    protected BufferedReader getSysinfoLocally() {
-        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(20 * 1024);
-        PrintWriter pw = new PrintWriter(byteStream, true); // autoflush
-        org.apache.derby.tools.sysinfo.getInfo(pw);
-        pw.flush();
-        pw.close();
-        byte[] outBytes = byteStream.toByteArray();
-        BufferedReader sysinfoOutput = new BufferedReader(
-                    new InputStreamReader(
-                            new ByteArrayInputStream(outBytes)));
-        return sysinfoOutput;
-    }
-    
-    /**
-     * <p>Calls the public method <code>getSysInfo()</code> of the Network

-     * Server instance associated with the current test configuration and 
-     * returns the result as a BufferedReader, making it easy to analyse the 
-     * output line by line.</p>
-     * 
-     * <p>This is useful for obtaining system information that could be 
-     * used to verify (for example) values returned by Derby MBeans.</p>
-     * 
-     * @return a buffering character-input stream containing the output from 
-     *         the server's sysinfo.
-     * @see org.apache.derby.drda.NetworkServerControl#getSysinfo()
-     */
-    protected BufferedReader getSysinfoFromServer() throws Exception {
-        
-        return new BufferedReader(new StringReader(
-                NetworkServerTestSetup.getNetworkServerControl().getSysinfo()));
-    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?rev=636417&r1=636416&r2=636417&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Wed Mar 12 10:02:44 2008
@@ -83,13 +83,14 @@
     private SpawnedProcess spawnedServer;
     
     /**
-     * Decorator this test with the NetworkServerTestSetup.
+     * Decorates a test with the NetworkServerTestSetup.
      * 
      * Runs the server using the current configuration (at the time
      * of setup).
      * 
      * @param asCommand True to start using NetworkServerControl.main()
-     * within the same virtual machine, false to use NetworkServerControl.start.
+     * within the same virtual machine, false to use NetworkServerControl.start
+     * (also within the same JVM).
      * 
      * @see NetworkServerControl#main(String[])
      * @see NetworkServerControl#start(PrintWriter)
@@ -106,19 +107,25 @@
 }
 
     /**
-     * Decorator this test with the NetworkServerTestSetup.
+     * Decorates a test with the NetworkServerTestSetup.
      * 
-     * Sets up the server using the current configuration, but does not start.
+     * Sets up the server using the current configuration. Whether or not the
+     * server is actually started at setup time is determined by the value of 
+     * the passed parameters.
      * 
      * @param test the Test for which this setup is used
      * @param asCommand True to start using NetworkServerControl.main()
-     * within the same virtual machine, false to use NetworkServerControl.start.
-     * @param startServerAtSetup False to start using NetworkServerControl.main()
+     * within the same virtual machine, false to use NetworkServerControl.start()
+     * (also within the same virtual machine).
+     * @param startServerAtSetup True to start the Network Server at setup time,
+     *        False otherwise.
      * 
      * @see NetworkServerControl#main(String[])
      * @see NetworkServerControl#start(PrintWriter)
      */
-    public NetworkServerTestSetup(Test test, boolean asCommand, boolean startServerAtSetup)
{
+    public NetworkServerTestSetup(  Test test, 
+                                    boolean asCommand, 
+                                    boolean startServerAtSetup) {
         super(test);
         this.asCommand = asCommand;
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java?rev=636417&r1=636416&r2=636417&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java Wed Mar
12 10:02:44 2008
@@ -19,18 +19,21 @@
  */
 package org.apache.derbyTesting.junit;
 
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 
-import junit.framework.Assert;
 
 /**
  * General non-JDBC related utilities relocated from TestUtil
@@ -194,6 +197,48 @@
             }
             
             return pr;
-        }       
+        }
+        
+    /**
+     * Calls the public method <code>getInfo</code> of the sysinfo tool within
+     * this JVM and returns a <code>BufferedReader</code> for reading its 
+     * output. This is useful for obtaining system information that could be 
+     * used to verify, for example, values returned by Derby MBeans.
+     * 
+     * @return a buffering character-input stream containing the output from
+     *         sysinfo
+     * @see org.apache.derby.tools.sysinfo#getInfo(java.io.PrintWriter out)
+     */
+    public static BufferedReader getSysinfoLocally() {
+        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(20 * 1024);
+        PrintWriter pw = new PrintWriter(byteStream, true); // autoflush
+        org.apache.derby.tools.sysinfo.getInfo(pw);
+        pw.flush();
+        pw.close();
+        byte[] outBytes = byteStream.toByteArray();
+        BufferedReader sysinfoOutput = new BufferedReader(
+                    new InputStreamReader(
+                            new ByteArrayInputStream(outBytes)));
+        return sysinfoOutput;
+    }
+    
+    /**
+     * <p>Calls the public method <code>getSysInfo()</code> of the Network

+     * Server instance associated with the current test configuration and 
+     * returns the result as a BufferedReader, making it easy to analyse the 
+     * output line by line.</p>
+     * 
+     * <p>This is useful for obtaining system information that could be 
+     * used to verify, for example, values returned by Derby MBeans.</p>
+     * 
+     * @return a buffering character-input stream containing the output from 
+     *         the server's sysinfo.
+     * @see org.apache.derby.drda.NetworkServerControl#getSysinfo()
+     */
+    public static BufferedReader getSysinfoFromServer() throws Exception {
+        
+        return new BufferedReader(new StringReader(
+                NetworkServerTestSetup.getNetworkServerControl().getSysinfo()));
+    }
 
 }



Mime
View raw message