< prev index next >
jaxp/test/javax/xml/jaxp/unittest/sax/SymbolTableResetTest.java
Print this page
*** 21,30 ****
--- 21,32 ----
* questions.
*/
package sax;
+ import static jaxp.library.JAXPTestUtilities.runWithAllPerm;
+
import java.io.StringReader;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
*** 34,78 ****
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
/*
* @test
! * @bug 8173390
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
! * @run testng/othervm -DrunSecMngr=true sax.SymbolTableResetTest
! * @run testng/othervm sax.SymbolTableResetTest
* @summary Test that SAXParser reallocates symbol table during
* subsequent parse operations
*/
@Listeners({jaxp.library.BasePolicy.class})
public class SymbolTableResetTest {
/*
* Test mimics the SAXParser usage in SAAJ-RI that reuses the
* parsers from the internal pool. To avoid memory leaks, symbol
* table associated with the parser should be reallocated during each
* parse() operation.
*/
! @Test
! public void testReset() throws Exception {
// Dummy xml input for parser
String input = "<dummy>Test</dummy>";
! // Create SAXParser
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser p = spf.newSAXParser();
// First parse iteration
p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
// Get first symbol table reference
Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY);
p.reset();
// Second parse iteration
p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
// Get second symbol table reference
Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY);
! // Symbol table references should be different
Assert.assertNotSame(symTable1, symTable2, "Symbol table references");
}
// Symbol table property
private static final String SYMBOL_TABLE_PROPERTY = "http://apache.org/xml/properties/internal/symbol-table";
-
}
--- 36,137 ----
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
/*
* @test
! * @bug 8173390 8176168
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
! * @run testng/othervm -Djdk.xml.resetSymbolTable=false sax.SymbolTableResetTest
! * @run testng/othervm -Djdk.xml.resetSymbolTable=true sax.SymbolTableResetTest
! * @run testng/othervm -Djdk.xml.resetSymbolTable=false -DrunSecMngr=true sax.SymbolTableResetTest
! * @run testng/othervm -Djdk.xml.resetSymbolTable=true -DrunSecMngr=true sax.SymbolTableResetTest
* @summary Test that SAXParser reallocates symbol table during
* subsequent parse operations
*/
@Listeners({jaxp.library.BasePolicy.class})
public class SymbolTableResetTest {
/*
+ * Test verifies the following use cases when the parser feature is not set:
+ * a) Reset symbol table is requested via the system property
+ * b) Reset symbol table is not requested via the system property
+ * and therefore the default value should be used - reset
+ * operation should not occur.
+ */
+ @Test
+ public void testNoFeatureSet() throws Exception {
+ parseAndCheckReset(false, false);
+ }
+
+
+ /*
+ * Test that when symbol table reset is requested through parser
+ * feature it is not affected by the system property value
+ */
+ @Test
+ public void testResetEnabled() throws Exception {
+ parseAndCheckReset(true, true);
+ }
+
+ /*
+ * Test that when symbol table reset is disabled through parser
+ * feature it is not affected by the system property value
+ */
+ @Test
+ public void testResetDisabled() throws Exception {
+ parseAndCheckReset(true, false);
+ }
+
+ /*
* Test mimics the SAXParser usage in SAAJ-RI that reuses the
* parsers from the internal pool. To avoid memory leaks, symbol
* table associated with the parser should be reallocated during each
* parse() operation.
*/
! private void parseAndCheckReset(boolean setFeature, boolean value) throws Exception {
! // Expected result based on system property and feature
! boolean resetExpected = setFeature && value;
! // Indicates if system property is set
! boolean spSet = runWithAllPerm(() -> System.getProperty(RESET_FEATURE)) != null;
// Dummy xml input for parser
String input = "<dummy>Test</dummy>";
!
! // Check if system property is set only when feature setting is not requested
! // and estimate if reset of symbol table is expected
! if (!setFeature && spSet) {
! resetExpected = runWithAllPerm(() -> Boolean.getBoolean(RESET_FEATURE));
! }
!
! // Create SAXParser and set feature if it is requested
SAXParserFactory spf = SAXParserFactory.newInstance();
+ if (setFeature) {
+ spf.setFeature(RESET_FEATURE, value);
+ }
SAXParser p = spf.newSAXParser();
+
// First parse iteration
p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
// Get first symbol table reference
Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY);
+
+ // reset parser
p.reset();
+
// Second parse iteration
p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
// Get second symbol table reference
Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY);
!
! // Check symbol table references after two subsequent parse operations
! if (resetExpected) {
Assert.assertNotSame(symTable1, symTable2, "Symbol table references");
+ } else {
+ Assert.assertSame(symTable1, symTable2, "Symbol table references");
}
+ }
+
+ // Reset symbol table feature
+ private static final String RESET_FEATURE = "jdk.xml.resetSymbolTable";
// Symbol table property
private static final String SYMBOL_TABLE_PROPERTY = "http://apache.org/xml/properties/internal/symbol-table";
}
< prev index next >