You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2014/07/15 13:42:49 UTC
svn commit: r1610662 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
junit/BaseTestCase.java junit/SpawnedProcess.java
unitTests/junit/MissingPermissionsTest.java
Author: kahatlen
Date: Tue Jul 15 11:42:48 2014
New Revision: 1610662
URL: http://svn.apache.org/r1610662
Log:
DERBY-6617: Stabilize MissingPermissionsTest
Make sure the ij process is shut down cleanly to make the exit code stable.
Use a regular expression to check for messages in the test output. The
regular expression accepts both double-quoted and unquoted names, and
any directory separator, to account for platform differences.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/MissingPermissionsTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1610662&r1=1610661&r2=1610662&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Tue Jul 15 11:42:48 2014
@@ -862,11 +862,7 @@ public abstract class BaseTestCase
public static final boolean isJava5() {
return getSystemProperty("java.version").startsWith("1.5");
}
-
- public static final boolean isJava6() {
- return getSystemProperty("java.version").startsWith("1.6");
- }
-
+
public static final boolean isJava7() {
return getSystemProperty("java.version").startsWith("1.7");
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java?rev=1610662&r1=1610661&r2=1610662&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java Tue Jul 15 11:42:48 2014
@@ -290,6 +290,8 @@ public final class SpawnedProcess {
* forcibly destroyed</li>
* <li>the hung-process watchdog mechanism forcibly terminates the
* process (see {@linkplain #scheduleKill})</li>
+ * @param timeout the number of milliseconds to wait for the process
+ * to terminate normally before destroying it
* @return The process exit code.
* @throws IOException if printing diagnostics fails
*/
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/MissingPermissionsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/MissingPermissionsTest.java?rev=1610662&r1=1610661&r2=1610662&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/MissingPermissionsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/MissingPermissionsTest.java Tue Jul 15 11:42:48 2014
@@ -33,7 +33,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import static junit.framework.Assert.assertTrue;
+import java.util.regex.Pattern;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.BaseTestSuite;
@@ -110,6 +110,11 @@ public class MissingPermissionsTest exte
final BaseTestSuite suite =
new BaseTestSuite("SystemPrivilegesPermissionTest");
+ if (!TestConfiguration.loadingFromJars()) {
+ // This test only works with jar files.
+ return suite;
+ }
+
suite.addTest(
new SupportFilesSetup(
makeTest("testMissingFilePermission",
@@ -210,8 +215,14 @@ public class MissingPermissionsTest exte
+ getSystemProperty("derbyTesting.codejar"));
args.add("-DderbyTesting.testjar="
+ getSystemProperty("derbyTesting.testjar"));
- args.add("-DderbyTesting.antjunit="
- + getSystemProperty("derbyTesting.antjunit"));
+ args.add("-DderbyTesting.junit="
+ + getSystemProperty("derbyTesting.junit"));
+ String antjunit = getSystemProperty("derbyTesting.antjunit");
+ if (antjunit != null) {
+ // This property is only available when the test is started
+ // by Ant's JUnit task.
+ args.add("-DderbyTesting.antjunit=" + antjunit);
+ }
args.add("-Dderby.system.home=system/nested");
args.add("-Dij.connection.test=jdbc:derby:wombat;create=true");
args.add("org.apache.derby.tools.ij");
@@ -221,49 +232,52 @@ public class MissingPermissionsTest exte
SpawnedProcess spawned = new SpawnedProcess(p, "MPT");
spawned.suppressOutputOnComplete(); // we want to read it ourselves
- final int exitCode = spawned.complete(3000); // 3 seconds
+ // The started process is an interactive ij session that will wait
+ // for user input. Close stdin of the process so that it stops
+ // waiting and exits.
+ p.getOutputStream().close();
+
+ final int exitCode = spawned.complete(120000L); // 2 minutes
assertTrue(
spawned.getFailMessage("subprocess run failed: "), exitCode == 0);
- final String expectedMessageOnConsole = isJava6() ?
- "The file or directory system/nested could not be created " +
- "due to a security exception: " +
- "java.security.AccessControlException: access denied " +
- "(java.io.FilePermission system/nested write)."
- :
- "The file or directory system/nested could not be created " +
+ // The actual message may vary. On Java 6, the names are not quoted,
+ // whereas newer versions double-quote them. On Windows, the directory
+ // separator is different. Use a regular expression that matches any
+ // variant.
+ final String expectedMessageOnConsole =
+ "(?s).*The file or directory system.nested could not be created " +
"due to a security exception: " +
"java.security.AccessControlException: access denied " +
- "(\"java.io.FilePermission\" \"system/nested\" \"write\").";
+ "\\(\"?java.io.FilePermission\"? \"?system.nested\"? " +
+ "\"?write\"?\\).*";
final String output = spawned.getFullServerOutput(); // ignore
final String err = spawned.getFullServerError();
- assertTrue( err, err.contains( expectedMessageOnConsole ) );
+ assertTrue(err, err.matches(expectedMessageOnConsole));
}
+ /**
+ * Make a regex that matches a warning for missing property permission.
+ * @param property the property for which read permission is missing
+ * @return a pattern that matches the expected warning
+ */
private String makeMessage(String property) {
+ // A variable part in the message is whether or not the names are
+ // double-quoted. In Java 6 they are not. In newer versions they are.
final StringBuilder sb = new StringBuilder();
- sb.append("WARNING: the property ");
- sb.append(property);
+ sb.append("(?s).*WARNING: the property ");
+ sb.append(Pattern.quote(property));
sb.append(" could not be read due to a security exception: ");
- sb.append("java.security.AccessControlException: access denied (");
- sb.append( doubleQuoteIfNotJava6( "java.util.PropertyPermission" ) );
- sb.append(" ");
- sb.append( doubleQuoteIfNotJava6( property ) );
- sb.append(" ");
- sb.append( doubleQuoteIfNotJava6( "read" ) );
+ sb.append("java\\.security\\.AccessControlException: access denied \\(");
+ sb.append("\"?java\\.util\\.PropertyPermission\"? \"?");
+ sb.append(Pattern.quote(property));
+ sb.append("\"? \"?read\"?.*");
return sb.toString();
}
- private String doubleQuoteIfNotJava6( String text )
- {
- if ( isJava6() ) { return text; }
- else { return "\"" + text + "\""; }
- }
-
-
private void verifyMessagesInDerbyLog(int kind) throws
FileNotFoundException,
@@ -289,17 +303,21 @@ public class MissingPermissionsTest exte
log.append('\n');
}
+ String logString = log.toString();
if (kind == KIND_EXPECT_ERROR_MSG_PRESENT) {
// We should see SecurityException when reading security
// related properties in FileMonitor#PBgetJVMProperty
- assertTrue(log.toString().contains(makeMessage(AUTH_MSG)));
+ assertTrue(logString, logString.matches(makeMessage(AUTH_MSG)));
// We should see SecurityException when reading
// derby.system.home in FileMonitor#PBinitialize
- assertTrue(log.toString().contains(makeMessage(SYSTEM_HOME)));
+ assertTrue(logString,
+ logString.matches(makeMessage(SYSTEM_HOME)));
} else if (kind == KIND_EXPECT_ERROR_MSG_ABSENT) {
- assertFalse(log.toString().contains(makeMessage(AUTH_MSG)));
- assertFalse(log.toString().contains(makeMessage(SYSTEM_HOME)));
+ assertFalse(logString,
+ logString.matches(makeMessage(AUTH_MSG)));
+ assertFalse(logString,
+ logString.matches(makeMessage(SYSTEM_HOME)));
}
} finally {
dl.close();