1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
public class HBaseUtilTest {
@Test public void createTable(){ HBaseUtil.createTable("FileTable", new String[]{"fileInfo", "saveInfo"}); }
@Test public void addFileDetails(){ HBaseUtil.putRow("FileTable", "rowkey1", "fileInfo", "name", "file1.txt"); HBaseUtil.putRow("FileTable", "rowkey1", "fileInfo", "type", "txt"); HBaseUtil.putRow("FileTable", "rowkey1", "fileInfo", "size", "1024"); HBaseUtil.putRow("FileTable", "rowkey1", "saveInfo", "creator", "suiwo1"); HBaseUtil.putRow("FileTable", "rowkey2", "fileInfo", "name", "file2.jpg"); HBaseUtil.putRow("FileTable", "rowkey2", "fileInfo", "type", "jpg"); HBaseUtil.putRow("FileTable", "rowkey2", "fileInfo", "size", "2048"); HBaseUtil.putRow("FileTable", "rowkey2", "saveInfo", "creator", "suiwo2"); }
@Test public void getFileDetails(){ Result result = HBaseUtil.getRow("FileTable", "rowkey1"); if(result != null){ System.out.println("rowkey = " + Bytes.toString(result.getRow())); System.out.println("fileName = " + Bytes.toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); } }
@Test public void scanFileDetail(){ ResultScanner scanner = HBaseUtil.getScanner("FileTable", "rowkey2", "rowkey2"); if(scanner != null){ scanner.forEach(result -> { System.out.println("rowkey = " + Bytes.toString(result.getRow())); System.out.println("fileName = " + Bytes.toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); }); scanner.close(); } }
@Test public void deleteRow(){ HBaseUtil.deleteRow("FileTable", "rowkey1"); }
@Test public void deleteTable(){ HBaseUtil.deleteTable("FileTable"); } }
|