Skip to content

Commit

Permalink
ZOOKEEPER-3037 - add serviceStop() and improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkalmar committed Apr 12, 2019
1 parent 7d0baaa commit a502086
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ public synchronized void shutdown(boolean fullyShutDown) {
if (firstProcessor != null) {
firstProcessor.shutdown();
}
if(jvmPauseMonitor != null) {
jvmPauseMonitor.serviceStop();
}

if (zkDb != null) {
if (fullyShutDown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,9 @@ public void shutdown() {
if(udpSocket != null) {
udpSocket.close();
}
if(jvmPauseMonitor != null) {
jvmPauseMonitor.serviceStop();
}

try {
adminServer.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private String formatMessage(long extraSleepTime,
}
}

String ret = "Detected pause in JVM or host machine (eg GC): pause of approximately " + extraSleepTime
+ "ms, total pause: info level: " + numGcInfoThresholdExceeded
+ ", warn level: " + numGcWarnThresholdExceeded + "\n";
String ret = String.format("Detected pause in JVM or host machine (eg GC): pause of approximately %d ms, " +
"total pause: info level: %d, warn level: %d \n",
extraSleepTime, numGcInfoThresholdExceeded, numGcWarnThresholdExceeded);
if (gcDiffs.isEmpty()) {
ret += ("No GCs detected");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testJvmPauseMonitorConfigured()
final Long warnTH = 5555L;
final Long infoTH = 555L;

QuorumPeerConfig quorumPeerConfig = new MockQuorumPeerConfig(1);
QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
Properties zkProp = getDefaultZKProperties();
zkProp.setProperty("dataDir", new File("myDataDir").getAbsolutePath());
zkProp.setProperty("jvm.pause.monitor", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.zookeeper.server.util;

import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -27,28 +28,48 @@

public class JvmPauseMonitorTest {

private final Long sleepTime = 100L;
private final Long infoTH = -1L;
private final Long warnTH = -1L;
private JvmPauseMonitor pauseMonitor;

@Test(timeout=5000)
public void testJvmPauseMonitorExceedThreshold() throws InterruptedException {
final Long sleepTime = 100L;
final Long warnTH = -1L;
final Long infoTH = -1L;
public void testJvmPauseMonitorExceedInfoThreshold() throws InterruptedException {
QuorumPeerConfig qpConfig = mock(QuorumPeerConfig.class);
when(qpConfig.getJvmPauseSleepTimeMs()).thenReturn(sleepTime);
when(qpConfig.getJvmPauseInfoThresholdMs()).thenReturn(infoTH);

pauseMonitor = new JvmPauseMonitor(qpConfig);
pauseMonitor.serviceStart();

Assert.assertEquals(sleepTime, Long.valueOf(pauseMonitor.sleepTimeMs));
Assert.assertEquals(infoTH, Long.valueOf(pauseMonitor.infoThresholdMs));

while(pauseMonitor.getNumGcInfoThresholdExceeded() == 0) {
Thread.sleep(200);
}
}

@Test(timeout=5000)
public void testJvmPauseMonitorExceedWarnThreshold() throws InterruptedException {
QuorumPeerConfig qpConfig = mock(QuorumPeerConfig.class);
when(qpConfig.getJvmPauseSleepTimeMs()).thenReturn(sleepTime);
when(qpConfig.getJvmPauseWarnThresholdMs()).thenReturn(warnTH);
when(qpConfig.getJvmPauseInfoThresholdMs()).thenReturn(infoTH);

JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(qpConfig);
pauseMonitor = new JvmPauseMonitor(qpConfig);
pauseMonitor.serviceStart();

Assert.assertEquals(sleepTime, Long.valueOf(pauseMonitor.sleepTimeMs));
Assert.assertEquals(warnTH, Long.valueOf(pauseMonitor.warnThresholdMs));
Assert.assertEquals(infoTH, Long.valueOf(pauseMonitor.infoThresholdMs));

while(pauseMonitor.getNumGcInfoThresholdExceeded() == 0 && pauseMonitor.getNumGcWarnThresholdExceeded() == 0) {
while(pauseMonitor.getNumGcWarnThresholdExceeded() == 0) {
Thread.sleep(200);
}

}

@After
public void teardown() {
pauseMonitor.serviceStop();
}
}

0 comments on commit a502086

Please sign in to comment.