kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gwens...@apache.org
Subject [10/50] [abbrv] kafka git commit: KAFKA-3451: Add basic HTML coverage report generation to gradle
Date Mon, 11 Apr 2016 23:09:26 GMT
KAFKA-3451: Add basic HTML coverage report generation to gradle

Author: Grant Henke <granthenke@gmail.com>

Reviewers: Gwen Shapira, Ismael Juma, Ewen Cheslack-Postava

Closes #1121 from granthenke/coverage


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/623ab1e7
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/623ab1e7
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/623ab1e7

Branch: refs/heads/0.10.0
Commit: 623ab1e7c6497c000bc9c9978637f20542a3191c
Parents: 9f6a6f9
Author: Grant Henke <granthenke@gmail.com>
Authored: Thu Mar 31 10:07:54 2016 -0700
Committer: Gwen Shapira <cshapi@gmail.com>
Committed: Thu Mar 31 10:07:54 2016 -0700

----------------------------------------------------------------------
 README.md                                     |  3 ++
 build.gradle                                  | 59 ++++++++++++++++++++++
 core/src/main/scala/kafka/utils/ZkUtils.scala | 11 ++--
 gradle/dependencies.gradle                    |  3 ++
 4 files changed, 71 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/623ab1e7/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index bc2ca3a..97c5fef 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,9 @@ Change the log4j setting in either `clients/src/test/resources/log4j.properties`
 
     ./gradlew -i -Dtest.single=RequestResponseSerializationTest core:test
 
+### Generating test coverage reports ###
+    ./gradlew reportCoverage
+
 ### Building a binary release gzipped tar ball ###
     ./gradlew clean
     ./gradlew releaseTarGz

http://git-wip-us.apache.org/repos/asf/kafka/blob/623ab1e7/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index d6f82a4..da0152b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,12 +26,15 @@ buildscript {
     // For Apache Rat plugin to ignore non-Git files
     classpath "org.ajoberstar:grgit:1.5.0"
     classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
+    classpath 'org.scoverage:gradle-scoverage:2.0.1'
   }
 }
 
 allprojects {
   apply plugin: 'idea'
   apply plugin: 'eclipse'
+  apply plugin: "jacoco"
+
   repositories {
     mavenCentral()
   }
@@ -249,8 +252,50 @@ subprojects {
     configProperties = [importControlFile: "$rootDir/checkstyle/import-control.xml"]
   }
   test.dependsOn('checkstyleMain', 'checkstyleTest')
+
+  // Ignore core since its a scala project
+  if (it.path != ':core') {
+    // NOTE: Gradles Jacoco plugin does not support "offline instrumentation" this means
that classes mocked by PowerMock
+    // may report 0 coverage, since the source was modified after initial instrumentation.
+    // See https://github.com/jacoco/jacoco/issues/51
+    jacocoTestReport {
+      dependsOn tasks.test
+      sourceSets sourceSets.main
+      reports {
+        html.enabled = true
+        xml.enabled = true
+        csv.enabled = false
+      }
+    }
+  }
+}
+
+// Aggregates all jacoco results into the root project directory
+task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
+  def javaProjects = subprojects.findAll { it.path != ':core' }
+
+  description = 'Generates an aggregate report from all subprojects'
+  dependsOn(javaProjects.test)
+
+  additionalSourceDirs = files(javaProjects.sourceSets.main.allSource.srcDirs)
+  sourceDirectories = files(javaProjects.sourceSets.main.allSource.srcDirs)
+  classDirectories =  files(javaProjects.sourceSets.main.output)
+  executionData = files(javaProjects.jacocoTestReport.executionData)
+
+  reports {
+    html.enabled = true
+    xml.enabled = true
+  }
+
+  // workaround to ignore projects that don't have any tests at all
+  onlyIf = { true }
+  doFirst {
+    executionData = files(executionData.findAll { it.exists() })
+  }
 }
 
