1   /**
2    * Copyright 2007 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.regionserver;
21  
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.hadoop.hbase.HBaseConfiguration;
27  import org.apache.hadoop.hbase.client.Put;
28  
29  /**
30   * A region server that will OOME.
31   * Everytime {@link #put(regionName, Put)} is called, we add
32   * keep around a reference to the batch.  Use this class to test OOME extremes.
33   * Needs to be started manually as in
34   * <code>${HBASE_HOME}/bin/hbase ./bin/hbase org.apache.hadoop.hbase.OOMERegionServer start</code>.
35   */
36  public class OOMERegionServer extends HRegionServer {
37    private List<Put> retainer = new ArrayList<Put>();
38  
39    public OOMERegionServer(HBaseConfiguration conf) throws IOException, InterruptedException {
40      super(conf);
41    }
42  
43    public void put(byte [] regionName, Put put)
44    throws IOException {
45      super.put(regionName, put);
46      for (int i = 0; i < 30; i++) {
47        // Add the batch update 30 times to bring on the OOME faster.
48        this.retainer.add(put);
49      }
50    }
51  
52    public static void main(String[] args) throws Exception {
53      new HRegionServerCommandLine(OOMERegionServer.class).doMain(args);
54    }
55  }