You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/08 05:41:15 UTC
svn commit: r1079165 - in
/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs:
FCStatisticsBaseTest.java TestLocalFsFCStatistics.java
Author: omalley
Date: Tue Mar 8 04:41:14 2011
New Revision: 1079165
URL: http://svn.apache.org/viewvc?rev=1079165&view=rev
Log:
commit bc66a0dcd8233b7ead17dd0087bcdac58c32feb3
Author: Jitendra Nath Pandey <jitendra@sufferhome-lm.(none)>
Date: Tue Feb 1 16:40:24 2011 -0800
HADOOP-6432. Add Statistics support in FileContext.
from https://issues.apache.org/jira/secure/attachment/12469995/HADOOP-6432-trunk.8.patch
Added:
hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FCStatisticsBaseTest.java
hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestLocalFsFCStatistics.java
Added: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FCStatisticsBaseTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FCStatisticsBaseTest.java?rev=1079165&view=auto
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FCStatisticsBaseTest.java (added)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FCStatisticsBaseTest.java Tue Mar 8 04:41:14 2011
@@ -0,0 +1,100 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import org.apache.hadoop.fs.FileSystem.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.hadoop.fs.FileContextTestHelper.*;
+
+/**
+ * <p>
+ * Base class to test {@link FileContext} Statistics.
+ * </p>
+ */
+public abstract class FCStatisticsBaseTest {
+
+ static protected int blockSize = 512;
+ static protected int numBlocks = 1;
+
+ //fc should be set appropriately by the deriving test.
+ protected static FileContext fc = null;
+
+ @Test
+ public void testStatistics() throws IOException, URISyntaxException {
+ URI fsUri = getFsUri();
+ Statistics stats = FileContext.getStatistics(fsUri);
+ Assert.assertEquals(0, stats.getBytesRead());
+ Path filePath = getTestRootPath(fc, "file1");
+ createFile(fc, filePath, numBlocks, blockSize);
+
+ Assert.assertEquals(0, stats.getBytesRead());
+ verifyWrittenBytes(stats);
+ FSDataInputStream fstr = fc.open(filePath);
+ byte[] buf = new byte[blockSize];
+ int bytesRead = fstr.read(buf, 0, blockSize);
+ Assert.assertEquals(blockSize, bytesRead);
+ verifyReadBytes(stats);
+ verifyWrittenBytes(stats);
+ verifyReadBytes(FileContext.getStatistics(getFsUri()));
+ Map<URI, Statistics> statsMap = FileContext.getAllStatistics();
+ URI exactUri = getSchemeAuthorityUri();
+ verifyWrittenBytes(statsMap.get(exactUri));
+ fc.delete(filePath, true);
+ }
+
+ /**
+ * Bytes read may be different for different file systems. This method should
+ * throw assertion error if bytes read are incorrect.
+ *
+ * @param stats
+ */
+ protected abstract void verifyReadBytes(Statistics stats);
+
+ /**
+ * Bytes written may be different for different file systems. This method should
+ * throw assertion error if bytes written are incorrect.
+ *
+ * @param stats
+ */
+ protected abstract void verifyWrittenBytes(Statistics stats);
+
+ /**
+ * Returns the filesystem uri. Should be set
+ * @return URI
+ */
+ protected abstract URI getFsUri();
+
+ protected URI getSchemeAuthorityUri() {
+ URI uri = getFsUri();
+ String SchemeAuthString = uri.getScheme() + "://";
+ if (uri.getAuthority() == null) {
+ SchemeAuthString += "/";
+ } else {
+ SchemeAuthString += uri.getAuthority();
+ }
+ return URI.create(SchemeAuthString);
+ }
+}
Added: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestLocalFsFCStatistics.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestLocalFsFCStatistics.java?rev=1079165&view=auto
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestLocalFsFCStatistics.java (added)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestLocalFsFCStatistics.java Tue Mar 8 04:41:14 2011
@@ -0,0 +1,63 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.fs;
+
+import java.net.URI;
+
+import org.apache.hadoop.fs.FileSystem.Statistics;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+
+import static org.apache.hadoop.fs.FileContextTestHelper.*;
+
+/**
+ * <p>
+ * Tests the File Context Statistics for {@link LocalFileSystem}
+ * </p>
+ */
+public class TestLocalFsFCStatistics extends FCStatisticsBaseTest {
+
+ static final String LOCAL_FS_ROOT_URI = "file:///tmp/test";
+
+ @Before
+ public void setUp() throws Exception {
+ fc = FileContext.getLocalFSFileContext();
+ fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ fc.delete(getTestRootPath(fc, "test"), true);
+ }
+
+ protected void verifyReadBytes(Statistics stats) {
+ Assert.assertEquals(blockSize, stats.getBytesRead());
+ }
+
+ protected void verifyWrittenBytes(Statistics stats) {
+ //Extra 12 bytes are written apart from the block.
+ Assert.assertEquals(blockSize + 12, stats.getBytesWritten());
+ }
+
+ protected URI getFsUri() {
+ return URI.create(LOCAL_FS_ROOT_URI);
+ }
+
+}