Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
952 views
by
edited by

Is there any sample code for mocking hbase in scala. ?

When we run our test cases it actually interacts with HBase. We would like to identify something using which we can mock the interaction with HBase. So that instead of going and adding\deleting\modifying something from the HBase tables it will just simulate these actions.

by
edited by
Is it possible for you to execute this code  following hbase operation  Get  ,put,scan HERE.
https://scastie.scala-lang.org/

1 Answer

0 like 0 dislike
by The go-to Tester (142 points)
One sample that I have got from the internet might help you,

package hbase

import org.scalatest.mock.MockitoSugar;

import Bytes;

import org.apache.hadoop.hbase.KeyValue;

import org.apache.hadoop.hbase.client.{HTableInterface, Get, Result => HResult};

import org.mockito.Mockito;

import org.mockito.Matchers;

class TableSpec extends UnitSpec with MockitoSugar{

  "A table" should "get from key 'Hello'" in {

    val htable = mock[HTableInterface]

    val table = Table(htable)

    val row = "Hello"

    val hresult = new HResult(Array(new KeyValue(StringBytes.toBytes(row), StringBytes.toBytes("Family"), StringBytes.toBytes("Column"), null)))

    when(htable.get(any[Get])).thenReturn(hresult)    

    val result = table.get(row)

    verify(htable, times(1)).get(any[Get])

    result should not be empty

    assert(result.get.getRow[String] === row)

    result.get.getValueAs[String] shouldBe empty

    result.get.getValue("Family", "Column") shouldBe empty

  }

}


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...