HFileGenerator { public static List<Path> generateHFiles(FileSystem sourceFileSystem, Configuration conf, File outputFolder, PartitionerType partitionerType, int numOfPartitions, int numOfKeys) throws IOException { StoreFile.Writer[] writers = new StoreFile.Writer[numOfPartitions]; for (int i = 0; i < numOfPartitions; i++) { writers[i] = new StoreFile.WriterBuilder(conf, new CacheConfig(conf), sourceFileSystem, 4096) .withFilePath(new Path(String.format("%s/%s", outputFolder.getAbsoluteFile(), TerrapinUtil.formatPartitionName(i)))) .withCompression(Compression.Algorithm.NONE) .build(); } Partitioner partitioner = PartitionerFactory.getPartitioner(partitionerType); for (int i = 0; i < numOfKeys; i++) { byte[] key = String.format("%06d", i).getBytes(); byte[] value; if (i <= 1) { value = "".getBytes(); } else { value = ("v" + (i + 1)).getBytes(); } KeyValue kv = new KeyValue(key, Bytes.toBytes("cf"), Bytes.toBytes(""), value); int partition = partitioner.getPartition(new BytesWritable(key), new BytesWritable(value), numOfPartitions); writers[partition].append(kv); } for (int i = 0; i < numOfPartitions; i++) { writers[i].close(); } return Lists.transform(Lists.newArrayList(writers), new Function<StoreFile.Writer, Path>() { @Override public Path apply(StoreFile.Writer writer) { return writer.getPath(); } }); }  static List<Path> generateHFiles(FileSystem sourceFileSystem, Configuration conf,
                                          File outputFolder, PartitionerType partitionerType,
                                          int numOfPartitions, int numOfKeys); static void main(String[] args);  }
@Test public void testGenerateHFiles() throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); int numOfPart = 10; int numOfKeys = 1000; HFileGenerator.generateHFiles(fs, conf, outputDir, PartitionerType.CASCADING, numOfPart, numOfKeys); FilenameFilter hfileFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith(Constants.FILE_PREFIX); } }; File[] hfiles = outputDir.listFiles(hfileFilter); assertEquals(numOfPart, hfiles.length); int count = 0; for(File hfile : hfiles) { HColumnDescriptor columnDescriptor = new HColumnDescriptor(); columnDescriptor.setBlockCacheEnabled(false); HFile.Reader reader = HFile.createReader(fs, new Path(hfile.toURI()), new CacheConfig(conf, columnDescriptor)); count += reader.getEntries(); reader.close(); } assertEquals(numOfKeys, count); }