HADOOP-13291. Probing stats in DFSOpsCountStatistics/S3AStorageStatistics 
should be correctly implemented. Contributed by Mingliang Liu.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b7c4cf71
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b7c4cf71
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b7c4cf71

Branch: refs/heads/HDFS-1312
Commit: b7c4cf7129768c0312b186dfb94ba1beb891e2f3
Parents: 5d58858
Author: Jitendra Pandey <jiten...@apache.org>
Authored: Mon Jun 20 16:00:13 2016 -0700
Committer: Jitendra Pandey <jiten...@apache.org>
Committed: Mon Jun 20 16:25:30 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hdfs/DFSOpsCountStatistics.java      |   5 +-
 .../hadoop/hdfs/TestDFSOpsCountStatistics.java  | 108 +++++++++++++++++++
 .../hadoop/fs/s3a/S3AStorageStatistics.java     |   5 +-
 3 files changed, 114 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b7c4cf71/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
index d58a59f..a047d34 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
@@ -139,7 +139,8 @@ public class DFSOpsCountStatistics extends 
StorageStatistics {
         throw new NoSuchElementException();
       }
       final Entry<OpType, AtomicLong> entry = iterator.next();
-      return new LongStatistic(entry.getKey().name(), entry.getValue().get());
+      return new LongStatistic(entry.getKey().getSymbol(),
+          entry.getValue().get());
     }
 
     @Override
@@ -161,7 +162,7 @@ public class DFSOpsCountStatistics extends 
StorageStatistics {
 
   @Override
   public boolean isTracked(String key) {
-    return OpType.fromSymbol(key) == null;
+    return OpType.fromSymbol(key) != null;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b7c4cf71/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
new file mode 100644
index 0000000..7c1b018
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdfs;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.hadoop.fs.StorageStatistics.LongStatistic;
+
+import org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType;
+
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.junit.rules.ExpectedException;
+import org.junit.rules.Timeout;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * This tests basic operations of {@link DFSOpsCountStatistics} class.
+ */
+public class TestDFSOpsCountStatistics {
+
+  private static final DFSOpsCountStatistics STORAGE_STATISTICS =
+      new DFSOpsCountStatistics();
+  private static final Map<String, Long> OP_COUNTER_MAP = new HashMap<>();
+  private static final String NO_SUCH_OP = "no-such-dfs-operation-dude";
+
+  @Rule
+  public final Timeout globalTimeout = new Timeout(10 * 1000);
+  @Rule
+  public final ExpectedException exception = ExpectedException.none();
+
+  @BeforeClass
+  public static void setup() {
+    for (OpType opType : OpType.values()) {
+      final Long opCount = RandomUtils.nextLong(0, 100);
+      OP_COUNTER_MAP.put(opType.getSymbol(), opCount);
+      for (long i = 0; i < opCount; i++) {
+        STORAGE_STATISTICS.incrementOpCounter(opType);
+      }
+    }
+  }
+
+  @Test
+  public void testGetLongStatistics() {
+    short iterations = 0; // number of the iter.hasNext()
+    final Iterator<LongStatistic> iter = 
STORAGE_STATISTICS.getLongStatistics();
+
+    while (iter.hasNext()) {
+      final LongStatistic longStat = iter.next();
+      assertNotNull(longStat);
+      assertTrue(OP_COUNTER_MAP.containsKey(longStat.getName()));
+      assertEquals(OP_COUNTER_MAP.get(longStat.getName()).longValue(),
+          longStat.getValue());
+      iterations++;
+    }
+
+    // check that all the OpType enum entries are iterated via iter
+    assertEquals(OpType.values().length, iterations);
+  }
+
+  @Test
+  public void testGetLong() {
+    assertNull(STORAGE_STATISTICS.getLong(NO_SUCH_OP));
+
+    for (OpType opType : OpType.values()) {
+      final String key = opType.getSymbol();
+      assertEquals(OP_COUNTER_MAP.get(key), STORAGE_STATISTICS.getLong(key));
+    }
+  }
+
+  @Test
+  public void testIsTracked() {
+    assertFalse(STORAGE_STATISTICS.isTracked(NO_SUCH_OP));
+
+    final Iterator<LongStatistic> iter = 
STORAGE_STATISTICS.getLongStatistics();
+    while (iter.hasNext()) {
+      final LongStatistic longStatistic = iter.next();
+      assertTrue(STORAGE_STATISTICS.isTracked(longStatistic.getName()));
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b7c4cf71/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AStorageStatistics.java
----------------------------------------------------------------------
diff --git 
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AStorageStatistics.java
 
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AStorageStatistics.java
index f69159a..a74b864 100644
--- 
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AStorageStatistics.java
+++ 
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AStorageStatistics.java
@@ -76,7 +76,8 @@ public class S3AStorageStatistics extends StorageStatistics {
         throw new NoSuchElementException();
       }
       final Map.Entry<Statistic, AtomicLong> entry = iterator.next();
-      return new LongStatistic(entry.getKey().name(), entry.getValue().get());
+      return new LongStatistic(entry.getKey().getSymbol(),
+          entry.getValue().get());
     }
 
     @Override
@@ -98,7 +99,7 @@ public class S3AStorageStatistics extends StorageStatistics {
 
   @Override
   public boolean isTracked(String key) {
-    return Statistic.fromSymbol(key) == null;
+    return Statistic.fromSymbol(key) != null;
   }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to