Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.HTableInterface


    /**
     * Test that the wrapped ResultScanner.next(int) works, and also ResultScanner.close()
     */
    @Test
    public void testResultScannerIteratorHasNext() throws Exception {
        HTableInterface hTable = getHTable();
        byte[] row = randomRowKey();

        Put put = new Put(row);
        put.add(cf, row, row);
        hTable.put(put);

        ResultScanner rs = hTable.getScanner(new Scan());

        Assert.assertTrue(rs.iterator().hasNext());

        rs.close();

View Full Code Here


    /**
     * Test getScanner(byte[] family)
     */
    @Test
    public void testGetScannerCfName() throws Exception {
        HTableInterface hTable = getHTable();
        byte[] row = randomRowKey();

        Put put = new Put(row);
        put.add(cf, row, row);
        hTable.put(put);

        ResultScanner rs = hTable.getScanner(cf);

        Assert.assertNotNull(rs.next());

        assertMetricsUpdated(OpType.PUT, OpType.GET_SCANNER, OpType.RESULTSCANNER_NEXT);
       
View Full Code Here

   /**
    * Test getScanner(byte[] family)
    */
   @Test
   public void testGetScannerCfAndQual() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       byte[] qual = randomRowKey();

       Put put = new Put(row);
       put.add(cf, qual, row);
       hTable.put(put);

       ResultScanner rs = hTable.getScanner(cf, qual);

       Assert.assertNotNull(rs.next());

       assertMetricsUpdated(OpType.PUT, OpType.GET_SCANNER, OpType.RESULTSCANNER_NEXT);

View Full Code Here

       rs.close();
   }
  
   @Test
   public void testMultiPut() throws Exception {
       HTableInterface hTable = getHTable();
       List<byte[]> rows = getRandomRows(2);

       Put put1 = new Put(rows.get(0));
       Put put2 = new Put(rows.get(1));
       put1.add(cf, rows.get(0), rows.get(0));
       put2.add(cf, rows.get(1), rows.get(1));
       hTable.put(ImmutableList.of(put1, put2));

       ResultScanner rs = hTable.getScanner(cf);
       Result[] results = rs.next(2);
       Assert.assertArrayEquals(rows.get(0), results[0].getRow());
       Assert.assertArrayEquals(rows.get(1), results[1].getRow());
      
       assertMetricsUpdated(OpType.MULTIPUT, OpType.RESULTSCANNER_NEXTARRAY,
View Full Code Here

       rs.close();
   }
  
   @Test
   public void testcheckAndPut() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       Put put = new Put(row);
       put.add(cf, row, row);
       hTable.put(put);

       Put newPut = new Put(row);
       byte[] randBytes = randomRowKey();
       newPut.add(cf, randBytes, randBytes);
       hTable.checkAndPut(row, cf, row, row, newPut);

       Result result = hTable.get(new Get(row));
       Assert.assertEquals(2, result.list().size());
      
       assertMetricsUpdated(OpType.PUT, OpType.CHECK_AND_PUT, OpType.GET);
   }
View Full Code Here

       assertMetricsUpdated(OpType.PUT, OpType.CHECK_AND_PUT, OpType.GET);
   }

   @Test
   public void testDelete() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       Put put = new Put(row);
       put.add(cf, row, row);
       hTable.put(put);

       hTable.delete(new Delete(row));
      
       Assert.assertTrue(hTable.get(new Get(row)).isEmpty());
      
       assertMetricsUpdated(OpType.PUT, OpType.GET, OpType.DELETE);
   }
View Full Code Here

       assertMetricsUpdated(OpType.PUT, OpType.GET, OpType.DELETE);
   }
  
   @Test
   public void testMultiDelete() throws Exception {
       HTableInterface hTable = getHTable();
      
       final int ROWS_TO_INSERT = 5;
      
       List<byte[]> rows = getRandomRows(ROWS_TO_INSERT);
       for(byte[] row: rows) {
           Put put = new Put(row);
           put.add(cf, row, row);
           hTable.put(put);
       }

       ResultScanner rs = hTable.getScanner(new Scan());
       int countRows = 0;
       while(rs.next() != null) {
           countRows++;
       }
       rs.close();
       Assert.assertEquals(ROWS_TO_INSERT, countRows);
      
       List<Delete> deletes = new ArrayList<Delete>();
       for(byte[] row: rows) {
           deletes.add(new Delete(row));
       }
       hTable.delete(deletes);
      
       rs = hTable.getScanner(new Scan());
       countRows = 0;
       while(rs.next() != null) {
           countRows++;
       }
       Assert.assertEquals(0, countRows);
View Full Code Here

      
   }
  
   @Test
   public void testCheckAndDelete() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       Put put = new Put(row);
       put.add(cf, row, row);
       hTable.put(put);

       hTable.checkAndDelete(row, cf, row, row, new Delete(row));

       Assert.assertTrue(hTable.get(new Get(row)).isEmpty());
       assertMetricsUpdated(OpType.PUT, OpType.CHECK_AND_DELETE, OpType.GET);

   }
View Full Code Here

   }
  
   @Test
   public void testIcv() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       Put put = new Put(row);
       put.add(cf, row, Bytes.toBytes(10L));
       hTable.put(put);

       hTable.incrementColumnValue(row, cf, row, 5);

       Result result = hTable.get(new Get(row));
       Assert.assertEquals(15L, Bytes.toLong(result.value()));
       assertMetricsUpdated(OpType.PUT, OpType.INCREMENT, OpType.GET);

   }
View Full Code Here

   }

   @Test
   public void testIcvWithWal() throws Exception {
       HTableInterface hTable = getHTable();
       byte[] row = randomRowKey();
       Put put = new Put(row);
       put.add(cf, row, Bytes.toBytes(10L));
       hTable.put(put);

       hTable.incrementColumnValue(row, cf, row, 5, true);

       Result result = hTable.get(new Get(row));
       Assert.assertEquals(15L, Bytes.toLong(result.value()));
       assertMetricsUpdated(OpType.PUT, OpType.INCREMENT, OpType.GET);

   }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.HTableInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.