Class MockHTable

  • All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.hadoop.hbase.client.Table

    public class MockHTable
    extends Object
    implements org.apache.hadoop.hbase.client.Table
    MockHTable. original MockHTable (by agaoglu) : https://gist.github.com/agaoglu/613217#file_mock_h_table.java Modifications
    • fix filter (by k-mack) : https://gist.github.com/k-mack/4600133
    • fix batch() : implement all mutate operation and fix result[] count.
    • fix exists()
    • fix increment() : wrong return value
    • check columnFamily
    • implement mutateRow()
    • implement getTableName()
    • implement getTableDescriptor()
    • throws RuntimeException when unimplemented method was called.
    • remove some methods for loading data, checking values ...
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.client.Table

        org.apache.hadoop.hbase.client.Table.CheckAndMutateBuilder, org.apache.hadoop.hbase.client.Table.CheckAndMutateWithFilterBuilder
    • Constructor Summary

      Constructors 
      Constructor Description
      MockHTable​(org.apache.hadoop.hbase.TableName tableName)  
      MockHTable​(org.apache.hadoop.hbase.TableName tableName, String... columnFamilies)  
      MockHTable​(org.apache.hadoop.hbase.TableName tableName, List<String> columnFamilies)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.hadoop.hbase.client.Result append​(org.apache.hadoop.hbase.client.Append append)
      org.apache.hadoop.hbase.client.HTable asHTable()  
      Object[] batch​(List<? extends org.apache.hadoop.hbase.client.Row> actions)
      void batch​(List<? extends org.apache.hadoop.hbase.client.Row> actions, Object[] results)
      <R> void batchCallback​(List<? extends org.apache.hadoop.hbase.client.Row> actions, Object[] results, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
      <R extends com.google.protobuf.Message>
      Map<byte[],​R>
      batchCoprocessorService​(com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor, com.google.protobuf.Message request, byte[] startKey, byte[] endKey, R responsePrototype)
      <R extends com.google.protobuf.Message>
      void
      batchCoprocessorService​(com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor, com.google.protobuf.Message request, byte[] startKey, byte[] endKey, R responsePrototype, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
      boolean checkAndDelete​(byte[] row, byte[] family, byte[] qualifier, byte[] value, org.apache.hadoop.hbase.client.Delete delete)
      boolean checkAndDelete​(byte[] row, byte[] family, byte[] qualifier, org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp, byte[] value, org.apache.hadoop.hbase.client.Delete delete)
      boolean checkAndMutate​(byte[] row, byte[] family, byte[] qualifier, org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp, byte[] value, org.apache.hadoop.hbase.client.RowMutations rm)
      boolean checkAndPut​(byte[] row, byte[] family, byte[] qualifier, byte[] value, org.apache.hadoop.hbase.client.Put put)
      boolean checkAndPut​(byte[] row, byte[] family, byte[] qualifier, org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp, byte[] value, org.apache.hadoop.hbase.client.Put put)
      void clear()  
      void close()
      org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel coprocessorService​(byte[] row)
      <T extends com.google.protobuf.Service,​R>
      Map<byte[],​R>
      coprocessorService​(Class<T> service, byte[] startKey, byte[] endKey, org.apache.hadoop.hbase.client.coprocessor.Batch.Call<T,​R> callable)
      <T extends com.google.protobuf.Service,​R>
      void
      coprocessorService​(Class<T> service, byte[] startKey, byte[] endKey, org.apache.hadoop.hbase.client.coprocessor.Batch.Call<T,​R> callable, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
      void delete​(List<org.apache.hadoop.hbase.client.Delete> deletes)
      void delete​(org.apache.hadoop.hbase.client.Delete delete)  
      boolean[] exists​(List<org.apache.hadoop.hbase.client.Get> gets)
      boolean exists​(org.apache.hadoop.hbase.client.Get get)
      org.apache.hadoop.hbase.client.Result[] get​(List<org.apache.hadoop.hbase.client.Get> gets)
      org.apache.hadoop.hbase.client.Result get​(org.apache.hadoop.hbase.client.Get get)
      org.apache.hadoop.conf.Configuration getConfiguration()
      org.apache.hadoop.hbase.client.TableDescriptor getDescriptor()
      org.apache.hadoop.hbase.TableName getName()
      org.apache.hadoop.hbase.client.RegionLocator getRegionLocator()  
      org.apache.hadoop.hbase.client.ResultScanner getScanner​(byte[] family)
      org.apache.hadoop.hbase.client.ResultScanner getScanner​(byte[] family, byte[] qualifier)
      org.apache.hadoop.hbase.client.ResultScanner getScanner​(org.apache.hadoop.hbase.client.Scan scan)
      byte[] getTableName()  
      org.apache.hadoop.hbase.client.Result increment​(org.apache.hadoop.hbase.client.Increment increment)
      long incrementColumnValue​(byte[] row, byte[] family, byte[] qualifier, long amount)
      long incrementColumnValue​(byte[] row, byte[] family, byte[] qualifier, long amount, org.apache.hadoop.hbase.client.Durability durability)
      org.apache.hadoop.hbase.client.Result mutateRow​(org.apache.hadoop.hbase.client.RowMutations rm)
      void put​(List<org.apache.hadoop.hbase.client.Put> puts)
      void put​(org.apache.hadoop.hbase.client.Put put)
      MockHTable setConfiguration​(org.apache.hadoop.conf.Configuration config)  
      • Methods inherited from interface org.apache.hadoop.hbase.client.Table

        checkAndDelete, checkAndMutate, checkAndMutate, checkAndMutate, checkAndMutate, checkAndMutate, checkAndPut, existsAll, getOperationTimeout, getOperationTimeout, getReadRpcTimeout, getReadRpcTimeout, getRpcTimeout, getRpcTimeout, getTableDescriptor, getWriteRpcTimeout, getWriteRpcTimeout, setOperationTimeout, setReadRpcTimeout, setRpcTimeout, setWriteRpcTimeout
    • Constructor Detail

      • MockHTable

        public MockHTable​(org.apache.hadoop.hbase.TableName tableName)
      • MockHTable

        public MockHTable​(org.apache.hadoop.hbase.TableName tableName,
                          String... columnFamilies)
      • MockHTable

        public MockHTable​(org.apache.hadoop.hbase.TableName tableName,
                          List<String> columnFamilies)
    • Method Detail

      • clear

        public void clear()
      • getTableName

        public byte[] getTableName()
      • getName

        public org.apache.hadoop.hbase.TableName getName()
        Specified by:
        getName in interface org.apache.hadoop.hbase.client.Table
      • getConfiguration

        public org.apache.hadoop.conf.Configuration getConfiguration()
        Specified by:
        getConfiguration in interface org.apache.hadoop.hbase.client.Table
      • setConfiguration

        public MockHTable setConfiguration​(org.apache.hadoop.conf.Configuration config)
      • getDescriptor

        public org.apache.hadoop.hbase.client.TableDescriptor getDescriptor()
                                                                     throws IOException
        Specified by:
        getDescriptor in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • mutateRow

        public org.apache.hadoop.hbase.client.Result mutateRow​(org.apache.hadoop.hbase.client.RowMutations rm)
                                                        throws IOException
        Specified by:
        mutateRow in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • append

        public org.apache.hadoop.hbase.client.Result append​(org.apache.hadoop.hbase.client.Append append)
                                                     throws IOException
        Specified by:
        append in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • exists

        public boolean exists​(org.apache.hadoop.hbase.client.Get get)
                       throws IOException
        Specified by:
        exists in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • exists

        public boolean[] exists​(List<org.apache.hadoop.hbase.client.Get> gets)
                         throws IOException
        Specified by:
        exists in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • batchCallback

        public <R> void batchCallback​(List<? extends org.apache.hadoop.hbase.client.Row> actions,
                                      Object[] results,
                                      org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
                               throws IOException,
                                      InterruptedException
        Specified by:
        batchCallback in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
        InterruptedException
      • get

        public org.apache.hadoop.hbase.client.Result get​(org.apache.hadoop.hbase.client.Get get)
                                                  throws IOException
        Specified by:
        get in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • get

        public org.apache.hadoop.hbase.client.Result[] get​(List<org.apache.hadoop.hbase.client.Get> gets)
                                                    throws IOException
        Specified by:
        get in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • getScanner

        public org.apache.hadoop.hbase.client.ResultScanner getScanner​(org.apache.hadoop.hbase.client.Scan scan)
                                                                throws IOException
        Specified by:
        getScanner in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • getScanner

        public org.apache.hadoop.hbase.client.ResultScanner getScanner​(byte[] family)
                                                                throws IOException
        Specified by:
        getScanner in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • getScanner

        public org.apache.hadoop.hbase.client.ResultScanner getScanner​(byte[] family,
                                                                       byte[] qualifier)
                                                                throws IOException
        Specified by:
        getScanner in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • put

        public void put​(org.apache.hadoop.hbase.client.Put put)
                 throws IOException
        Specified by:
        put in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • put

        public void put​(List<org.apache.hadoop.hbase.client.Put> puts)
                 throws IOException
        Specified by:
        put in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • checkAndPut

        public boolean checkAndPut​(byte[] row,
                                   byte[] family,
                                   byte[] qualifier,
                                   byte[] value,
                                   org.apache.hadoop.hbase.client.Put put)
                            throws IOException
        Specified by:
        checkAndPut in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • checkAndPut

        public boolean checkAndPut​(byte[] row,
                                   byte[] family,
                                   byte[] qualifier,
                                   org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp,
                                   byte[] value,
                                   org.apache.hadoop.hbase.client.Put put)
                            throws IOException
        Specified by:
        checkAndPut in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • delete

        public void delete​(org.apache.hadoop.hbase.client.Delete delete)
                    throws IOException
        Specified by:
        delete in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • delete

        public void delete​(List<org.apache.hadoop.hbase.client.Delete> deletes)
                    throws IOException
        Specified by:
        delete in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • checkAndDelete

        public boolean checkAndDelete​(byte[] row,
                                      byte[] family,
                                      byte[] qualifier,
                                      byte[] value,
                                      org.apache.hadoop.hbase.client.Delete delete)
                               throws IOException
        Specified by:
        checkAndDelete in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • checkAndDelete

        public boolean checkAndDelete​(byte[] row,
                                      byte[] family,
                                      byte[] qualifier,
                                      org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp,
                                      byte[] value,
                                      org.apache.hadoop.hbase.client.Delete delete)
                               throws IOException
        Specified by:
        checkAndDelete in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • checkAndMutate

        public boolean checkAndMutate​(byte[] row,
                                      byte[] family,
                                      byte[] qualifier,
                                      org.apache.hadoop.hbase.filter.CompareFilter.CompareOp compareOp,
                                      byte[] value,
                                      org.apache.hadoop.hbase.client.RowMutations rm)
                               throws IOException
        Specified by:
        checkAndMutate in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • increment

        public org.apache.hadoop.hbase.client.Result increment​(org.apache.hadoop.hbase.client.Increment increment)
                                                        throws IOException
        Specified by:
        increment in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • incrementColumnValue

        public long incrementColumnValue​(byte[] row,
                                         byte[] family,
                                         byte[] qualifier,
                                         long amount)
                                  throws IOException
        Specified by:
        incrementColumnValue in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • incrementColumnValue

        public long incrementColumnValue​(byte[] row,
                                         byte[] family,
                                         byte[] qualifier,
                                         long amount,
                                         org.apache.hadoop.hbase.client.Durability durability)
                                  throws IOException
        Specified by:
        incrementColumnValue in interface org.apache.hadoop.hbase.client.Table
        Throws:
        IOException
      • coprocessorService

        public org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel coprocessorService​(byte[] row)
        Specified by:
        coprocessorService in interface org.apache.hadoop.hbase.client.Table
      • coprocessorService

        public <T extends com.google.protobuf.Service,​R> Map<byte[],​R> coprocessorService​(Class<T> service,
                                                                                                      byte[] startKey,
                                                                                                      byte[] endKey,
                                                                                                      org.apache.hadoop.hbase.client.coprocessor.Batch.Call<T,​R> callable)
                                                                                               throws com.google.protobuf.ServiceException
        Specified by:
        coprocessorService in interface org.apache.hadoop.hbase.client.Table
        Throws:
        com.google.protobuf.ServiceException
      • coprocessorService

        public <T extends com.google.protobuf.Service,​R> void coprocessorService​(Class<T> service,
                                                                                       byte[] startKey,
                                                                                       byte[] endKey,
                                                                                       org.apache.hadoop.hbase.client.coprocessor.Batch.Call<T,​R> callable,
                                                                                       org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
                                                                                throws com.google.protobuf.ServiceException
        Specified by:
        coprocessorService in interface org.apache.hadoop.hbase.client.Table
        Throws:
        com.google.protobuf.ServiceException
      • batchCoprocessorService

        public <R extends com.google.protobuf.Message> Map<byte[],​R> batchCoprocessorService​(com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor,
                                                                                                   com.google.protobuf.Message request,
                                                                                                   byte[] startKey,
                                                                                                   byte[] endKey,
                                                                                                   R responsePrototype)
                                                                                            throws com.google.protobuf.ServiceException
        Specified by:
        batchCoprocessorService in interface org.apache.hadoop.hbase.client.Table
        Throws:
        com.google.protobuf.ServiceException
      • batchCoprocessorService

        public <R extends com.google.protobuf.Message> void batchCoprocessorService​(com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor,
                                                                                    com.google.protobuf.Message request,
                                                                                    byte[] startKey,
                                                                                    byte[] endKey,
                                                                                    R responsePrototype,
                                                                                    org.apache.hadoop.hbase.client.coprocessor.Batch.Callback<R> callback)
                                                                             throws com.google.protobuf.ServiceException
        Specified by:
        batchCoprocessorService in interface org.apache.hadoop.hbase.client.Table
        Throws:
        com.google.protobuf.ServiceException
      • getRegionLocator

        public org.apache.hadoop.hbase.client.RegionLocator getRegionLocator()
        Specified by:
        getRegionLocator in interface org.apache.hadoop.hbase.client.Table
      • asHTable

        public org.apache.hadoop.hbase.client.HTable asHTable()