本文整理汇总了Scala中kafka.common.OffsetAndMetadata类的典型用法代码示例。如果您正苦于以下问题:Scala OffsetAndMetadata类的具体用法?Scala OffsetAndMetadata怎么用?Scala OffsetAndMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OffsetAndMetadata类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: KafkaOffsetGetterSpec
//设置package包名称以及导入依赖的类
package com.quantifind.kafka.core
import com.quantifind.kafka.core.KafkaOffsetGetter.GroupTopicPartition
import com.quantifind.utils.ZkUtilsWrapper
import kafka.api.{OffsetRequest, OffsetResponse, PartitionOffsetsResponse}
import kafka.common.{OffsetAndMetadata, TopicAndPartition}
import kafka.consumer.SimpleConsumer
import org.I0Itec.zkclient.ZkClient
import org.mockito.Matchers._
import org.mockito.Mockito._
import org.mockito.{Matchers => MockitoMatchers, Mockito}
import org.scalatest._
class KafkaOffsetGetterSpec extends FlatSpec with ShouldMatchers {
trait Fixture {
val mockedZkClient = Mockito.mock(classOf[ZkClient])
val mockedZkUtil = Mockito.mock(classOf[ZkUtilsWrapper])
val mockedConsumer = Mockito.mock(classOf[SimpleConsumer])
val testPartitionLeader = 1
val offsetGetter = new KafkaOffsetGetter(mockedZkClient, mockedZkUtil)
offsetGetter.consumerMap += (testPartitionLeader -> Some(mockedConsumer))
}
"KafkaOffsetGetter" should "be able to build offset data for given partition" in new Fixture {
val testGroup = "testgroup"
val testTopic = "testtopic"
val testPartition = 1
val topicAndPartition = TopicAndPartition(testTopic, testPartition)
val groupTopicPartition = GroupTopicPartition(testGroup, topicAndPartition)
val offsetAndMetadata = OffsetAndMetadata(100, "meta", System.currentTimeMillis)
KafkaOffsetGetter.offsetMap += (groupTopicPartition -> offsetAndMetadata)
when(mockedZkUtil.getLeaderForPartition(MockitoMatchers.eq(mockedZkClient), MockitoMatchers.eq(testTopic), MockitoMatchers.eq(testPartition)))
.thenReturn(Some(testPartitionLeader))
val partitionErrorAndOffsets = Map(topicAndPartition -> PartitionOffsetsResponse(0,Seq(102)))
val offsetResponse = OffsetResponse(1, partitionErrorAndOffsets)
when(mockedConsumer.getOffsetsBefore(any[OffsetRequest])).thenReturn(offsetResponse)
offsetGetter.processPartition(testGroup, testTopic, testPartition) match {
case Some(offsetInfo) =>
offsetInfo.topic shouldBe testTopic
offsetInfo.group shouldBe testGroup
offsetInfo.partition shouldBe testPartition
offsetInfo.offset shouldBe 100
offsetInfo.logSize shouldBe 102
case None => fail("Failed to build offset data")
}
}
}