Skip to content

Commit

Permalink
Merge commit 'e10ad3fe19a3c8a722400217d64162a03d97ac77' into recover-…
Browse files Browse the repository at this point in the history
…pr-133
  • Loading branch information
daniel-beck committed Apr 4, 2020
2 parents d756a14 + e10ad3f commit 1556b4c
Show file tree
Hide file tree
Showing 25 changed files with 823 additions and 156 deletions.
19 changes: 19 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 1
update_configs:
- package_manager: "java:maven"
directory: "/"
update_schedule: "weekly"
default_reviewers:
- "oleg-nenashev"
- "jglick"
ignored_updates:
- match:
dependency_name: "org.jenkins-ci.main:jenkins-core"
- match:
dependency_name: "org.jenkins-ci.main:jenkins-war"
# Avoid bumping plugins for self-testing, there is PCT which shoud be used for newest versions
- match:
dependency_name: "org.jenkins-ci.plugins*"
- match:
dependency_name: "io.jenkins.plugins*"
#TBD: Jetty?
2 changes: 2 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_extends: .github
tag-template: jenkins-test-harness-$NEXT_MINOR_VERSION
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
38 changes: 17 additions & 21 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
timeout(time: 1, unit: 'HOURS')
}
agent {
docker {
image 'maven:3.5.0-jdk-8'
label 'docker'
}
}
stages {
stage('main') {
// TODO Windows build in parallel
steps {
sh 'mvn -B clean verify'
}
post {
success {
junit '**/target/surefire-reports/TEST-*.xml'
}
properties([buildDiscarder(logRotator(numToKeepStr: '20'))])
node('docker') {
timeout(time: 1, unit: 'HOURS') {
deleteDir()
checkout scm
def tmp = pwd tmp: true
// TODO or can do explicitly something like: docker run -v "$TMP"/m2repo:/var/maven/.m2/repository --rm -u $(id -u):$(id -g) -e MAVEN_CONFIG=/var/maven/.m2 -v "$PWD":/usr/src/mymaven -w /usr/src/mymaven maven:3.6.1-jdk-8 mvn -Duser.home=/var/maven …
docker.image('maven:3.6.1-jdk-8').inside {
withEnv(["TMP=$tmp"]) {
// TODO Azure mirror
sh 'mvn -B -Dmaven.repo.local="$TMP"/m2repo -ntp -e -Dset.changelist -Dexpression=changelist -Doutput="$TMP"/changelist -Dmaven.test.failure.ignore help:evaluate clean install'
}
}
junit '**/target/surefire-reports/TEST-*.xml'
def changelist = readFile("$tmp/changelist")
dir("$tmp/m2repo") {
archiveArtifacts "**/*$changelist/*$changelist*"
}
}
}
infra.maybePublishIncrementals()
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Jenkins Unit Test Harness

[![GitHub release](https://img.shields.io/github/release/jenkinsci/jenkins-test-harness.svg?label=release)](https://github.com/jenkinsci/jenkins-test-harness/releases/latest)

Defines test harness for Jenkins core and plugins that you can use during the `mvn test` phase.
See [wiki page](//wiki.jenkins-ci.org/display/JENKINS/Unit+Test)

Expand All @@ -8,6 +11,13 @@ See https://javadoc.jenkins.io/component/jenkins-test-harness/

## Changelog

| WARNING: Changelogs have been moved to [GitHub Releases](https://github.com/jenkinsci/jenkins-test-harness/releases) |
| --- |

## New releases

See [GitHub Releases](https://github.com/jenkinsci/jenkins-test-harness/releases).

### 2.49 (2019 Apr 02)

* [PR-127](https://github.com/jenkinsci/jenkins-test-harness/pull/127): `JenkinsRule.showAgentLogs` utility
Expand Down
45 changes: 45 additions & 0 deletions docs/jmh-benchmarks.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
= JMH benchmarks with Jenkins
:toc:

link:https://openjdk.java.net/projects/code-tools/jmh/[Java Microbenchmark Harness] allows running benchmarks
in the JVM. To run a benchmark where you need a Jenkins instance, you can use use link:../src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java[``JmhBenchmarkState``]
as a state in your benchmark. This creates a temporary Jenkins instance for each fork of the JMH benchmark.

== Writing benchmarks

A reference to the Jenkins instance is available through either the `JmhBenchmarkState#getJenkins()` or through
`Jenkins.getInstance()` like you would otherwise do. `JmhBenchmarkState` provides `setup()` and `tearDown` methods
which can be overridden to configure the Jenkins instance according to your benchmark's requirements.

== Running the benchmarks

The benchmarks can be run through JUnit tests. From a test method, you can use the `OptionsBuilder` provided by JMH to
configure your benchmarks. For a sample, take a look at link:../src/test/java/jenkins/benchmark/jmh/BenchmarkTest.java[this].
Classes containing benchmarks are found automatically by the `BenchmarkFinder` when annotated
with `@JmhBenchmark`. Benchmark reports can also be generated and can be visualized using the jmh-report plugin.

NOTE: Benchmark methods need to be annotated by `@Benchmark` for JMH to detect them.

== Sample benchmarks

=== Simplest Benchmark:

[source,java]
----
@JmhBenchmark
public class JmhStateBenchmark {
public static class MyState extends JmhBenchmarkState {
}
@Benchmark
public void benchmark(MyState state) {
// benchmark code goes here
}
}
----

=== Examples

Some benchmarks have been implemented in the https://github.com/jenkinsci/role-strategy-plugin/tree/master/src/test/java/jmh/benchmarks[Role Strategy Plugin]
which show setting up the benchmarks for many different situations.

75 changes: 45 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.51</version>
<version>1.52</version>
<relativePath />
</parent>

<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.50-SNAPSHOT</version>
<version>${revision}${changelist}</version>

<name>Test harness for Jenkins and plugins</name>
<description>Harness used to run functional tests of Jenkins core and plugins.</description>
Expand All @@ -43,17 +43,16 @@ THE SOFTWARE.
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://[email protected]/jenkinsci/${project.artifactId}.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}</url>
<tag>HEAD</tag>
<tag>${scmTag}</tag>
</scm>

<properties>
<revision>2.56</revision>
<changelist>-SNAPSHOT</changelist>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.4.5.v20170502</jetty.version>
<java.level>8</java.level>
<concurrency>1</concurrency> <!-- may use e.g. 2C for 2 × (number of cores) -->
<!--TODO: fix upper bounds -->
<!--Upper bounds: com.google.guava:guava:11.0.1, and com.google.code.findbugs:jsr305:1.3.9. Core update is needed-->
<enforcer.skip>true</enforcer.skip>
<!--TODO: fix FindBugs-->
<findbugs.failOnError>false</findbugs.failOnError>
</properties>
Expand Down Expand Up @@ -147,12 +146,12 @@ THE SOFTWARE.
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-netbeans-insane</artifactId>
<version>RELEASE72</version>
<version>RELEASE802</version>
</dependency>
<dependency>
<groupId>com.github.stephenc.findbugs</groupId>
<artifactId>findbugs-annotations</artifactId>
<version>1.3.9-1</version>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
Expand All @@ -170,8 +169,17 @@ THE SOFTWARE.
<artifactId>classgraph</artifactId>
<version>4.4.7</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -185,6 +193,25 @@ THE SOFTWARE.
<!-- version specified in grandparent pom -->
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireUpperBoundDeps>
<excludes combine.children="append">
<!--
Stapler requests Guava 14.0 and Jenkins core requests Guice 4.0 which requests
Guava 16.0.1. Core actually provides 11.0.1. Work around this mess by just
excluding Guava from the RequireUpperBoundDeps check. The long-term fix is
tracked in JENKINS-36779.
-->
<exclude>com.google.guava:guava</exclude>
</excludes>
</requireUpperBoundDeps>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -204,9 +231,9 @@ THE SOFTWARE.
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<!-- version specified in grandparent pom -->
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>preset-packager</id>
Expand All @@ -215,31 +242,19 @@ THE SOFTWARE.
<goal>execute</goal>
</goals>
<configuration>
<source>${pom.basedir}/src/main/preset-data/package.groovy</source>
<scripts>
<script>file:///${pom.basedir}/src/main/preset-data/package.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.0</version>
</dependency>
<!-- Usually a dependency of ant, but some people seem to have an incomplete ant POM. See JENKINS-11416 -->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5-jenkins-1</version>
<version>1.10.6</version>
</dependency>
</dependencies>
<configuration>
<providerSelection>2.0</providerSelection>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/jenkins/benchmark/jmh/BenchmarkFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jenkins.benchmark.jmh;


import org.jvnet.hudson.annotation_indexer.Index;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;

import java.io.IOException;
import java.lang.reflect.AnnotatedElement;

/**
* Find classes annotated with {@link JmhBenchmark} to run their benchmark methods.
*
* @since 2.50
*/
@SuppressWarnings("WeakerAccess")
public final class BenchmarkFinder {
private final ClassLoader classLoader;

/**
* Class whose {@link ClassLoader} will be used to search for benchmarks.
*
* @param clazz the class whose {@link ClassLoader} will be used to search for benchmarks.
*/
public BenchmarkFinder(Class<?> clazz) {
this.classLoader = clazz.getClassLoader();
}

/**
* Includes classes annotated with {@link JmhBenchmark} as candidates for JMH benchmarks.
*
* @param optionsBuilder the optionsBuilder used to build the benchmarks
*/
public void findBenchmarks(ChainedOptionsBuilder optionsBuilder) throws IOException {
for (AnnotatedElement e : Index.list(JmhBenchmark.class, classLoader)) {
Class<?> clazz = (Class<?>) e;
JmhBenchmark annotation = clazz.getAnnotation(JmhBenchmark.class);
optionsBuilder.include(clazz.getName() + annotation.value());
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/jenkins/benchmark/jmh/JmhBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package jenkins.benchmark.jmh;

import org.jvnet.hudson.annotation_indexer.Indexed;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate your benchmark classes with this annotation to allow them to be discovered by {@link BenchmarkFinder}
*
* @since 2.50
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Indexed
public @interface JmhBenchmark {
/**
* Methods which annotated by {@link org.openjdk.jmh.annotations.Benchmark}
* in classes annotated by {@link JmhBenchmark} are to be run as benchmarks if they
* match this regex pattern.
* <p>
* Matches all functions by default, i.e. default pattern is {@code .*}.
*
* @return the regular expression used to match function names.
*/
String value() default ".*";
}
Loading

0 comments on commit 1556b4c

Please sign in to comment.