gearpump-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manuzhang <...@git.apache.org>
Subject [GitHub] incubator-gearpump pull request #86: [GEARPUMP-204]add unit test for externa...
Date Thu, 22 Sep 2016 06:01:44 GMT
Github user manuzhang commented on a diff in the pull request:

    https://github.com/apache/incubator-gearpump/pull/86#discussion_r79979548
  
    --- Diff: external/hbase/src/test/scala/org/apache/gearpump/external/hbase/HBaseSinkSpec.scala
---
    @@ -17,24 +17,52 @@
      */
     package org.apache.gearpump.external.hbase
     
    +import org.apache.gearpump.cluster.UserConfig
    +import org.apache.gearpump.streaming.MockUtil
    +import org.apache.gearpump.streaming.task.TaskContext
    +import org.apache.hadoop.conf.Configuration
    +import org.apache.hadoop.hbase.TableName
    +import org.apache.hadoop.hbase.client._
    +import org.apache.hadoop.hbase.util.Bytes
    +import org.mockito.Mockito._
    +import org.scalatest.mock.MockitoSugar
     import org.scalatest.prop.PropertyChecks
     import org.scalatest.{Matchers, PropSpec}
     
    -class HBaseSinkSpec extends PropSpec with PropertyChecks with Matchers {
    +class HBaseSinkSpec extends PropSpec with PropertyChecks with Matchers with MockitoSugar
{
     
       property("HBaseSink should insert a row successfully") {
     
    -  //  import Mockito._
    -  //  val htable = Mockito.mock(classOf[HTable])
    -  //  val row = "row"
    -  //  val group = "group"
    -  //  val name = "name"
    -  //  val value = "1.2"
    -  //  val put = new Put(Bytes.toBytes(row))
    -  //  put.add(Bytes.toBytes(group), Bytes.toBytes(name), Bytes.toBytes(value))
    -  //  val hbaseSink = HBaseSink(htable)
    -  //  hbaseSink.insert(put)
    -  //  verify(htable).put(put)
    +    val table = mock[Table]
    +    val config = mock[Configuration]
    +    val conn = mock[Connection]
    +    val taskContext = mock[TaskContext]
    +
    +
    +    val map = Map[String, String]("HBASESINK" -> "hbasesink", "TABLE_NAME" -> "hbase.table.name",
    +      "COLUMN_FAMILY" -> "hbase.table.column.family", "COLUMN_NAME" -> "hbase.table.column.name",
    +      "HBASE_USER" -> "hbase.user", "GEARPUMP_KERBEROS_PRINCIPAL" -> "gearpump.kerberos.principal",
    +      "GEARPUMP_KEYTAB_FILE" -> "gearpump.keytab.file"
    +    )
    +    val userconfig = new UserConfig(map)
    +    val tablename = "hbase"
    +    val row = "row"
    +    val group = "group"
    +    val name = "name"
    +    val value = "1.2"
    +
    +    when(conn.getTable(TableName.valueOf(tablename))).thenReturn(table)
    +
    +    val connection = HBaseSink.getConn(conn, true, userconfig, config)
    --- End diff --
    
    simply use mocked `conn` here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message