db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1559943 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/DDMWriter.java drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
Date Tue, 21 Jan 2014 08:58:12 GMT
Author: kahatlen
Date: Tue Jan 21 08:58:12 2014
New Revision: 1559943

URL: http://svn.apache.org/r1559943
Log:
DERBY-6456: Infinite loop in NetworkServerControlImpl when reply >= 32k

Make sure the reply buffer in NetworkServerControlImpl is able to hold
the longest possible reply that it could see.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java?rev=1559943&r1=1559942&r2=1559943&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java Tue Jan 21 08:58:12
2014
@@ -62,7 +62,7 @@ class DDMWriter
      * The maximum length in bytes for strings sent by {@code writeLDString()},
      * which is the maximum unsigned integer value that fits in two bytes.
      */
-    private final static int MAX_VARCHAR_BYTE_LENGTH = 0xFFFF;
+    final static int MAX_VARCHAR_BYTE_LENGTH = 0xFFFF;
 
     /**
      * Output buffer.

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1559943&r1=1559942&r2=1559943&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Tue Jan 21 08:58:12 2014
@@ -167,8 +167,20 @@ public final class NetworkServerControlI
     private final static int SHUTDOWN_CHECK_ATTEMPTS = 100;
     private final static int SHUTDOWN_CHECK_INTERVAL= 100;
 
-    // maximum reply size
-    private final static int MAXREPLY = 32767;
+    /**
+     * Maximum reply size. The reply buffer must be large enough to hold the
+     * largest reply that {@link #readBytesReply(String)} and
+     * {@link #readStringReply(String)} can receive. That is, a reply header
+     * (4 bytes), a status byte (1 byte), a length field (2 bytes) and the
+     * longest value (in bytes) that could be written by
+     * {@link DDMWriter#writeLDBytes(byte[])} or
+     * {@link DDMWriter#writeLDString(String)}.
+     */
+    private final static int MAXREPLY =
+            REPLY_HEADER_LENGTH
+            + 1     // status byte
+            + 2     // length field
+            + DDMWriter.MAX_VARCHAR_BYTE_LENGTH;
 
     // Application Server Attributes.
     private static String att_srvclsnm;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java?rev=1559943&r1=1559942&r2=1559943&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
Tue Jan 21 08:58:12 2014
@@ -77,9 +77,15 @@ public class RuntimeInfoTest extends Bas
 	 */
 	public static Test suite() {
 		TestSuite suite = new TestSuite("RuntimeInfoTest");
-        
-        suite.addTest(decorateTest(englishLocale));
-        suite.addTest(decorateTest(germanLocale));
+
+        // Run testRunTests in both English and German locale
+        suite.addTest(decorateTest(englishLocale, "testRunTests"));
+        suite.addTest(decorateTest(germanLocale, "testRunTests"));
+
+        // Other test cases, only tested in a single locale.
+        suite.addTest(
+                decorateTest(englishLocale, "testRuntimeInfoWithLongValues"));
+
 		return suite;
 	}	
 	
@@ -188,6 +194,33 @@ public class RuntimeInfoTest extends Bas
 		assertEquals("Output doesn't match", expectedOutput, s);
 	}
 
+    /**
+     * Regression test case for DERBY-6456, which caused an infinite loop if
+     * the runtimeinfo output was more than 32KB.
+     */
+    public void testRuntimeInfoWithLongValues() throws Exception {
+        // First open many connections on the server, so that the reply from
+        // getRuntimeInfo() will be long.
+        for (int i = 0; i < 200; i++) {
+            prepareAndExecuteQuery(openDefaultConnection(),
+                "VALUES 'Hello, World! How are you today?',\n"
+              + "'Not that bad today, actually. Thanks for asking.'\n"
+              + "-- Let's add some more text to increase the output length.\n"
+              + "-- And even more here... The statement text, including this\n"
+              + "-- comment, will be included in the runtimeinfo output.\n");
+        }
+
+        // This call used to hang.
+        String runtimeinfo =
+            NetworkServerTestSetup.getNetworkServerControl().getRuntimeInfo();
+
+        // For debugging:
+        println(runtimeinfo);
+
+        // Output gets truncated to 65535 bytes (DERBY-5220).
+        assertEquals(65535, runtimeinfo.length());
+    }
+
 	public static PreparedStatement prepareAndExecuteQuery(Connection conn,
 			String sql) throws SQLException {
 		PreparedStatement ps = conn.prepareStatement(sql);
@@ -232,9 +265,9 @@ public class RuntimeInfoTest extends Bas
 	 * 
 	 * @return the decorated test
 	 */
-	private static Test decorateTest(Locale serverLocale) {
-        Test test = new TestSuite(RuntimeInfoTest.class);
-        
+    private static Test decorateTest(Locale serverLocale, String testName) {
+        Test test = new RuntimeInfoTest(testName);
+
         test = TestConfiguration.clientServerDecorator(test);
         
         /* A single use database must be used to ensure the consistent output.



Mime
View raw message