001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with this 004 * work for additional information regarding copyright ownership. The ASF 005 * licenses this file to you under the Apache License, Version 2.0 (the 006 * "License"); you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017package org.apache.hadoop.hbase; 018 019import java.util.Arrays; 020import java.util.HashSet; 021import java.util.Set; 022import java.util.Collections; 023 024import org.apache.hadoop.hbase.util.Bytes; 025 026/** 027 * Similar to {@link HConstants} but for tests. Also provides some simple 028 * static utility functions to generate test data. 029 */ 030public class HTestConst { 031 032 private HTestConst() { 033 } 034 035 public static final String DEFAULT_TABLE_STR = "MyTestTable"; 036 public static final byte[] DEFAULT_TABLE_BYTES = Bytes.toBytes(DEFAULT_TABLE_STR); 037 public static final TableName DEFAULT_TABLE = 038 TableName.valueOf(DEFAULT_TABLE_BYTES); 039 040 public static final String DEFAULT_CF_STR = "MyDefaultCF"; 041 public static final byte[] DEFAULT_CF_BYTES = Bytes.toBytes(DEFAULT_CF_STR); 042 043 public static final Set<String> DEFAULT_CF_STR_SET = 044 Collections.unmodifiableSet(new HashSet<>( 045 Arrays.asList(new String[] { DEFAULT_CF_STR }))); 046 047 public static final String DEFAULT_ROW_STR = "MyTestRow"; 048 public static final byte[] DEFAULT_ROW_BYTES = Bytes.toBytes(DEFAULT_ROW_STR); 049 050 public static final String DEFAULT_QUALIFIER_STR = "MyColumnQualifier"; 051 public static final byte[] DEFAULT_QUALIFIER_BYTES = Bytes.toBytes(DEFAULT_QUALIFIER_STR); 052 053 public static String DEFAULT_VALUE_STR = "MyTestValue"; 054 public static byte[] DEFAULT_VALUE_BYTES = Bytes.toBytes(DEFAULT_VALUE_STR); 055 056 /** 057 * Generate the given number of unique byte sequences by appending numeric 058 * suffixes (ASCII representations of decimal numbers). 059 */ 060 public static byte[][] makeNAscii(byte[] base, int n) { 061 byte [][] ret = new byte[n][]; 062 for (int i = 0; i < n; i++) { 063 byte[] tail = Bytes.toBytes(Integer.toString(i)); 064 ret[i] = Bytes.add(base, tail); 065 } 066 return ret; 067 } 068 069}