8173261: JAXP: TESTBUG: javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh

Reviewed-by: dfuchs, fyuan
This commit is contained in:
Christoph Langer 2017-01-24 11:10:19 +01:00
parent 7eb3a2d4cb
commit afcf1eb292
6 changed files with 128 additions and 105 deletions

View file

@ -1,6 +1,6 @@
########################################################################### ###########################################################################
# #
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -22,5 +22,3 @@
# questions. # questions.
# #
########################################################################### ###########################################################################
javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh 8169827 generic-all

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -21,11 +21,6 @@
# or visit www.oracle.com if you need additional information or have any # or visit www.oracle.com if you need additional information or have any
# questions. # questions.
if [ $# = 0 ]; then
echo "The suffix of ISOLATED_JDK is mandatory"
exit 1
fi
checkVariable() { checkVariable() {
variable='$'$1 variable='$'$1
@ -42,20 +37,33 @@ checkVariables() {
done done
} }
# Check essential variables # Script needs parameters
checkVariables TESTJAVA TESTSRC TESTCLASSES TESTCLASSPATH if [ $# = 0 ]; then
echo "Syntax: IsolatedJDK.sh <Suffix> [remove]"
exit 1
fi
echo "TESTJAVA=${TESTJAVA}" # Is it the call to remove ?
echo "TESTSRC=${TESTSRC}" if [ $# = 2 ]; then
echo "TESTCLASSES=${TESTCLASSES}" if [ "$2" = "remove" ]; then
echo "TESTCLASSPATH=${TESTCLASSPATH}" removeIsolatedJdk=1
fi
fi
# Check essential variables
checkVariables TESTJAVA
ISOLATED_JDK="./ISOLATED_JDK_$1"
# Remove isolated copy
if [ "$removeIsolatedJdk" = "1" ]; then
echo "Removing ${ISOLATED_JDK}..."
rm -rf ${ISOLATED_JDK}
echo "Removed."
exit 0
fi
# Make an isolated copy of the testing JDK # Make an isolated copy of the testing JDK
ISOLATED_JDK="./ISOLATED_JDK_$1" echo "Copying test JDK: ${TESTJAVA} -> ${ISOLATED_JDK}..."
echo "ISOLATED_JDK=${ISOLATED_JDK}"
echo "Copy testing JDK started"
cp -H -R ${TESTJAVA} ${ISOLATED_JDK} || exit 1 cp -H -R ${TESTJAVA} ${ISOLATED_JDK} || exit 1
chmod -R +w ${ISOLATED_JDK} || exit 1 chmod -R +w ${ISOLATED_JDK} || exit 1
echo "Copy testing JDK ended" echo "Copy done."

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -37,20 +37,95 @@ import static catalog.CatalogTestUtils.deleteJAXPProps;
import static catalog.CatalogTestUtils.generateJAXPProps; import static catalog.CatalogTestUtils.generateJAXPProps;
import static catalog.CatalogTestUtils.getCatalogPath; import static catalog.CatalogTestUtils.getCatalogPath;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.xml.catalog.CatalogResolver; import javax.xml.catalog.CatalogResolver;
import org.testng.Assert;
import org.testng.annotations.Test;
/* /*
* This case tests if the properties FILES, DEFER, PREFER, RESOLVE in * @test
* jaxp.properties and system properties could be cared. * @library /javax/xml/jaxp/libs /javax/xml/jaxp/isolatedjdk
* @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS
* @run testng catalog.PropertiesTest
* @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS remove
* @summary This test case tests if the properties FILES, DEFER, PREFER,
* RESOLVE in jaxp.properties and system properties are used.
* It needs to run in a copied JDK as it modifies the JDK's
* jaxp.properties file.
* @bug 8077931
*/ */
public class PropertiesTest { public class PropertiesTest {
private static final String CATALOG_PROPERTIES = "properties.xml"; private static final String CATALOG_PROPERTIES = "properties.xml";
@Test
/*
* Run main in a child process as it will modify the JDK.
*/
public void test() throws Exception {
// get required properties and do some assertions
String javaclasspath = System.getProperty("java.class.path");
Assert.assertNotNull(javaclasspath, "Test class path is null");
String testclasspath = System.getProperty("test.class.path");
Assert.assertNotNull(testclasspath, "Test class path is null");
String testsourcepath = System.getProperty("test.src");
Assert.assertNotNull(testsourcepath, "Test source path is null");
// start the child process
List<String> testCall = new ArrayList<>(6);
testCall.add(Paths.get("ISOLATED_JDK_JAXP_PROPS", "/bin", "java").toString());
testCall.add("-cp");
testCall.add(javaclasspath);
testCall.add("-Dtest.class.path=" + testclasspath);
testCall.add("-Dtest.src=" + testsourcepath);
testCall.add("catalog.PropertiesTest");
System.out.println("Starting child process: " + Arrays.toString(testCall.toArray()));
Process test = new ProcessBuilder(testCall).start();
// wait for it to finish
boolean interrupted = false;
do {
try {
test.waitFor();
interrupted = false;
} catch (InterruptedException ie) {
interrupted = true;
}
} while (interrupted);
// trace system.out of child process
System.out.println("Proccess Out:");
BufferedReader br = new BufferedReader(new InputStreamReader(test.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
// trace system.err of child process
System.out.println("Proccess Err:");
br = new BufferedReader(new InputStreamReader(test.getErrorStream()));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
// trace exit value and assert 0
int exitValue = test.exitValue();
System.out.println("Process Exit code: " + exitValue);
Assert.assertEquals(exitValue, 0, "PropertiesTest returned nonzero exit code.");
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("testJAXPProperties started"); System.out.println("testJAXPProperties started");
testJAXPProperties(); testJAXPProperties();
@ -64,7 +139,8 @@ public class PropertiesTest {
} }
/* /*
* Tests how does jaxp.properties affects the resolution. * Tests how jaxp.properties affects the resolution.
* Be careful: This test modifies jaxp.properties in the used JDK.
*/ */
private static void testJAXPProperties() throws IOException { private static void testJAXPProperties() throws IOException {
generateJAXPProps(createJAXPPropsContent()); generateJAXPProps(createJAXPPropsContent());
@ -73,7 +149,7 @@ public class PropertiesTest {
} }
/* /*
* Tests how does system properties affects the resolution. * Tests how system properties affects the resolution.
*/ */
private static void testSystemProperties() { private static void testSystemProperties() {
setSystemProperties(); setSystemProperties();
@ -104,7 +180,7 @@ public class PropertiesTest {
// The properties in jaxp.properties don't use default values // The properties in jaxp.properties don't use default values
private static String createJAXPPropsContent() { private static String createJAXPPropsContent() {
Map<String, String> props = new HashMap<>(); Map<String, String> props = new HashMap<>();
props.put(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES)); props.put(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES).toString());
props.put(FEATURE_DEFER, DEFER_FALSE); props.put(FEATURE_DEFER, DEFER_FALSE);
props.put(FEATURE_PREFER, PREFER_SYSTEM); props.put(FEATURE_PREFER, PREFER_SYSTEM);
props.put(FEATURE_RESOLVE, RESOLVE_CONTINUE); props.put(FEATURE_RESOLVE, RESOLVE_CONTINUE);
@ -113,7 +189,7 @@ public class PropertiesTest {
// The system properties don't use default values // The system properties don't use default values
private static void setSystemProperties() { private static void setSystemProperties() {
System.setProperty(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES)); System.setProperty(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES).toString());
System.setProperty(FEATURE_DEFER, DEFER_FALSE); System.setProperty(FEATURE_DEFER, DEFER_FALSE);
System.setProperty(FEATURE_PREFER, PREFER_SYSTEM); System.setProperty(FEATURE_PREFER, PREFER_SYSTEM);
System.setProperty(FEATURE_RESOLVE, RESOLVE_CONTINUE); System.setProperty(FEATURE_RESOLVE, RESOLVE_CONTINUE);

View file

@ -1,58 +0,0 @@
#!/bin/sh
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
# @test
# @bug 8077931
# @summary This case tests if the properties FILES, DEFER, PREFER, RESOLVE in
# jaxp.properties and system properties could be used.
# @key intermittent
# @library ../../libs/
# @build catalog.CatalogTestUtils
# @build PropertiesTest
# @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS
# @run shell/timeout=600 PropertiesTest.sh
echo "Copies properties.xml to class path"
TEST_CATALOG_PATH=${TESTCLASSES}/catalog/catalogFiles
echo "TEST_CATALOG_PATH=${TEST_CATALOG_PATH}"
mkdir -p ${TEST_CATALOG_PATH}
cp ${TESTSRC}/catalogFiles/properties.xml ${TEST_CATALOG_PATH}/properties.xml
# Execute test
ISOLATED_JDK=./ISOLATED_JDK_JAXP_PROPS
echo "Executes PropertiesTest"
${ISOLATED_JDK}/bin/java -Dtest.src="${TESTSRC}/.." ${TESTVMOPTS} -cp "${TESTCLASSPATH}" catalog.PropertiesTest
exitCode=$?
# Cleanup ISOLATED_JDK
rm -rf ${ISOLATED_JDK}
# Results
echo ''
if [ $exitCode -gt 0 ]; then
echo "PropertiesTest failed";
else
echo "PropertiesTest passed";
fi
exit $exitCode

View file

@ -69,12 +69,6 @@ final class CatalogTestUtils {
private static final String JAXP_PROPS = "jaxp.properties"; private static final String JAXP_PROPS = "jaxp.properties";
private static final String JAXP_PROPS_BAK = JAXP_PROPS + ".bak"; private static final String JAXP_PROPS_BAK = JAXP_PROPS + ".bak";
/*
* Force using slash as File separator as we always use cygwin to test in
* Windows platform.
*/
private static final String FILE_SEP = "/";
private CatalogTestUtils() { } private CatalogTestUtils() { }
/* ********** create resolver ********** */ /* ********** create resolver ********** */
@ -133,11 +127,14 @@ final class CatalogTestUtils {
/* ********** jaxp.properties ********** */ /* ********** jaxp.properties ********** */
/* /*
* Generates the jaxp.properties with the specified content. * Generates jaxp.properties with the specified content,
* takes a backup if possible.
*/ */
static void generateJAXPProps(String content) throws IOException { static void generateJAXPProps(String content) throws IOException {
Path filePath = getJAXPPropsPath(); Path filePath = getJAXPPropsPath();
Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK); Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK);
System.out.println("Creating new file " + filePath +
", saving old version to " + bakPath + ".");
if (Files.exists(filePath) && !Files.exists(bakPath)) { if (Files.exists(filePath) && !Files.exists(bakPath)) {
Files.move(filePath, bakPath); Files.move(filePath, bakPath);
} }
@ -146,14 +143,16 @@ final class CatalogTestUtils {
} }
/* /*
* Deletes the jaxp.properties. * Deletes jaxp.properties, restoring backup if possible.
*/ */
static void deleteJAXPProps() throws IOException { static void deleteJAXPProps() throws IOException {
Path filePath = getJAXPPropsPath(); Path filePath = getJAXPPropsPath();
Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK);
System.out.println("Removing file " + filePath +
", restoring old version from " + bakPath + ".");
Files.delete(filePath); Files.delete(filePath);
Path bakFilePath = filePath.resolveSibling(JAXP_PROPS_BAK); if (Files.exists(bakPath)) {
if (Files.exists(bakFilePath)) { Files.move(bakPath, filePath);
Files.move(bakFilePath, filePath);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -85,13 +85,13 @@ public class JAXPTestUtilities {
* A map storing every test's current test file pointer. File number should * A map storing every test's current test file pointer. File number should
* be incremental and it's a thread-safe reading on this file number. * be incremental and it's a thread-safe reading on this file number.
*/ */
private static final ConcurrentHashMap<Class, Integer> currentFileNumber private static final ConcurrentHashMap<Class<?>, Integer> currentFileNumber
= new ConcurrentHashMap<>(); = new ConcurrentHashMap<>();
/** /**
* BOM table for storing BOM header. * BOM table for storing BOM header.
*/ */
private final static Map<String, byte[]> bom = new HashMap(); private final static Map<String, byte[]> bom = new HashMap<>();
/** /**
* Initialize all BOM headers. * Initialize all BOM headers.
@ -313,7 +313,7 @@ public class JAXPTestUtilities {
* @param clazz test class. * @param clazz test class.
* @return next test output file name. * @return next test output file name.
*/ */
public static String getNextFile(Class clazz) { public static String getNextFile(Class<?> clazz) {
int nextNumber = currentFileNumber.contains(clazz) int nextNumber = currentFileNumber.contains(clazz)
? currentFileNumber.get(clazz) + 1 : 1; ? currentFileNumber.get(clazz) + 1 : 1;
Integer i = currentFileNumber.putIfAbsent(clazz, nextNumber); Integer i = currentFileNumber.putIfAbsent(clazz, nextNumber);
@ -332,7 +332,7 @@ public class JAXPTestUtilities {
* path. * path.
* @return a string represents the full path of accessing path. * @return a string represents the full path of accessing path.
*/ */
public static String getPathByClassName(Class clazz, String relativeDir) { public static String getPathByClassName(Class<?> clazz, String relativeDir) {
String javaSourcePath = System.getProperty("test.src").replaceAll("\\" + File.separator, FILE_SEP); String javaSourcePath = System.getProperty("test.src").replaceAll("\\" + File.separator, FILE_SEP);
String normalizedPath = Paths.get(javaSourcePath, relativeDir).normalize(). String normalizedPath = Paths.get(javaSourcePath, relativeDir).normalize().
toAbsolutePath().toString(); toAbsolutePath().toString();
@ -435,7 +435,7 @@ public class JAXPTestUtilities {
*/ */
public static void runWithTmpPermission(Runnable r, Permission... ps) { public static void runWithTmpPermission(Runnable r, Permission... ps) {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false); JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
List<Integer> tmpPermissionIndexes = new ArrayList(); List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) { if (policyManager != null) {
for (Permission p : ps) for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p)); tmpPermissionIndexes.add(policyManager.addTmpPermission(p));
@ -459,7 +459,7 @@ public class JAXPTestUtilities {
*/ */
public static <T> T runWithTmpPermission(Supplier<T> s, Permission... ps) { public static <T> T runWithTmpPermission(Supplier<T> s, Permission... ps) {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false); JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
List<Integer> tmpPermissionIndexes = new ArrayList(); List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) { if (policyManager != null) {
for (Permission p : ps) for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p)); tmpPermissionIndexes.add(policyManager.addTmpPermission(p));
@ -483,7 +483,7 @@ public class JAXPTestUtilities {
*/ */
public static void tryRunWithTmpPermission(RunnableWithException r, Permission... ps) throws Exception { public static void tryRunWithTmpPermission(RunnableWithException r, Permission... ps) throws Exception {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false); JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
List<Integer> tmpPermissionIndexes = new ArrayList(); List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) { if (policyManager != null) {
for (Permission p : ps) for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p)); tmpPermissionIndexes.add(policyManager.addTmpPermission(p));