Modified: hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java?rev=1340622&r1=1340621&r2=1340622&view=diff ============================================================================== --- hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java (original) +++ hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java Sun May 20 06:12:14 2012 @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import java.util.List; @@ -36,6 +37,11 @@ import org.apache.hadoop.hdfs.server.nam import org.apache.hadoop.hdfs.server.namenode.NNStorage; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; +import org.apache.hadoop.hdfs.util.Canceler; +import org.apache.hadoop.io.compress.CompressionCodecFactory; +import org.apache.hadoop.io.compress.CompressionOutputStream; +import org.apache.hadoop.io.compress.GzipCodec; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -52,12 +58,18 @@ public class TestStandbyCheckpoints { private NameNode nn0, nn1; private FileSystem fs; + @SuppressWarnings("rawtypes") @Before public void setupCluster() throws Exception { Configuration conf = new Configuration(); conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 1); conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 5); conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); + conf.setBoolean(DFSConfigKeys.DFS_IMAGE_COMPRESS_KEY, true); + conf.set(DFSConfigKeys.DFS_IMAGE_COMPRESSION_CODEC_KEY, + SlowCodec.class.getCanonicalName()); + CompressionCodecFactory.setCodecClasses(conf, + ImmutableList.<Class>of(SlowCodec.class)); MiniDFSNNTopology topology = new MiniDFSNNTopology() .addNameservice(new MiniDFSNNTopology.NSConf("ns1") @@ -159,14 +171,15 @@ public class TestStandbyCheckpoints { // We should make exactly one checkpoint at this new txid. Mockito.verify(spyImage1, Mockito.times(1)) - .saveNamespace((FSNamesystem) Mockito.anyObject()); + .saveNamespace((FSNamesystem) Mockito.anyObject(), + (Canceler)Mockito.anyObject()); } /** * Test cancellation of ongoing checkpoints when failover happens * mid-checkpoint. */ - @Test + @Test(timeout=120000) public void testCheckpointCancellation() throws Exception { cluster.transitionToStandby(0); @@ -191,16 +204,18 @@ public class TestStandbyCheckpoints { cluster.transitionToActive(0); - for (int i = 0; i < 10; i++) { + boolean canceledOne = false; + for (int i = 0; i < 10 && !canceledOne; i++) { doEdits(i*10, i*10 + 10); cluster.transitionToStandby(0); cluster.transitionToActive(1); cluster.transitionToStandby(1); cluster.transitionToActive(0); + canceledOne = StandbyCheckpointer.getCanceledCount() > 0; } - assertTrue(StandbyCheckpointer.getCanceledCount() > 0); + assertTrue(canceledOne); } private void doEdits(int start, int stop) throws IOException { @@ -209,5 +224,22 @@ public class TestStandbyCheckpoints { fs.mkdirs(p); } } + + /** + * A codec which just slows down the saving of the image significantly + * by sleeping a few milliseconds on every write. This makes it easy to + * catch the standby in the middle of saving a checkpoint. + */ + public static class SlowCodec extends GzipCodec { + @Override + public CompressionOutputStream createOutputStream(OutputStream out) + throws IOException { + CompressionOutputStream ret = super.createOutputStream(out); + CompressionOutputStream spy = Mockito.spy(ret); + Mockito.doAnswer(new GenericTestUtils.SleepAnswer(2)) + .when(spy).write(Mockito.<byte[]>any(), Mockito.anyInt(), Mockito.anyInt()); + return spy; + } + } }
Modified: hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyIsHot.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyIsHot.java?rev=1340622&r1=1340621&r2=1340622&view=diff ============================================================================== --- hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyIsHot.java (original) +++ hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyIsHot.java Sun May 20 06:12:14 2012 @@ -42,7 +42,6 @@ import org.apache.hadoop.hdfs.protocol.L import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil; import org.apache.hadoop.hdfs.server.datanode.DataNode; -import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; @@ -70,7 +69,7 @@ public class TestStandbyIsHot { ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); } - @Test + @Test(timeout=60000) public void testStandbyIsHot() throws Exception { Configuration conf = new Configuration(); // We read from the standby to watch block locations @@ -111,6 +110,8 @@ public class TestStandbyIsHot { // Change replication LOG.info("Changing replication to 1"); fs.setReplication(TEST_FILE_PATH, (short)1); + BlockManagerTestUtil.computeAllPendingWork( + nn1.getNamesystem().getBlockManager()); waitForBlockLocations(cluster, nn1, TEST_FILE, 1); nn1.getRpcServer().rollEditLog(); @@ -121,6 +122,8 @@ public class TestStandbyIsHot { // Change back to 3 LOG.info("Changing replication to 3"); fs.setReplication(TEST_FILE_PATH, (short)3); + BlockManagerTestUtil.computeAllPendingWork( + nn1.getNamesystem().getBlockManager()); nn1.getRpcServer().rollEditLog(); LOG.info("Waiting for higher replication to show up on standby"); @@ -142,7 +145,7 @@ public class TestStandbyIsHot { * In the bug, the standby node would only very slowly notice the blocks returning * to the cluster. */ - @Test + @Test(timeout=60000) public void testDatanodeRestarts() throws Exception { Configuration conf = new Configuration(); conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024); @@ -224,17 +227,16 @@ public class TestStandbyIsHot { LOG.info("Got " + numReplicas + " locs: " + locs); if (numReplicas > expectedReplicas) { - for (DataNode dn : cluster.getDataNodes()) { - DataNodeTestUtils.triggerDeletionReport(dn); - } + cluster.triggerDeletionReports(); } + cluster.triggerHeartbeats(); return numReplicas == expectedReplicas; } catch (IOException e) { LOG.warn("No block locations yet: " + e.getMessage()); return false; } } - }, 500, 10000); + }, 500, 20000); } } Modified: hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestLightWeightHashSet.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestLightWeightHashSet.java?rev=1340622&r1=1340621&r2=1340622&view=diff ============================================================================== --- hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestLightWeightHashSet.java (original) +++ hadoop/common/branches/HDFS-3042/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestLightWeightHashSet.java Sun May 20 06:12:14 2012 @@ -421,5 +421,48 @@ public class TestLightWeightHashSet{ LOG.info("Test other - DONE"); } + + @Test + public void testGetElement() { + LightWeightHashSet<TestObject> objSet = new LightWeightHashSet<TestObject>(); + TestObject objA = new TestObject("object A"); + TestObject equalToObjA = new TestObject("object A"); + TestObject objB = new TestObject("object B"); + objSet.add(objA); + objSet.add(objB); + + assertSame(objA, objSet.getElement(objA)); + assertSame(objA, objSet.getElement(equalToObjA)); + assertSame(objB, objSet.getElement(objB)); + assertNull(objSet.getElement(new TestObject("not in set"))); + } + + /** + * Wrapper class which is used in + * {@link TestLightWeightHashSet#testGetElement()} + */ + private static class TestObject { + private final String value; + + public TestObject(String value) { + super(); + this.value = value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) + return false; + TestObject other = (TestObject) obj; + return this.value.equals(other.value); + } + } } \ No newline at end of file
