-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathJmhJenkinsRule.java
More file actions
44 lines (38 loc) · 1.26 KB
/
JmhJenkinsRule.java
File metadata and controls
44 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package jenkins.benchmark.jmh;
import com.gargoylesoftware.htmlunit.Cache;
import jenkins.model.Jenkins;
import org.jvnet.hudson.test.JenkinsRule;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
/**
* Extension of {@link JenkinsRule} to allow it to be used from JMH benchmarks.
* <p>
* This class should be instantiated only when the Jenkins instance is confirmed to exist.
*
* @since TODO
*/
public class JmhJenkinsRule extends JenkinsRule {
private final Jenkins jenkins;
public JmhJenkinsRule() {
super();
jenkins = Objects.requireNonNull(Jenkins.getInstanceOrNull());
super.jenkins = null; // the jenkins is not started from JenkinsRule
}
@Override
public URL getURL() throws MalformedURLException {
// the rootURL should not be null as it should've been set by JmhBenchmarkState
return new URL(Objects.requireNonNull(jenkins.getRootUrl()));
}
/**
* {@inheritDoc}
*/
@Override
public WebClient createWebClient() {
WebClient webClient = super.createWebClient();
Cache cache = new Cache();
cache.setMaxSize(0);
webClient.setCache(cache); // benchmarks should not rely on cached content
return webClient;
}
}