View Javadoc

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;
18  
19  import java.util.Arrays;
20  import java.util.HashSet;
21  import java.util.Set;
22  import java.util.Collections;
23  
24  import org.apache.hadoop.hbase.util.Bytes;
25  
26  /**
27   * Similar to {@link HConstants} but for tests. Also provides some simple
28   * static utility functions to generate test data.
29   */
30  public class HTestConst {
31  
32    private HTestConst() {
33    }
34  
35    public static final String DEFAULT_TABLE_STR = "MyTestTable";
36    public static final byte[] DEFAULT_TABLE_BYTES = Bytes.toBytes(DEFAULT_TABLE_STR);
37    public static final TableName DEFAULT_TABLE =
38        TableName.valueOf(DEFAULT_TABLE_BYTES);
39  
40    public static final String DEFAULT_CF_STR = "MyDefaultCF";
41    public static final byte[] DEFAULT_CF_BYTES = Bytes.toBytes(DEFAULT_CF_STR);
42  
43    public static final Set<String> DEFAULT_CF_STR_SET =
44        Collections.unmodifiableSet(new HashSet<String>(
45            Arrays.asList(new String[] { DEFAULT_CF_STR })));
46  
47    public static final String DEFAULT_ROW_STR = "MyTestRow";
48    public static final byte[] DEFAULT_ROW_BYTES = Bytes.toBytes(DEFAULT_ROW_STR);
49  
50    public static final String DEFAULT_QUALIFIER_STR = "MyColumnQualifier";
51    public static final byte[] DEFAULT_QUALIFIER_BYTES = Bytes.toBytes(DEFAULT_QUALIFIER_STR);
52  
53    public static String DEFAULT_VALUE_STR = "MyTestValue";
54    public static byte[] DEFAULT_VALUE_BYTES = Bytes.toBytes(DEFAULT_VALUE_STR);
55  
56    /**
57     * Generate the given number of unique byte sequences by appending numeric
58     * suffixes (ASCII representations of decimal numbers).
59     */
60    public static byte[][] makeNAscii(byte[] base, int n) {
61      byte [][] ret = new byte[n][];
62      for (int i = 0; i < n; i++) {
63        byte[] tail = Bytes.toBytes(Integer.toString(i));
64        ret[i] = Bytes.add(base, tail);
65      }
66      return ret;
67    }
68  
69  }