|
@@ -27,6 +27,7 @@ import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang.UnhandledException;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -73,6 +74,7 @@ import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo.BlockStatus;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks;
|
|
|
import org.apache.hadoop.hdfs.tools.DFSAdmin;
|
|
|
+import org.apache.hadoop.hdfs.tools.JMXGet;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.io.nativeio.NativeIO;
|
|
|
import org.apache.hadoop.net.NetUtils;
|
|
@@ -1703,4 +1705,22 @@ public class DFSTestUtil {
|
|
|
lastBlock.setNumBytes(len);
|
|
|
return lastBlock;
|
|
|
}
|
|
|
+
|
|
|
+ public static void waitForMetric(final JMXGet jmx, final String metricName, final int expectedValue)
|
|
|
+ throws TimeoutException, InterruptedException {
|
|
|
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
+ @Override
|
|
|
+ public Boolean get() {
|
|
|
+ try {
|
|
|
+ final int currentValue = Integer.parseInt(jmx.getValue(metricName));
|
|
|
+ LOG.info("Waiting for " + metricName +
|
|
|
+ " to reach value " + expectedValue +
|
|
|
+ ", current value = " + currentValue);
|
|
|
+ return currentValue == expectedValue;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnhandledException("Test failed due to unexpected exception", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, Integer.MAX_VALUE);
|
|
|
+ }
|
|
|
}
|