|
@@ -19,11 +19,13 @@ package org.apache.hadoop.hdfs.server.federation.metrics;
|
|
|
|
|
|
import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.getBean;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
+import static org.junit.Assert.assertNotEquals;
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
-import static org.junit.Assert.assertFalse;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -31,6 +33,7 @@ import javax.management.MalformedObjectNameException;
|
|
|
|
|
|
import org.apache.commons.collections.ListUtils;
|
|
|
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.protocol.NamenodeHeartbeatRequest;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.records.MembershipStats;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
|
|
@@ -58,6 +61,7 @@ public class TestRBFMetrics extends TestMetricsBase {
|
|
|
FederationMBean federationBean = getBean(FEDERATION_BEAN,
|
|
|
FederationMBean.class);
|
|
|
validateClusterStatsFederationBean(federationBean);
|
|
|
+ testCapacity(federationBean);
|
|
|
RouterMBean routerBean = getBean(ROUTER_BEAN, RouterMBean.class);
|
|
|
validateClusterStatsRouterBean(routerBean);
|
|
|
}
|
|
@@ -348,4 +352,34 @@ public class TestRBFMetrics extends TestMetricsBase {
|
|
|
assertTrue(bean.getHostAndPort().length() > 0);
|
|
|
assertFalse(bean.isSecurityEnabled());
|
|
|
}
|
|
|
+
|
|
|
+ private void testCapacity(FederationMBean bean) throws IOException {
|
|
|
+ List<MembershipState> memberships = getActiveMemberships();
|
|
|
+ assertTrue(memberships.size() > 1);
|
|
|
+
|
|
|
+ BigInteger availableCapacity = BigInteger.valueOf(0);
|
|
|
+ BigInteger totalCapacity = BigInteger.valueOf(0);
|
|
|
+ BigInteger unitCapacity = BigInteger.valueOf(Long.MAX_VALUE);
|
|
|
+ for (MembershipState mock : memberships) {
|
|
|
+ MembershipStats stats = mock.getStats();
|
|
|
+ stats.setTotalSpace(Long.MAX_VALUE);
|
|
|
+ stats.setAvailableSpace(Long.MAX_VALUE);
|
|
|
+ // reset stats to make the new value persistent
|
|
|
+ mock.setStats(stats);
|
|
|
+ // write back the new namenode information to state store
|
|
|
+ assertTrue(refreshNamenodeRegistration(
|
|
|
+ NamenodeHeartbeatRequest.newInstance(mock)));
|
|
|
+ totalCapacity = totalCapacity.add(unitCapacity);
|
|
|
+ availableCapacity = availableCapacity.add(unitCapacity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // for local cache update
|
|
|
+ assertEquals(totalCapacity, bean.getTotalCapacityBigInt());
|
|
|
+ // not equal since overflow happened.
|
|
|
+ assertNotEquals(totalCapacity, BigInteger.valueOf(bean.getTotalCapacity()));
|
|
|
+ assertEquals(availableCapacity, bean.getRemainingCapacityBigInt());
|
|
|
+ // not equal since overflow happened.
|
|
|
+ assertNotEquals(availableCapacity,
|
|
|
+ BigInteger.valueOf(bean.getRemainingCapacity()));
|
|
|
+ }
|
|
|
}
|