You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2022/04/30 07:40:07 UTC

[unomi] branch add-jacoco updated (456287117 -> 92ecab48f)

This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a change to branch add-jacoco
in repository https://gitbox.apache.org/repos/asf/unomi.git


 discard 456287117 add jacoco report
     new 92ecab48f add jacoco report

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (456287117)
            \
             N -- N -- N   refs/heads/add-jacoco (92ecab48f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/unomi-ci-build-tests.yml         |   8 +-
 itests/jacoco-report.sh                            |   2 +-
 itests/pom.xml                                     | 109 +++++----------------
 .../test/java/org/apache/unomi/itests/BaseIT.java  |  10 +-
 4 files changed, 34 insertions(+), 95 deletions(-)


[unomi] 01/01: add jacoco report

Posted by dg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch add-jacoco
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 92ecab48f044aaae04573bb5f800d28c75825c7f
Author: David Griffon <dg...@jahia.com>
AuthorDate: Fri Apr 29 23:04:28 2022 +0200

    add jacoco report
---
 .github/workflows/unomi-ci-build-tests.yml         |  8 +-
 itests/jacoco-report.sh                            | 28 +++++++
 itests/pom.xml                                     | 89 +++++++++++++++++++++-
 .../test/java/org/apache/unomi/itests/BaseIT.java  | 19 +++--
 4 files changed, 135 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/unomi-ci-build-tests.yml b/.github/workflows/unomi-ci-build-tests.yml
index cb5f82463..edf9b2853 100644
--- a/.github/workflows/unomi-ci-build-tests.yml
+++ b/.github/workflows/unomi-ci-build-tests.yml
@@ -45,8 +45,14 @@ jobs:
         uses: actions/upload-artifact@v3
         if: failure()
         with:
-          name: unomi-${{ matrix.java }}-${{ github.run_number }}
+          name: unomi-log-jdk${{ matrix.java }}-${{ github.run_number }}
           path: itests/target/exam/**/data/log
+      - name: Archive code coverage logs
+        uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: unomi-code-coverage-jdk${{ matrix.java }}-${{ github.run_number }}
+          path: itests/target/site/jacoco
       - name: Publish Test Report
         uses: mikepenz/action-junit-report@v3
         if: failure()
diff --git a/itests/jacoco-report.sh b/itests/jacoco-report.sh
new file mode 100755
index 000000000..8f17476f4
--- /dev/null
+++ b/itests/jacoco-report.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+################################################################################
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+################################################################################
+echo "Copy classes locally"
+for project in api common graphql/cxs-impl metrics persistence-elasticsearch/core persistence-spi plugins/baseplugin rest wab
+do
+  cp -rf ../$project/src/main src
+  cp -rf ../$project/target/classes target
+done
+mvn jacoco:report -Dit.code.coverage=true
+echo "clean up src/main"
+rm -rf src/main
\ No newline at end of file
diff --git a/itests/pom.xml b/itests/pom.xml
index 86955adc0..00e67db46 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -16,7 +16,8 @@
   ~ limitations under the License.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.unomi</groupId>
@@ -151,6 +152,7 @@
     </dependencies>
 
     <profiles>
+
         <profile>
             <id>run-tests</id>
             <activation>
@@ -158,6 +160,45 @@
             </activation>
             <build>
                 <plugins>
+                    <plugin>
+                        <groupId>com.googlecode.maven-download-plugin</groupId>
+                        <artifactId>download-maven-plugin</artifactId>
+                        <version>1.3.0</version>
+                        <executions>
+                            <execution>
+                                <!-- the wget goal actually binds itself to this phase by default -->
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>wget</goal>
+                                </goals>
+                                <configuration>
+                                    <url>
+                                        https://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.8/jacoco-0.8.8.zip
+                                    </url>
+                                    <outputFileName>jacoco.zip</outputFileName>
+                                    <!-- default target location, just to demonstrate the parameter -->
+                                    <outputDirectory>${project.build.directory}/jacoco/</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>pre-integration-test</phase>
+                                <configuration>
+                                    <tasks>
+                                        <unzip src="${project.build.directory}/jacoco/jacoco.zip"
+                                               dest="${project.build.directory}/jacoco"/>
+                                    </tasks>
+                                </configuration>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
                     <!-- Needed if you use versionAsInProject() -->
                     <plugin>
                         <groupId>org.apache.servicemix.tooling</groupId>
@@ -188,7 +229,8 @@
                             </environmentVariables>
                             <instanceSettings>
                                 <properties>
-                                    <cluster.routing.allocation.disk.threshold_enabled>false</cluster.routing.allocation.disk.threshold_enabled>
+                                    <cluster.routing.allocation.disk.threshold_enabled>false
+                                    </cluster.routing.allocation.disk.threshold_enabled>
                                     <http.cors.allow-origin>*</http.cors.allow-origin>
                                 </properties>
                             </instanceSettings>
@@ -238,6 +280,49 @@
                             </execution>
                         </executions>
                     </plugin>
+                    <plugin>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <executions>
+                            <execution>
+                                <id>Generate code coverage report</id>
+                                <phase>verify</phase>
+                                <goals>
+                                    <goal>exec</goal>
+                                </goals>
+                                <configuration>
+                                    <executable>${basedir}/jacoco-report.sh</executable>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>Jacoco code coverage report profile</id>
+            <activation>
+                <property>
+                    <name>it.code.coverage</name>
+                    <value>true</value>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.jacoco</groupId>
+                        <artifactId>jacoco-maven-plugin</artifactId>
+                        <version>0.7.7.201606060606</version>
+                        <executions>
+                            <execution>
+                                <phase>post-site</phase>
+                                <id>report</id>
+                                <goals>
+                                    <goal>report</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
                 </plugins>
             </build>
         </profile>
diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index 1007ff74f..dd2fa0dd4 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -125,7 +125,8 @@ public abstract class BaseIT {
     @Inject
     protected BundleContext bundleContext;
 
-    @Inject @Filter(timeout = 600000)
+    @Inject
+    @Filter(timeout = 600000)
     protected BundleWatcher bundleWatcher;
 
     @Inject
@@ -150,7 +151,7 @@ public abstract class BaseIT {
     }
 
 
-    protected void removeItems(final Class<? extends Item> ...classes) throws InterruptedException {
+    protected void removeItems(final Class<? extends Item>... classes) throws InterruptedException {
         Condition condition = new Condition(definitionsService.getConditionType("matchAllCondition"));
         for (Class<? extends Item> aClass : classes) {
             persistenceService.removeByQuery(condition, aClass);
@@ -257,6 +258,11 @@ public abstract class BaseIT {
             options.add(0, debugConfiguration(port, hold));
         }
 
+        // Jacoco setup
+        final String jacocoOption = "-javaagent:" + System.getProperty("user.dir") + "/target/jacoco/lib/jacocoagent.jar=destfile=" + System.getProperty("user.dir") + "/target/jacoco.exec,includes=org.apache.unomi.*";
+        LOGGER.info("set jacoco java agent: {}", jacocoOption);
+        options.add(new VMOption(jacocoOption));
+
         if (JavaVersionUtil.getMajorVersion() >= 9) {
             Option[] jdk9PlusOptions = new Option[]{
                     new VMOption("--add-reads=java.xml=java.logging"),
@@ -338,10 +344,10 @@ public abstract class BaseIT {
         }
     }
 
-    protected String getValidatedBundleJSON(final String resourcePath, Map<String,String> parameters) throws IOException {
+    protected String getValidatedBundleJSON(final String resourcePath, Map<String, String> parameters) throws IOException {
         String jsonString = bundleResourceAsString(resourcePath);
         if (parameters != null && parameters.size() > 0) {
-            for (Map.Entry<String,String> parameterEntry : parameters.entrySet()) {
+            for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
                 jsonString = jsonString.replace("###" + parameterEntry.getKey() + "###", parameterEntry.getValue());
             }
         }
@@ -378,7 +384,7 @@ public abstract class BaseIT {
         ServiceListener serviceListener = e -> {
             LOGGER.info("Service {} {}", e.getServiceReference().getProperty("objectClass"), serviceEventTypeToString(e));
             if ((e.getType() == ServiceEvent.UNREGISTERING || e.getType() == ServiceEvent.REGISTERED)
-                    && ((String[])e.getServiceReference().getProperty("objectClass"))[0].equals(serviceName)) {
+                    && ((String[]) e.getServiceReference().getProperty("objectClass"))[0].equals(serviceName)) {
                 latch1.countDown();
             }
         };
@@ -469,7 +475,7 @@ public abstract class BaseIT {
     }
 
     protected CloseableHttpResponse post(final String url, final String resource) {
-        return post(url,resource, JSON_CONTENT_TYPE);
+        return post(url, resource, JSON_CONTENT_TYPE);
     }
 
     protected CloseableHttpResponse delete(final String url) {
@@ -588,6 +594,7 @@ public abstract class BaseIT {
     void registerEventType(String jsonSchemaFileName) {
         post(JSONSCHEMA_URL, "schemas/events/" + jsonSchemaFileName, ContentType.TEXT_PLAIN);
     }
+
     void unRegisterEventType(String jsonSchemaId) {
         delete(JSONSCHEMA_URL + "/" + Base64.getEncoder().encodeToString(jsonSchemaId.getBytes()));
     }