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 rh...@apache.org on 2023/01/04 15:21:24 UTC
svn commit: r1906395 - in /db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management: CacheManagerMBeanTest.java JMXConnectionDecorator.java
Author: rhillegas
Date: Wed Jan 4 15:21:24 2023
New Revision: 1906395
URL: http://svn.apache.org/viewvc?rev=1906395&view=rev
Log:
DERBY-7149: Skip some MBean tests from JDK 20 onward; commit derby-7149-02-aa-disableJMXtest.diff.
Modified:
db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/CacheManagerMBeanTest.java
db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
Modified: db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/CacheManagerMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/CacheManagerMBeanTest.java?rev=1906395&r1=1906394&r2=1906395&view=diff
==============================================================================
--- db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/CacheManagerMBeanTest.java (original)
+++ db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/CacheManagerMBeanTest.java Wed Jan 4 15:21:24 2023
@@ -21,9 +21,12 @@
package org.apache.derbyTesting.functionTests.tests.management;
+import java.io.File;
+import java.io.FileInputStream;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Hashtable;
+import java.util.Properties;
import java.util.Set;
import javax.management.ObjectName;
import javax.management.RuntimeMBeanException;
@@ -42,6 +45,14 @@ public class CacheManagerMBeanTest exten
private final static int DEFAULT_CONTAINER_CACHE_SIZE = 100;
private final static int DEFAULT_STATEMENT_CACHE_SIZE = 100;
+ // machinery needed for overriding the default MBean deserialization filter.
+ private final static String JAVA_HOME = "java.home";
+ private final static String CONF_DIR = "conf";
+ private final static String MANAGEMENT_DIR = "management";
+ private final static String MANAGEMENT_PROPERTIES_FILE = "management.properties";
+ private final static String DESERIALIZATION_FILTER_PROP = "com.sun.management.jmxremote.serial.filter.pattern";
+ private final static String DERBY_FILTER_VALUE = "*";
+
private static String[] ALL_ATTRIBUTES = {
"CollectAccessCounts", "HitCount", "MissCount", "EvictionCount",
"MaxEntries", "AllocatedEntries", "UsedEntries"
@@ -75,6 +86,45 @@ public class CacheManagerMBeanTest exten
}
/**
+ * <p>
+ * This method returns true if remote deserialization is enabled for Derby MBeans, that is,
+ * if com.sun.management.jmxremote.serial.filter.pattern=* in conf/management/management.properties.
+ * </p>
+ *
+ * <p>
+ * In a remote JMX configuration, the page and statement caches cannot be interrogated because
+ * Open JDK build 20-ea+27-2213 disabled the rmi deserialization of
+ * some objects required by our MBeans. See DERBY-7149. See also https://bugs.openjdk.org/browse/JDK-8283093
+ * and https://bugs.openjdk.org/browse/JDK-8295938.
+ * In order to read the page and statement caches in a client/server setup,
+ * you have to hack the JVM,
+ * overriding com.sun.management.jmxremote.serial.filter.pattern in conf/management/management.properties.
+ * </p>
+ *
+ * <p>
+ * It would be nice if this overriding could be done by setting a system property,
+ * but that doesn't seem to be supported.
+ * </p>
+ */
+ private boolean remoteDeserializationEnabled() throws Exception {
+
+ File javaHomeDir = new File(System.getProperty(JAVA_HOME));
+ File jmxManagementDir = new File(new File(javaHomeDir, CONF_DIR), MANAGEMENT_DIR);
+ File managementPropertiesFile = new File(jmxManagementDir, MANAGEMENT_PROPERTIES_FILE);
+
+ // read the JVM's management properties
+ Properties originalManagementProperties = new Properties();
+ try (FileInputStream fis = new FileInputStream(managementPropertiesFile))
+ {
+ originalManagementProperties.load(fis);
+ }
+
+ String filterValue = originalManagementProperties.getProperty(DESERIALIZATION_FILTER_PROP);
+
+ return (DERBY_FILTER_VALUE.equals(filterValue));
+ }
+
+ /**
* Create an {@code ObjectName} that identifies a {@code CacheManager}
* management bean, or a pattern that potentially matches multiple
* beans.
@@ -131,9 +181,20 @@ public class CacheManagerMBeanTest exten
}
/**
+ * Return false if we are using a remote JMX connection getter
+ * but com.sun.management.jmxremote.serial.filter.pattern has not been hacked in conf/management/management.properties.
+ */
+ public boolean skipRemoteDeserialization() throws Exception {
+ return (JMXConnectionDecorator.usingRemoteJMXConnectionGetter() && !remoteDeserializationEnabled());
+ }
+
+ /**
* Test the {@code CacheManagerMBean} for the page cache.
*/
public void testPageCache() throws Exception {
+
+ if (skipRemoteDeserialization()) { return; }
+
getConnection(); // boot the database
Set<ObjectName> names =
queryMBeans(createObjectName("PageCache", null));
@@ -208,6 +269,9 @@ public class CacheManagerMBeanTest exten
* Test the {@code CacheManagerMBean} for the statement cache.
*/
public void testStatementCache() throws Exception {
+
+ if (skipRemoteDeserialization()) { return; }
+
getConnection(); // boot the database
Set<ObjectName> names =
queryMBeans(createObjectName("StatementCache", null));
Modified: db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java?rev=1906395&r1=1906394&r2=1906395&view=diff
==============================================================================
--- db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java (original)
+++ db/derby/code/trunk/java/org.apache.derby.tests/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java Wed Jan 4 15:21:24 2023
@@ -36,6 +36,8 @@ import org.apache.derbyTesting.junit.Tes
* an implementation of this class to obtain JMX connections.
*/
class JMXConnectionDecorator extends BaseTestSetup {
+
+ private static final String REMOTE_CONNECTION_PROP = "derby.test.remote.connection.getter";
/**
* Decorate a test so to use JMX connections from the passed in url.
@@ -74,6 +76,11 @@ class JMXConnectionDecorator extends Bas
new PlatformConnectionGetter();
JMXConnectionGetter.mbeanServerConnector.set(getter);
+
+ if (remote)
+ {
+ System.setProperty(REMOTE_CONNECTION_PROP, "true");
+ }
}
@Override
@@ -81,6 +88,14 @@ class JMXConnectionDecorator extends Bas
super.tearDown();
JMXConnectionGetter.mbeanServerConnector.set(oldGetter);
oldGetter = null;
+ System.setProperty(REMOTE_CONNECTION_PROP, "false");
+ }
+
+ /**
+ * Return true if we are using a remote JMX connection getter.
+ */
+ public static boolean usingRemoteJMXConnectionGetter() {
+ return Boolean.getBoolean(REMOTE_CONNECTION_PROP);
}
/**