You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:21:18 UTC

svn commit: r1181569 - in /hbase/branches/0.89/src/test: java/org/apache/hadoop/hbase/io/hfile/ resources/org/apache/hadoop/hbase/io/ resources/org/apache/hadoop/hbase/io/hfile/

Author: nspiegelberg
Date: Tue Oct 11 02:21:18 2011
New Revision: 1181569

URL: http://svn.apache.org/viewvc?rev=1181569&view=rev
Log:
A unit test to read a pre-existing version 1 binary HFile

Summary:
To make sure the version of HBase with HFile v2 changes stays compatible with
the legacy HFile format, we need to have a pre-existing binary HFile in the v1
format and a unit test that reads that binary file using the new HFile v1 reader
code.

Test Plan:
Run the unit test.

Reviewed By: kannan
Reviewers: kannan, gqchen
CC: hbase@lists, , kannan
Revert Plan:
OK

Differential Revision: 269117

Added:
    hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderV1.java
    hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/
    hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/
    hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/8e8ab58dcf39412da19833fcd8f687ac

Added: hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderV1.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderV1.java?rev=1181569&view=auto
==============================================================================
--- hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderV1.java (added)
+++ hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderV1.java Tue Oct 11 02:21:18 2011
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2011 The Apache Software Foundation
+ *
+ * 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.hbase.io.hfile;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestHFileReaderV1 {
+
+  private static final HBaseTestingUtility TEST_UTIL =
+    new HBaseTestingUtility();
+
+  private Configuration conf;
+  private FileSystem fs;
+
+  private static final int N = 1000;
+
+  @Before
+  public void setUp() throws IOException {
+    conf = TEST_UTIL.getConfiguration();
+    fs = FileSystem.get(conf);
+  }
+
+  @Test
+  public void testReadingExistingVersion1HFile() throws IOException {
+    URL url = TestHFileReaderV1.class.getResource(
+        "8e8ab58dcf39412da19833fcd8f687ac");
+    Path existingHFilePath = new Path(url.getPath());
+    HFile.Reader reader =
+      HFile.createReader(fs, existingHFilePath, null, false, false);
+    reader.loadFileInfo();
+    FixedFileTrailer trailer = reader.getTrailer();
+
+    assertEquals(N, reader.getEntries());
+    assertEquals(N, trailer.getEntryCount());
+    assertEquals(1, trailer.getVersion());
+    assertEquals(Compression.Algorithm.GZ, trailer.getCompressionCodec());
+
+    for (boolean pread : new boolean[] { false, true }) {
+      int totalDataSize = 0;
+      int n = 0;
+
+      HFileScanner scanner = reader.getScanner(false, pread);
+      assertTrue(scanner.seekTo());
+      do {
+        totalDataSize += scanner.getKey().limit() + scanner.getValue().limit()
+            + Bytes.SIZEOF_INT * 2;
+        ++n;
+      } while (scanner.next());
+
+      // Add magic record sizes, one per data block.
+      totalDataSize += 8 * trailer.getDataIndexCount();
+
+      assertEquals(N, n);
+      assertEquals(trailer.getTotalUncompressedBytes(), totalDataSize);
+    }
+    reader.close();
+  }
+
+}

Added: hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/8e8ab58dcf39412da19833fcd8f687ac
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/8e8ab58dcf39412da19833fcd8f687ac?rev=1181569&view=auto
==============================================================================
Files hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/8e8ab58dcf39412da19833fcd8f687ac (added) and hbase/branches/0.89/src/test/resources/org/apache/hadoop/hbase/io/hfile/8e8ab58dcf39412da19833fcd8f687ac Tue Oct 11 02:21:18 2011 differ