You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bigtop.apache.org by rv...@apache.org on 2012/06/16 02:01:22 UTC

svn commit: r1350830 - /incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java

Author: rvs
Date: Sat Jun 16 00:01:22 2012
New Revision: 1350830

URL: http://svn.apache.org/viewvc?rev=1350830&view=rev
Log:
BIGTOP-619. Add HBase CopyTable test (Stephen Chu via rvs)

Added:
    incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java

Added: incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java?rev=1350830&view=auto
==============================================================================
--- incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java (added)
+++ incubator/bigtop/trunk/bigtop-tests/test-artifacts/hbase/src/main/groovy/org/apache/bigtop/itest/hbase/smoke/TestCopyTable.java Sat Jun 16 00:01:22 2012
@@ -0,0 +1,109 @@
+/**
+ * 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.bigtop.itest.hbase.smoke;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import org.apache.bigtop.itest.shell.Shell;
+import org.apache.bigtop.itest.hbase.util.HBaseTestUtil;
+import static org.apache.bigtop.itest.LogErrorsUtils.logError;
+
+public class TestCopyTable {
+  private static Shell sh = new Shell("/bin/bash -s");
+
+  private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
+  private static final byte[] TEST_QUALIFIER = Bytes.toBytes("q1");
+  private static final byte[] TEST_VALUE = Bytes.toBytes("v1");
+
+  private static byte[] orig;
+  private static byte[] copy;
+  private static HTable origTable;
+  private static HTable copyTable;
+  private static String copyTableCmd =
+    "hbase org.apache.hadoop.hbase.mapreduce.CopyTable";
+
+  private static int NUM_ROWS = 5000;
+  private static Configuration conf;
+  private static HBaseAdmin admin;
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    conf = HBaseConfiguration.create();
+    admin = new HBaseAdmin(conf);
+
+    HTableDescriptor htd_orig =
+      HBaseTestUtil.createTestTableDescriptor("orig", TEST_FAMILY);
+    admin.createTable(htd_orig);
+    orig = htd_orig.getName();
+
+    HTableDescriptor htd_copy =
+      HBaseTestUtil.createTestTableDescriptor("copy", TEST_FAMILY);
+    admin.createTable(htd_copy);
+    copy = htd_copy.getName();
+
+    copyTable = new HTable(conf, copy);
+    origTable = new HTable(conf, orig);
+    // Write some rows to the table that will be copied.
+    for (int i = 0; i < NUM_ROWS; i++) {
+      byte[] row = Bytes.toBytes("row_" + i);
+      Put p = new Put(row);
+      for (HColumnDescriptor hcd : htd_orig.getFamilies()) {
+        p.add(hcd.getName(), TEST_QUALIFIER, TEST_VALUE);
+      }
+      origTable.put(p);
+    }
+    origTable.flushCommits();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    admin.disableTable(orig);
+    admin.deleteTable(orig);
+    admin.disableTable(copy);
+    admin.deleteTable(copy);
+  }
+
+  /**
+   * Validates the CopyTable utility.
+   */
+  @Test
+  public void testCopyTable() throws Exception {
+    sh.exec(copyTableCmd + " --new.name=" + new String(copy) +
+      " " + new String(orig));
+    logError(sh);
+    assertTrue(sh.getRet() == 0);
+
+    String origDigest = HBaseTestUtil.checksumRows(origTable);
+    String copyDigest = HBaseTestUtil.checksumRows(copyTable);
+    assertTrue("Original and copy tables contain different data",
+               origDigest.equals(copyDigest));
+  }
+}