db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1619776 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
Date Fri, 22 Aug 2014 12:18:48 GMT
Author: kahatlen
Date: Fri Aug 22 12:18:48 2014
New Revision: 1619776

URL: http://svn.apache.org/r1619776
Log:
DERBY-6701: Instability in RuntimeInfoTest.x_testRuntimeInfoAfterConnClose

Keep calling getRuntimeInfo() for up to a minute until it gives the
expected response.

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

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=1619776&r1=1619775&r2=1619776&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
Fri Aug 22 12:18:48 2014
@@ -177,18 +177,34 @@ public class RuntimeInfoTest extends Bas
 	 * @throws Exception
 	 */
 	public void x_testRuntimeInfoAfterConnClose() throws Exception {
-		// give the network server a second to clean up (DERBY-1455)
-		Thread.sleep(1000);
 
-		String s = NetworkServerTestSetup
+        String expectedOutput =
+            outputs.get(Locale.getDefault()).get("RuntimeInfoAfterConnClose");
+
+        // DERBY-1455 and DERBY-6701: The closed connections may not be
+        // cleaned up by the network server immediately. Retry the
+        // getRuntimeInfo() call for up to one minute until we get the
+        // expected response.
+        String s = null;
+        int retriesLeft = 60;
+        while (true) {
+            s = sed(NetworkServerTestSetup
 					.getNetworkServerControl(TestConfiguration.getCurrent().getPort())
-					.getRuntimeInfo();
-		s = sed(s);
+                    .getRuntimeInfo());
+
+            // Keep retrying until we either get the expected response, or
+            // we reach the maximum number of retries.
+            if (expectedOutput.equals(s) || (--retriesLeft <= 0)) {
+                break;
+            }
+
+            sleep(1000L);
+        }
+
 		NetworkServerTestSetup.getNetworkServerControl().shutdown();
 		
 		printIfVerbose("testRuntimeInfoMethod", s);
 		
-		String expectedOutput = ((HashMap)outputs.get(Locale.getDefault())).get("RuntimeInfoAfterConnClose").toString();
 		assertEquals("Output doesn't match", expectedOutput, s);
 	}
 
@@ -236,9 +252,11 @@ public class RuntimeInfoTest extends Bas
      * @return the string with the lines removed
      */
     private String sed(String s) {
-    	String searchString = ((HashMap)outputs.get(Locale.getDefault())).get("sedMemorySearch").toString();
-    	String replaceString = ((HashMap)outputs.get(Locale.getDefault())).get("sedMemoryReplace").toString();
-		s = s.replaceAll(searchString, replaceString);
+        HashMap<String, String> strings = outputs.get(Locale.getDefault());
+        s = s.replaceAll(strings.get("sedMemorySearch"),
+                         strings.get("sedMemoryReplace"));
+        s = s.replaceAll(strings.get("sedSessionNumberSearch"),
+                         strings.get("sedSessionNumberReplace"));
 		s = s.replaceAll(stdout_err_tags, "");
 		s = s.trim();
 		return s;
@@ -283,7 +301,7 @@ public class RuntimeInfoTest extends Bas
 		englishOutputs.put("RuntimeInfoWithActiveConn",
 				"--- Derby Network Server Runtime Information ---\n" + 
 				"---------- Session Information ---------------\n" + 
-				"Session # :2\n" + 
+                "Session # :##\n" +
 				"\n" + 
 				"\n" + 
 				"-------------------------------------------------------------\n" + 
@@ -295,7 +313,7 @@ public class RuntimeInfoTest extends Bas
 		englishOutputs.put("RuntimeInfoAfterConnClose", 
 				"--- Derby Network Server Runtime Information ---\n" + 
 				"---------- Session Information ---------------\n" + 
-				"Session # :8\n" + 
+                "Session # :##\n" +
 				"\n" + 
 				"\n" + 
 				"-------------------------------------------------------------\n" + 
@@ -306,13 +324,15 @@ public class RuntimeInfoTest extends Bas
 				"Total Memory : #####	Free Memory : #####");
 		englishOutputs.put("sedMemorySearch", "(?m)Memory : [0-9]*");
 		englishOutputs.put("sedMemoryReplace", "Memory : #####");
+        englishOutputs.put("sedSessionNumberSearch", "(?m)^(Session # :)\\d+");
+        englishOutputs.put("sedSessionNumberReplace", "$1##");
 		englishOutputs.put("RuntimeInfoLocaleString", "\tStmt ID\t\tSQLText\n\t-------------\t-----------\n\n\n\nSession");
 		
 		HashMap<String, String> germanOutputs = new HashMap<String, String>();
 		germanOutputs.put("RuntimeInfoWithActiveConn",
 				"--- Laufzeitinformationen zu Derby Network Server ---\n" + 
 				"---------- Sessioninformationen ---------------\n" + 
-				"Sessionnummer:2\n" + 
+                "Sessionnummer:##\n" +
 				"\n" + 
 				"\n" + 
 				"-------------------------------------------------------------\n" + 
@@ -324,7 +344,7 @@ public class RuntimeInfoTest extends Bas
 		germanOutputs.put("RuntimeInfoAfterConnClose", 
 				"--- Laufzeitinformationen zu Derby Network Server ---\n" + 
 				"---------- Sessioninformationen ---------------\n" + 
-				"Sessionnummer:8\n" + 
+                "Sessionnummer:##\n" +
 				"\n" + 
 				"\n" + 
 				"-------------------------------------------------------------\n" + 
@@ -335,6 +355,8 @@ public class RuntimeInfoTest extends Bas
 				"Speicher gesamt: #####	Freier Speicher: #####");
 		germanOutputs.put("sedMemorySearch", "Speicher gesamt: [0-9]*	Freier Speicher: [0-9]*");
 		germanOutputs.put("sedMemoryReplace", "Speicher gesamt: #####	Freier Speicher: #####");
+        germanOutputs.put("sedSessionNumberSearch", "(?m)^(Sessionnummer:)\\d+");
+        germanOutputs.put("sedSessionNumberReplace", "$1##");
 		germanOutputs.put("RuntimeInfoLocaleString", "\tAnwsg-ID\t\tSQL-Text\n\t-------------\t-----------\n\n\n\nSessionnummer");
 		
 		outputs = new HashMap<Locale, HashMap<String, String>>();



Mime
View raw message