1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with this
4    * work for additional information regarding copyright ownership. The ASF
5    * licenses this file to you under the Apache License, Version 2.0 (the
6    * "License"); you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations
15   * under the License.
16   */
17  package org.apache.hadoop.hbase.io.encoding;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.apache.hadoop.hbase.HColumnDescriptor;
23  import org.apache.hadoop.hbase.MediumTests;
24  import org.apache.hadoop.hbase.client.HBaseAdmin;
25  import org.apache.hadoop.hbase.io.hfile.CacheConfig;
26  import org.apache.hadoop.hbase.io.hfile.Compression;
27  import org.apache.hadoop.hbase.regionserver.HRegionServer;
28  import org.apache.hadoop.hbase.util.TestMiniClusterLoadSequential;
29  import org.apache.hadoop.hbase.util.Threads;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  import org.junit.runners.Parameterized.Parameters;
33  
34  /**
35   * Uses the load tester
36   */
37  @Category(MediumTests.class)
38  public class TestLoadAndSwitchEncodeOnDisk extends
39      TestMiniClusterLoadSequential {
40  
41    /** We do not alternate the multi-put flag in this test. */
42    private static final boolean USE_MULTI_PUT = true;
43  
44    /** Un-parameterize the test */
45    @Parameters
46    public static Collection<Object[]> parameters() {
47      return Arrays.asList(new Object[][]{ new Object[0] });
48    }
49  
50    public TestLoadAndSwitchEncodeOnDisk() {
51      super(USE_MULTI_PUT, DataBlockEncoding.PREFIX);
52      conf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, true);
53    }
54  
55    protected int numKeys() {
56      return 3000;
57    }
58  
59    @Test(timeout=TIMEOUT_MS)
60    public void loadTest() throws Exception {
61      HBaseAdmin admin = new HBaseAdmin(conf);
62  
63      compression = Compression.Algorithm.GZ; // used for table setup
64      super.loadTest();
65  
66      HColumnDescriptor hcd = getColumnDesc(admin);
67      System.err.println("\nDisabling encode-on-disk. Old column descriptor: " +
68          hcd + "\n");
69      admin.disableTable(TABLE);
70      hcd.setEncodeOnDisk(false);
71      admin.modifyColumn(TABLE, hcd);
72  
73      System.err.println("\nRe-enabling table\n");
74      admin.enableTable(TABLE);
75  
76      System.err.println("\nNew column descriptor: " +
77          getColumnDesc(admin) + "\n");
78  
79      System.err.println("\nCompacting the table\n");
80      admin.majorCompact(TABLE);
81      // Wait until compaction completes
82      Threads.sleepWithoutInterrupt(5000);
83      HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
84      while (rs.compactSplitThread.getCompactionQueueSize() > 0) {
85        Threads.sleep(50);
86      }
87  
88      System.err.println("\nDone with the test, shutting down the cluster\n");
89    }
90  
91  }