eolivelli commented on a change in pull request #904: ZOOKEEPER-3037 - Add JVMPauseMonitor URL: https://github.com/apache/zookeeper/pull/904#discussion_r274080245
########## File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/util/JvmPauseMonitorTest.java ########## @@ -0,0 +1,133 @@ +/** + * 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.zookeeper.server.util; + +import org.apache.zookeeper.server.ServerConfig; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +public class JvmPauseMonitorTest { + + @Test + public void testJvmPauseMonitorInit() { + final Long sleepTime = 444L; + final Long warnTH = 5555L; + final Long infoTH = 555L; + + ServerConfig serverConfig = new ServerConfig(); + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + + Assert.assertEquals(false, serverConfig.isJvmPauseMonitorToRun()); + Assert.assertEquals(false, quorumPeerConfig.isJvmPauseMonitorToRun()); + + Properties zkProp = new Properties(); + zkProp.setProperty("dataDir", new File("myDataDir").getAbsolutePath()); + zkProp.setProperty("jvm.pause.monitor", "true"); + zkProp.setProperty("jvm.pause.sleep.time.ms", sleepTime.toString()); + zkProp.setProperty("jvm.pause.warn-threshold.ms", warnTH.toString()); + zkProp.setProperty("jvm.pause.info-threshold.ms", infoTH.toString()); + try { + quorumPeerConfig.parseProperties(zkProp); + } catch (IOException | QuorumPeerConfig.ConfigException e) { + Assert.fail("Exception while reading config for JvmPauseMonitor"); + } + serverConfig.readFrom(quorumPeerConfig); + + Assert.assertEquals(true, serverConfig.isJvmPauseMonitorToRun()); + Assert.assertEquals(true, quorumPeerConfig.isJvmPauseMonitorToRun()); + + JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(serverConfig); + Assert.assertFalse(pauseMonitor.isStarted()); + pauseMonitor.serviceStart(); + Assert.assertTrue(pauseMonitor.isStarted()); + + Assert.assertEquals(sleepTime, Long.valueOf(pauseMonitor.sleepTimeMs)); + Assert.assertEquals(warnTH, Long.valueOf(pauseMonitor.warnThresholdMs)); + Assert.assertEquals(infoTH, Long.valueOf(pauseMonitor.infoThresholdMs)); + } + + @Test + public void testJvmPauseMonitorExceedInfoThreshold() throws InterruptedException { + final Long sleepTime = 100L; + final Long infoTH = -1L; + + ServerConfig serverConfig = new ServerConfig(); + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + + Properties zkProp = new Properties(); + zkProp.setProperty("dataDir", new File("myDataDir").getAbsolutePath()); + zkProp.setProperty("jvm.pause.monitor", "true"); + zkProp.setProperty("jvm.pause.sleep.time.ms", sleepTime.toString()); + zkProp.setProperty("jvm.pause.info-threshold.ms", infoTH.toString()); + try { + quorumPeerConfig.parseProperties(zkProp); + } catch (IOException | QuorumPeerConfig.ConfigException e) { + Assert.fail("Exception while reading config for JvmPauseMonitor"); + } + serverConfig.readFrom(quorumPeerConfig); + + JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(serverConfig); + pauseMonitor.serviceStart(); Review comment: Don't we have to stop it? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services