Kafka Streams is a de­ploy­ment-ag­nos­tic stream pro­cess­ing li­brary writ­ten in Java. Even though Kafka has a great test cov­er­age, there is no easy way to write unit-tests for pro­cess­ing topolo­gies, until now. I re­leased Mocked Streams for Scala, which sim­ply al­lows you to unit-test multi-in­put and out­put state­ful stream topolo­gies (since Apache Kafka >= 0.10.1) with­out Zookeeper and Kafka Bro­kers in your fa­vorite Scala test­ing frame­work e.g. Sca­laT­est and Specs2.

import com.madewithtea.mockedstreams.MockedStreams

val input = Seq(("x", "v1"), ("y", "v2"))
val expe = Seq(("x", "V1"), ("y", "V2"))
val strings = Serdes.String() MockedStreams()
.topology { builder => builder.stream(...) [...] }
.input("topic-in", strings, strings, input)
.output("topic-out", strings, strings, expe.size) shouldEqual expe

Mocked Streams

Mocked Streams 1.0 is a li­brary which al­lows you to do the lat­ter with­out much boil­er­plate code and in your favourite Scala test­ing frame­work. It wraps the org.​apache.​kafka.​test.​Proces­sor­Topol­o­gyTest­Driver class, but adds more syn­tac­tic sugar to keep your test code sim­ple. The fea­tures of the 1.0 re­lease in­clude:

  • Mul­ti­ple input and out­put streams
  • Spec­ify your topolo­gies as a func­tion: (KStream­Builder => Unit)
  • Use .con­fig to pass your Kafka Streams con­fig­u­ra­tion (e.g. Time­stamp ex­trac­tor)
  • Use .out­put­Table to match against the com­pacted table out­put as Map[K,V]
  • Sup­port for Scala 2.11.8
  • Sup­port for Apache Kafka 0.​10.​1.​0

Mul­ti­ple In­puts and Out­puts

val ms = MockedStreams()
.topology { builder => builder.stream(...) [...] }
.input("in-a", strings, ints, inputA)
.input("in-b", strings, ints, inputB)
.stores(Seq("store-name")) ms.output("out-a", strings, ints, expA.size) shouldEqual(expectedA)
ms.output("out-b", strings, ints, expB.size) shouldEqual(expectedB)

Get­ting Started

See the README for using Mocked Streams. For ex­am­ples check out the test code of Mocked Streams it­self. Mocked Streams is also lo­cated in the Maven Cen­tral Repos­i­tory, hence you just need to add:

libraryDependencies += "com.madewithtea" %% "mockedstreams" % "1.0.0" % "test"

If you have any ques­tions or is­sues re­gard­ing Mocked Streams, get in touch via Github. Al­ter­na­tively, you can get in con­tact via mail.

Released Mocked Streams for Apache Kafka的更多相关文章

  1. Apache Samza - Reliable Stream Processing atop Apache Kafka and Hadoop YARN

    http://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-fram ...

  2. Apache Kafka for Item Setup

    At Walmart.com in the U.S. and at Walmart's 11 other websites around the world, we provide seamless ...

  3. Apache Kafka:下一代分布式消息系统

    [http://www.infoq.com/cn/articles/apache-kafka/]分布式发布-订阅消息系统. Kafka是一种快速.可扩展的.设计内在就是分布式的,分区的和可复制的提交日 ...

  4. Apache Kafka: Next Generation Distributed Messaging System---reference

    Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...

  5. DataPipeline |《Apache Kafka实战》作者胡夕:Apache Kafka监控与调优

    胡夕 <Apache Kafka实战>作者,北航计算机硕士毕业,现任某互金公司计算平台总监,曾就职于IBM.搜狗.微博等公司.国内活跃的Kafka代码贡献者. 前言 虽然目前Apache ...

  6. An Overview of End-to-End Exactly-Once Processing in Apache Flink (with Apache Kafka, too!)

    01 Mar 2018 Piotr Nowojski (@PiotrNowojski) & Mike Winters (@wints) This post is an adaptation o ...

  7. How Cigna Tuned Its Spark Streaming App for Real-time Processing with Apache Kafka

    Explore the configuration changes that Cigna’s Big Data Analytics team has made to optimize the perf ...

  8. 《Apache Kafka 实战》读书笔记-认识Apache Kafka

    <Apache Kafka 实战>读书笔记-认识Apache Kafka 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.kafka概要设计 kafka在设计初衷就是 ...

  9. Streaming SQL for Apache Kafka

    KSQL是基于Kafka的Streams API进行构建的流式SQL引擎,KSQL降低了进入流处理的门槛,提供了一个简单的.完全交互式的SQL接口,用于处理Kafka的数据. KSQL是一套基于Apa ...

随机推荐

  1. lftp使用普通ftp模式登录

    set ftp:use-feat no set ftp:passive-mode yes set ftp:ssl-protect-data no set ssl:verify-certificate ...

  2. linux学习中遇到的各种故障与解决方法

    一.nginx 二.apache 三.mysql 四.tomcat 五.oracle 六.python python安装mysqldb(mysql-devel包)出现错误: error: comman ...

  3. Windows下安装Scala

    Scala是一种类似Java的纯面向对象的函数式编程语言,由于函数具有明确的确定输入对确定输出的关系,所以适合推理和计算,一切函数都可以看成一系列的计算组成,另外由于Scala函数是没有副作用和透明的 ...

  4. Base64编码格式详解

    什么是Base64? 按照RFC2045的定义,Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式.(The Base64 Content-T ...

  5. 【hadoop2.6.0】通过代码运行程序流程

    之前跑了一下hadoop里面自带的例子,现在顺一下如何通过源代码来运行程序. 我懒得装eclipse,就全部用命令行了. 整体参考官网上的:http://hadoop.apache.org/docs/ ...

  6. self dismissModalViewControllerAnimated:YES 无效(dismissviewcontrolleranimated无效)

    作为一个viewController(VC),想要消失的时候可以从parent VC里面调用dismissModalViewControllerAnimated来消去改VC,也可以在该VC里面手动调用 ...

  7. Python中判断是否为闰年,求输入日期是该年第几天

    #coding = utf-8 def getLastDay(): y = int(input("Please input year :")) m = int(input(&quo ...

  8. Linux Shell 高级编程技巧2----shell工具

    2.shell工具    2.1.日志文件        简介            创建日志文件是很重要的,记录了重要的信息.一旦出现错误,这些信息对于我们排错是非常有用的:监控的信息也可以记录到日 ...

  9. 【转载】Pyqt QSplitter分割窗口

    转载来自: http://blog.sina.com.cn/s/blog_4b5039210100h3ih.html 分割窗口在应用程序中经常用到,它可以灵活分布窗口布局,经常用于类似文件资源管理器的 ...

  10. Linux(CentOS)常用操作指令(二)

    1.安装wget指令: yum -y install wget 2.安装ifconfig指令: yum install net-tools 3.tar解压文件的使用:  tar -zxvf  aaa. ...