Repository: hadoop Updated Branches: refs/heads/branch-2.9 dd1de1ea3 -> 8702882b5
HDFS-13028. RBF: Fix spurious TestRouterRpc#testProxyGetStats. Contributed by Inigo Goiri. (cherry picked from commit 130f8bce00e8cab59c3aa4d668e8bddd84544713) (cherry picked from commit c6139332f9d55ce176701e63426b158060c97d38) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8702882b Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8702882b Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8702882b Branch: refs/heads/branch-2.9 Commit: 8702882b5461b2e5fc151227ebf95747849b65e1 Parents: dd1de1e Author: Inigo Goiri <inigo...@apache.org> Authored: Fri Jan 19 09:47:40 2018 -0800 Committer: Inigo Goiri <inigo...@apache.org> Committed: Fri Jan 19 09:53:22 2018 -0800 ---------------------------------------------------------------------- .../server/federation/router/TestRouterRpc.java | 51 +++++++++++++++----- 1 file changed, 40 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8702882b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java index d1d6601..9937513 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java @@ -70,10 +70,16 @@ import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport; import org.apache.hadoop.io.EnumSetWritable; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.service.Service.STATE; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Supplier; +import com.google.common.collect.Maps; /** * The the RPC interface of the {@link Router} implemented by @@ -81,6 +87,9 @@ import org.junit.Test; */ public class TestRouterRpc { + private static final Logger LOG = + LoggerFactory.getLogger(TestRouterRpc.class); + /** Federated HDFS cluster. */ private static RouterDFSCluster cluster; @@ -469,9 +478,37 @@ public class TestRouterRpc { @Test public void testProxyGetStats() throws Exception { + // Some of the statistics are out of sync because of the mini cluster + Supplier<Boolean> check = new Supplier<Boolean>() { + @Override + public Boolean get() { + try { + long[] combinedData = routerProtocol.getStats(); + long[] individualData = getAggregateStats(); + int len = Math.min(combinedData.length, individualData.length); + for (int i = 0; i < len; i++) { + if (combinedData[i] != individualData[i]) { + LOG.error("Stats for {} don't match: {} != {}", + i, combinedData[i], individualData[i]); + return false; + } + } + return true; + } catch (Exception e) { + LOG.error("Cannot get stats: {}", e.getMessage()); + return false; + } + } + }; + GenericTestUtils.waitFor(check, 500, 5 * 1000); + } - long[] combinedData = routerProtocol.getStats(); - + /** + * Get the sum of each subcluster statistics. + * @return Aggregated statistics. + * @throws Exception If it cannot get the stats from the Router or Namenode. + */ + private long[] getAggregateStats() throws Exception { long[] individualData = new long[10]; for (String nameservice : cluster.getNameservices()) { NamenodeContext n = cluster.getNamenode(nameservice, null); @@ -481,16 +518,8 @@ public class TestRouterRpc { for (int i = 0; i < data.length; i++) { individualData[i] += data[i]; } - assert(data.length == combinedData.length); - } - - for (int i = 0; i < combinedData.length && i < individualData.length; i++) { - if (i == ClientProtocol.GET_STATS_REMAINING_IDX) { - // Skip available storage as this fluctuates in mini cluster - continue; - } - assertEquals(combinedData[i], individualData[i]); } + return individualData; } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org