|
@@ -30,6 +30,8 @@ import static org.junit.Assert.fail;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
+import java.lang.management.ThreadInfo;
|
|
|
+import java.lang.management.ThreadMXBean;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.URI;
|
|
|
import java.util.ArrayList;
|
|
@@ -74,6 +76,7 @@ import org.apache.hadoop.test.GenericTestUtils.DelayAnswer;
|
|
|
import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
|
import org.apache.log4j.Level;
|
|
|
+import org.junit.After;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.mockito.ArgumentMatcher;
|
|
@@ -115,6 +118,22 @@ public class TestCheckpoint {
|
|
|
CheckpointFaultInjector.instance = faultInjector;
|
|
|
}
|
|
|
|
|
|
+ @After
|
|
|
+ public void checkForSNNThreads() {
|
|
|
+ ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
|
|
|
+
|
|
|
+ ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
|
|
|
+ for (ThreadInfo info : infos) {
|
|
|
+ if (info == null) continue;
|
|
|
+ LOG.info("Check thread: " + info.getThreadName());
|
|
|
+ if (info.getThreadName().contains("SecondaryNameNode")) {
|
|
|
+ fail("Leaked thread: " + info + "\n" +
|
|
|
+ Joiner.on("\n").join(info.getStackTrace()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LOG.info("--------");
|
|
|
+ }
|
|
|
+
|
|
|
static void checkFile(FileSystem fileSys, Path name, int repl)
|
|
|
throws IOException {
|
|
|
assertTrue(fileSys.exists(name));
|
|
@@ -1738,7 +1757,7 @@ public class TestCheckpoint {
|
|
|
/**
|
|
|
* Test that the 2NN triggers a checkpoint after the configurable interval
|
|
|
*/
|
|
|
- @Test
|
|
|
+ @Test(timeout=30000)
|
|
|
public void testCheckpointTriggerOnTxnCount() throws Exception {
|
|
|
MiniDFSCluster cluster = null;
|
|
|
SecondaryNameNode secondary = null;
|
|
@@ -1752,8 +1771,7 @@ public class TestCheckpoint {
|
|
|
.format(true).build();
|
|
|
FileSystem fs = cluster.getFileSystem();
|
|
|
secondary = startSecondaryNameNode(conf);
|
|
|
- Thread t = new Thread(secondary);
|
|
|
- t.start();
|
|
|
+ secondary.startCheckpointThread();
|
|
|
final NNStorage storage = secondary.getFSImage().getStorage();
|
|
|
|
|
|
// 2NN should checkpoint at startup
|