jchen21 commented on a change in pull request #6770:
URL: https://github.com/apache/geode/pull/6770#discussion_r692482329
##########
File path:
geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
##########
@@ -449,20 +463,15 @@ public synchronized void start() throws IOException {
if (accessFile != null && accessFile.length() > 0) {
// Rewire the mbs hierarchy to set accessController
ReadOpFileAccessController controller = new
ReadOpFileAccessController(accessFile);
- controller.setMBeanServer(mbs);
+ if (jmxConnectorServer.getMBeanServer() == null) {
Review comment:
Generally, I don't expect the MBeanServer to be null for
`jmxConnectorServer`. The MBeanServer is from line 369 and put in the
`jmxConnectorServer` constructor in 416. This `if` statement is a guard in case
some other code path leads to a null MBeanServer in `jmxConnectorServer`, then
we still need to set the MBeanServer for the `controller`. However, we don't
want to set MBeanServer twice for the `controller`, which is the original bug.
##########
File path:
geode-core/src/test/java/org/apache/geode/management/internal/ManagementAgentTest.java
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.security.SecurityService;
+
+public class ManagementAgentTest {
+
+ // private ManagementAgent managementAgent = spy(ManagementAgent.class);
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
Review comment:
Agree.
##########
File path:
geode-core/src/test/java/org/apache/geode/management/internal/ManagementAgentTest.java
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.security.SecurityService;
+
+public class ManagementAgentTest {
+
+ // private ManagementAgent managementAgent = spy(ManagementAgent.class);
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Test
+ public void testSetMBeanServer() throws IOException {
+ DistributionConfig distributionConfig = mock(DistributionConfig.class);
+ InternalCache internalCache = mock(InternalCache.class);
+ JmxRmiSerialFilter serialFilter = mock(JmxRmiSerialFilter.class);
+ SecurityService securityService = mock(SecurityService.class);
+ when(internalCache.getSecurityService()).thenReturn(securityService);
+ when(securityService.isIntegratedSecurity()).thenReturn(false);
+ File tempFile = temporaryFolder.newFile("testFile");
+
when(distributionConfig.getJmxManagerAccessFile()).thenReturn(tempFile.getCanonicalPath());
+ ManagementAgent managementAgent =
+ new ManagementAgent(distributionConfig, internalCache, serialFilter);
+ MBeanServer mBeanServer = mock(MBeanServer.class);
+ JMXConnectorServer jmxConnectorServerWithMBeanServer = new
JMXConnectorServer(mBeanServer) {
Review comment:
I need two instances of subclass of `JMXConnectorServer`, which an
abstract class. One instance with a non-null `mbeanServer` field, the other
with a null `mbeanServer`. I don't know why move this to a static inner-class.
I have tried to mock `JMXConnectorServer`. But I don't think a mock will work
in this test case. I need to set the `mbeanServer` field of
`JMXConnectorServer`. There is no setter for it. Only the constructor sets it.
##########
File path:
geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
##########
@@ -508,6 +517,10 @@ public JMXConnectorServer getJmxConnectorServer() {
return jmxConnectorServer;
}
+ public void setJmxConnectorServer(JMXConnectorServer jmxConnectorServer) {
+ this.jmxConnectorServer = jmxConnectorServer;
+ }
+
Review comment:
This method is added for the test. So it should be non-private. We can
remove the `public` scope.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]