+task reportCoverage(dependsOn: ['jacocoRootReport', 'core:reportScoverage'])
+
 for ( sv in ['2_10', '2_11'] ) {
   String svInDot = sv.replaceAll( "_", ".")
 
@@ -320,6 +365,7 @@ project(':core') {
   println "Building project 'core' with Scala version ${versions.scala}"
 
   apply plugin: 'scala'
+  apply plugin: "org.scoverage"
   archivesBaseName = "kafka_${versions.baseScala}"
 
   dependencies {
@@ -351,7 +397,20 @@ project(':core') {
     testCompile libs.apachedsJdbmPartition
     testCompile libs.junit
     testCompile libs.scalaTest
+
+    scoverage libs.scoveragePlugin
+    scoverage libs.scoverageRuntime
+  }
+
+  jacocoTestReport.enabled = false
+  scoverage {
+    reportDir = file("${rootProject.buildDir}/scoverage")
+    highlighting = false
+  }
+  checkScoverage {
+    minimumRate = 0.0
   }
+  checkScoverage.shouldRunAfter('test')
 
   configurations {
     // manually excludes some unnecessary dependencies

http://git-wip-us.apache.org/repos/asf/kafka/blob/623ab1e7/core/src/main/scala/kafka/utils/ZkUtils.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/utils/ZkUtils.scala b/core/src/main/scala/kafka/utils/ZkUtils.scala
index 49d3cfa..bd8ec7e 100644
--- a/core/src/main/scala/kafka/utils/ZkUtils.scala
+++ b/core/src/main/scala/kafka/utils/ZkUtils.scala
@@ -452,12 +452,13 @@ class ZkUtils(val zkClient: ZkClient,
     } catch {
       case e1: ZkBadVersionException =>
         optionalChecker match {
-          case Some(checker) => return checker(this, path, data)
-          case _ => debug("Checker method is not passed skipping zkData match")
+          case Some(checker) => checker(this, path, data)
+          case _ =>
+            debug("Checker method is not passed skipping zkData match")
+            warn("Conditional update of path %s with data %s and expected version %d failed
due to %s"
+              .format(path, data,expectVersion, e1.getMessage))
+            (false, -1)
         }
-        warn("Conditional update of path %s with data %s and expected version %d failed due
to %s".format(path, data,
-          expectVersion, e1.getMessage))
-        (false, -1)
       case e2: Exception =>
         warn("Conditional update of path %s with data %s and expected version %d failed due
to %s".format(path, data,
           expectVersion, e2.getMessage))

http://git-wip-us.apache.org/repos/asf/kafka/blob/623ab1e7/gradle/dependencies.gradle
----------------------------------------------------------------------
diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle
index 6ed317a..f035838 100644
--- a/gradle/dependencies.gradle
+++ b/gradle/dependencies.gradle
@@ -41,6 +41,7 @@ versions += [
   rocksDB: "4.1.0",
   scalaTest: "2.2.6",
   scalaParserCombinators: "1.0.4",
+  scoverage: "1.1.1",
   slf4j: "1.7.18",
   snappy: "1.1.2.1",
   zkclient: "0.8",
@@ -96,6 +97,8 @@ libs += [
   scalaCompiler: "org.scala-lang:scala-compiler:$versions.scala",
   scalaTest: "org.scalatest:scalatest_$versions.baseScala:$versions.scalaTest",
   scalaParserCombinators: "org.scala-lang.modules:scala-parser-combinators_$versions.baseScala:$versions.scalaParserCombinators",
+  scoveragePlugin: "org.scoverage:scalac-scoverage-plugin_$versions.baseScala:$versions.scoverage",
+  scoverageRuntime: "org.scoverage:scalac-scoverage-runtime_$versions.baseScala:$versions.scoverage",
   slf4jApi: "org.slf4j:slf4j-api:$versions.slf4j",
   slf4jlog4j: "org.slf4j:slf4j-log4j12:$versions.slf4j",
   snappy: "org.xerial.snappy:snappy-java:$versions.snappy",


Mime
View raw message