You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2012/12/04 00:26:51 UTC

svn commit: r1416728 - in /hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook: TestCompactionHook.java TestLowerToUpperCompactionHook.java TestSkipCompactionHook.java

Author: liyin
Date: Mon Dec  3 23:26:50 2012
New Revision: 1416728

URL: http://svn.apache.org/viewvc?rev=1416728&view=rev
Log:
[HBASE-7099] [89-fb] Fix TestCompactionHook fail

Author: adela

Summary:
under jdk7 one of the test cases (the one which is executed
second) is sometimes failing sometimes
not. Looks like the update on the configuration didn't take effect on
time, so there is a KV without updated value.
This diff separates the two tests in different Java classes, since it
looks like a method wrapped with @Before annotation will take the same effect on
all test cases (and here we don't want that).

Test Plan: run the tests

Reviewers: kannan, kranganathan

Reviewed By: kranganathan

CC: hbase-eng@

Differential Revision: https://phabricator.fb.com/D645053

Task ID: 1928247

Added:
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestLowerToUpperCompactionHook.java
      - copied, changed from r1416727, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestSkipCompactionHook.java
      - copied, changed from r1416727, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java
Modified:
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java?rev=1416728&r1=1416727&r2=1416728&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java Mon Dec  3 23:26:50 2012
@@ -1,145 +0,0 @@
-/**
- * Copyright The Apache Software Foundation.
- *
- *  Licensed 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.regionserver.compactionhook;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.hadoop.hbase.HBaseTestCase;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.io.hfile.Compression;
-import org.apache.hadoop.hbase.regionserver.HRegion;
-import org.apache.hadoop.hbase.regionserver.InternalScanner;
-import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-@SuppressWarnings("deprecation")
-public class TestCompactionHook {
-
-  private static byte[] TABLE = Bytes.toBytes("TestCompactionHook");
-  private static byte[] FAMILY = Bytes.toBytes("family");
-  private static byte[] START_KEY = Bytes.toBytes("aaa");
-  private static byte[] END_KEY = Bytes.toBytes("zzz");
-  private static int BLOCK_SIZE = 70;
-
-  private static HBaseTestingUtility TEST_UTIL = null;
-  private static HTableDescriptor TESTTABLEDESC = null;
-
-  @BeforeClass
-  public static void setUpBeforeClass() throws Exception {
-    SchemaMetrics.setUseTableNameInTest(true);
-    TEST_UTIL = new HBaseTestingUtility();
-    TESTTABLEDESC = new HTableDescriptor(TABLE);
-
-    TESTTABLEDESC.addFamily(new HColumnDescriptor(FAMILY).setMaxVersions(10)
-        .setBlockCacheEnabled(true).setBlocksize(BLOCK_SIZE)
-        .setCompressionType(Compression.Algorithm.NONE));
-    TEST_UTIL
-        .getConfiguration()
-        .set(
-            HConstants.COMPACTION_HOOK,
-            "org.apache.hadoop.hbase.regionserver.compactionhook.LowerToUpperCompactionHook");
-  }
-
-  @Test
-  public void testLowerToUpperHook() throws Exception {
-    HRegion r = HBaseTestCase.createNewHRegion(TESTTABLEDESC, START_KEY,
-        END_KEY, TEST_UTIL.getConfiguration());
-    Put[] puts = new Put[25];
-    // put some lowercase strings
-    for (int i = 0; i < 25; i++) {
-      byte[] row = Bytes.toBytes("row" + i);
-      Put put = new Put(row);
-      byte[] qualifier = Bytes.toBytes("qual" + i);
-      byte[] value = Bytes.toBytes("ab" + (char) (i + 97));
-      put.add(FAMILY, qualifier, value);
-      puts[i] = put;
-    }
-    r.put(puts);
-    // without calling this, the compaction will not happen
-    r.flushcache();
-    r.compactStores(true);
-    //
-    Scan scan = new Scan();
-    InternalScanner s = r.getScanner(scan);
-    List<KeyValue> results = new ArrayList<KeyValue>();
-    while (s.next(results))
-      ;
-    s.close();
-    // check if the values in results are in upper case
-    // this should return true, we are flushing the HRegion, so we expect the
-    // compaction to be done
-    Assert.assertTrue(checkIfLowerCase(results));
-    // check if we got all 25 results back
-    Assert.assertEquals(25, results.size());
-  }
-
-  public boolean checkIfLowerCase(List<KeyValue> result) {
-    for (KeyValue kv : result) {
-      String currValue = new String(kv.getValue());
-      String uppercase = currValue.toUpperCase();
-      if (!currValue.equals(uppercase)) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  @Test
-  public void testSkipHook () throws Exception {
-    TEST_UTIL
-    .getConfiguration()
-    .set(
-        HConstants.COMPACTION_HOOK,
-        "org.apache.hadoop.hbase.regionserver.compactionhook.SkipCompactionHook");
-    HRegion r = HBaseTestCase.createNewHRegion(TESTTABLEDESC, START_KEY,
-        END_KEY, TEST_UTIL.getConfiguration());
-    Put[] puts = new Put[25];
-    // put some strings
-    for (int i = 0; i < 25; i++) {
-      byte[] row = Bytes.toBytes("row" + i);
-      Put put = new Put(row);
-      byte[] qualifier = Bytes.toBytes("qual" + i);
-      byte[] value = Bytes.toBytes("ab" + (char) (i + 97));
-      put.add(FAMILY, qualifier, value);
-      puts[i] = put;
-    }
-    r.put(puts);
-    // without calling this, the compaction will not happen
-    r.flushcache();
-    r.compactStores(true);
-    //
-    Scan scan = new Scan();
-    InternalScanner s = r.getScanner(scan);
-    List<KeyValue> results = new ArrayList<KeyValue>();
-    while (s.next(results))
-      ;
-    s.close();
-    // check if we got 24 results back, since "abc" should be skipped.
-    Assert.assertEquals(24, results.size());
-  }
-
-}

Copied: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestLowerToUpperCompactionHook.java (from r1416727, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java)
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestLowerToUpperCompactionHook.java?p2=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestLowerToUpperCompactionHook.java&p1=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java&r1=1416727&r2=1416728&rev=1416728&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestLowerToUpperCompactionHook.java Mon Dec  3 23:26:50 2012
@@ -37,7 +37,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 @SuppressWarnings("deprecation")
-public class TestCompactionHook {
+public class TestLowerToUpperCompactionHook {
 
   private static byte[] TABLE = Bytes.toBytes("TestCompactionHook");
   private static byte[] FAMILY = Bytes.toBytes("family");
@@ -108,38 +108,4 @@ public class TestCompactionHook {
     return true;
   }
 
-  @Test
-  public void testSkipHook () throws Exception {
-    TEST_UTIL
-    .getConfiguration()
-    .set(
-        HConstants.COMPACTION_HOOK,
-        "org.apache.hadoop.hbase.regionserver.compactionhook.SkipCompactionHook");
-    HRegion r = HBaseTestCase.createNewHRegion(TESTTABLEDESC, START_KEY,
-        END_KEY, TEST_UTIL.getConfiguration());
-    Put[] puts = new Put[25];
-    // put some strings
-    for (int i = 0; i < 25; i++) {
-      byte[] row = Bytes.toBytes("row" + i);
-      Put put = new Put(row);
-      byte[] qualifier = Bytes.toBytes("qual" + i);
-      byte[] value = Bytes.toBytes("ab" + (char) (i + 97));
-      put.add(FAMILY, qualifier, value);
-      puts[i] = put;
-    }
-    r.put(puts);
-    // without calling this, the compaction will not happen
-    r.flushcache();
-    r.compactStores(true);
-    //
-    Scan scan = new Scan();
-    InternalScanner s = r.getScanner(scan);
-    List<KeyValue> results = new ArrayList<KeyValue>();
-    while (s.next(results))
-      ;
-    s.close();
-    // check if we got 24 results back, since "abc" should be skipped.
-    Assert.assertEquals(24, results.size());
-  }
-
 }

Copied: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestSkipCompactionHook.java (from r1416727, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java)
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestSkipCompactionHook.java?p2=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestSkipCompactionHook.java&p1=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java&r1=1416727&r2=1416728&rev=1416728&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestCompactionHook.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/compactionhook/TestSkipCompactionHook.java Mon Dec  3 23:26:50 2012
@@ -37,7 +37,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 @SuppressWarnings("deprecation")
-public class TestCompactionHook {
+public class TestSkipCompactionHook {
 
   private static byte[] TABLE = Bytes.toBytes("TestCompactionHook");
   private static byte[] FAMILY = Bytes.toBytes("family");
@@ -61,60 +61,11 @@ public class TestCompactionHook {
         .getConfiguration()
         .set(
             HConstants.COMPACTION_HOOK,
-            "org.apache.hadoop.hbase.regionserver.compactionhook.LowerToUpperCompactionHook");
-  }
-
-  @Test
-  public void testLowerToUpperHook() throws Exception {
-    HRegion r = HBaseTestCase.createNewHRegion(TESTTABLEDESC, START_KEY,
-        END_KEY, TEST_UTIL.getConfiguration());
-    Put[] puts = new Put[25];
-    // put some lowercase strings
-    for (int i = 0; i < 25; i++) {
-      byte[] row = Bytes.toBytes("row" + i);
-      Put put = new Put(row);
-      byte[] qualifier = Bytes.toBytes("qual" + i);
-      byte[] value = Bytes.toBytes("ab" + (char) (i + 97));
-      put.add(FAMILY, qualifier, value);
-      puts[i] = put;
-    }
-    r.put(puts);
-    // without calling this, the compaction will not happen
-    r.flushcache();
-    r.compactStores(true);
-    //
-    Scan scan = new Scan();
-    InternalScanner s = r.getScanner(scan);
-    List<KeyValue> results = new ArrayList<KeyValue>();
-    while (s.next(results))
-      ;
-    s.close();
-    // check if the values in results are in upper case
-    // this should return true, we are flushing the HRegion, so we expect the
-    // compaction to be done
-    Assert.assertTrue(checkIfLowerCase(results));
-    // check if we got all 25 results back
-    Assert.assertEquals(25, results.size());
-  }
-
-  public boolean checkIfLowerCase(List<KeyValue> result) {
-    for (KeyValue kv : result) {
-      String currValue = new String(kv.getValue());
-      String uppercase = currValue.toUpperCase();
-      if (!currValue.equals(uppercase)) {
-        return false;
-      }
-    }
-    return true;
+            "org.apache.hadoop.hbase.regionserver.compactionhook.SkipCompactionHook");
   }
 
   @Test
   public void testSkipHook () throws Exception {
-    TEST_UTIL
-    .getConfiguration()
-    .set(
-        HConstants.COMPACTION_HOOK,
-        "org.apache.hadoop.hbase.regionserver.compactionhook.SkipCompactionHook");
     HRegion r = HBaseTestCase.createNewHRegion(TESTTABLEDESC, START_KEY,
         END_KEY, TEST_UTIL.getConfiguration());
     Put[] puts = new Put[25];