Skip to content

Commit bb13613

Browse files
authored
Issue ReactiveX#146: Initial draft of a Bulkhead with bounded queue and fixed … (ReactiveX#373)
* Issue ReactiveX#146: Initial draft of a Bulkhead with bounded queue and fixed thread pool.
1 parent 0389530 commit bb13613

21 files changed

+1941
-534
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ before_install:
66
- chmod +x gradlew
77
script:
88
- "./gradlew clean check"
9-
- sonar-scanner
9+
- "./gradlew sonarqube"
1010
after_success:
1111
- test $TRAVIS_BRANCH = "master" && ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
1212
- test $TRAVIS_BRANCH = "master" && ./gradlew asciidoctor

build.gradle

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ buildscript {
77
}
88
}
99
dependencies {
10-
classpath 'net.saliman:gradle-cobertura-plugin:2.3.2'
11-
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1'
1210
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
1311
classpath 'me.champeau.gradle:jmh-gradle-plugin:0.3.1'
1412
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.3"
@@ -18,17 +16,18 @@ buildscript {
1816
classpath "com.netflix.nebula:gradle-extra-configurations-plugin:4.0.1"
1917
}
2018
}
21-
19+
plugins {
20+
id "org.sonarqube" version "2.7"
21+
}
2222
apply plugin: 'idea'
23-
apply plugin: 'com.github.kt3k.coveralls'
2423
apply from: "${rootDir}/libraries.gradle"
2524

2625
ext {
2726
releaseVersion = '0.14.1'
2827
}
2928

3029
allprojects {
31-
apply plugin: 'net.saliman.cobertura'
30+
apply plugin: 'jacoco'
3231
apply plugin: 'me.champeau.gradle.jmh'
3332
apply plugin: 'com.jfrog.artifactory'
3433

@@ -57,6 +56,7 @@ configure(project.coreProjects) {
5756
apply plugin: 'com.jfrog.bintray'
5857
apply from: "${rootDir}/publishing.gradle"
5958
apply plugin: 'nebula.optional-base'
59+
apply plugin: 'jacoco'
6060

6161
dependencies {
6262
compile ( libraries.vavr)
@@ -87,37 +87,68 @@ configure(project.coreProjects) {
8787

8888
}
8989

90-
cobertura {
91-
coverageIgnoreTrivial = true
92-
coverageExcludes = ['.*io.github.resilience4j.bulkhead.internal.*']
93-
}
94-
9590
jmh {
9691
duplicateClassesStrategy = 'warn'
9792
jmhVersion = '1.17'
9893
}
9994
}
10095

101-
def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }
102-
cobertura {
103-
coverageFormats = ['html', 'xml']
104-
coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
105-
coverageMergeDatafiles = files
96+
sonarqube {
97+
properties {
98+
property "sonar.projectName", "resilience4j"
99+
property "sonar.projectKey", "resilience4j_resilience4j"
100+
property "sonar.modules", "resilience4j-core,resilience4j-feign,resilience4j-metrics,resilience4j-micrometer,resilience4j-prometheus,resilience4j-retry,resilience4j-spring,resilience4j-timelimiter,resilience4j-bulkhead,resilience4j-circuitbreaker,resilience4j-ratelimiter,resilience4j-cache,resilience4j-circularbuffer,resilience4j-consumer,resilience4j-spring-boot,resilience4j-spring-boot2,resilience4j-reactor,resilience4j-rxjava2"
101+
property "sonar.projectVersion","0.15.0-SNAPSHOTS"
102+
103+
property "sonar.links.homepage","https://github.com/resilience4j/resilience4j"
104+
property "sonar.links.ci","https://travis-ci.org/resilience4j/resilience4j"
105+
property "sonar.links.scm","https://github.com/resilience4j/resilience4j"
106+
property "sonar.links.issue","https://github.com/resilience4j/resilience4j/issues"
107+
108+
property "sonar.java.source","1.8"
109+
property "sonar.sources","src/main/java"
110+
property "sonar.tests","src/test/java"
111+
property "sonar.java.binaries","build"
112+
property "sonar.java.test.binaries","build"
113+
property "sonar.binaries","build"
114+
// property "sonar.jacoco.reportPaths","build/reports/jacoco/test"
115+
116+
property "sonar.language","java"
117+
118+
119+
property "sonar.sourceEncoding","UTF-8"
120+
}
106121
}
122+
def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"
107123

108-
test {
109-
dependsOn(subprojects.test) // required by cobertura to aggregate report
124+
task jacocoMergeTest(type: JacocoMerge) {
125+
destinationFile = file(allTestCoverageFile)
126+
executionData = project.fileTree(dir: '.', include:'**/build/jacoco/test.exec')
110127
}
111128

112-
tasks.coveralls {
113-
dependsOn 'check'
129+
task jacocoMerge(dependsOn: ['jacocoMergeTest']) {
130+
// used to run the other merge tasks
131+
}
132+
133+
subprojects {
134+
sonarqube {
135+
properties {
136+
property "sonar.jacoco.reportPaths", allTestCoverageFile
137+
}
138+
}
139+
}
140+
141+
tasks.check.dependsOn tasks.jacocoTestReport
142+
143+
144+
test {
145+
dependsOn(subprojects.test) // required by cobertura to aggregate report
114146
}
115147

116148
task wrapper(type: Wrapper) {
117149
gradleVersion = '4.10.2'
118150
}
119151

120-
121152
artifactory {
122153
contextUrl = 'https://oss.jfrog.org'
123154
resolve {

gradle/wrapper/gradle-wrapper.jar

1.92 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Mon Jan 09 12:41:44 CET 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip

gradlew

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
3333
# Use the maximum available, or set MAX_FD != -1 to use that value.
3434
MAX_FD="maximum"
3535

36-
warn ( ) {
36+
warn () {
3737
echo "$*"
3838
}
3939

40-
die ( ) {
40+
die () {
4141
echo
4242
echo "$*"
4343
echo
@@ -155,7 +155,7 @@ if $cygwin ; then
155155
fi
156156

157157
# Escape application args
158-
save ( ) {
158+
save () {
159159
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160160
echo " "
161161
}

resilience4j-bulkhead/src/main/java/io/github/resilience4j/bulkhead/BulkheadConfig.java

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,83 +23,84 @@
2323
*/
2424
public class BulkheadConfig {
2525

26-
public static final int DEFAULT_MAX_CONCURRENT_CALLS = 25;
27-
public static final long DEFAULT_MAX_WAIT_TIME = 0L;
26+
public static final int DEFAULT_MAX_CONCURRENT_CALLS = 25;
27+
public static final long DEFAULT_MAX_WAIT_TIME = 0L;
2828

29-
private int maxConcurrentCalls = DEFAULT_MAX_CONCURRENT_CALLS;
30-
private long maxWaitTime = DEFAULT_MAX_WAIT_TIME;
29+
private int maxConcurrentCalls = DEFAULT_MAX_CONCURRENT_CALLS;
30+
private long maxWaitTime = DEFAULT_MAX_WAIT_TIME;
3131

32-
private BulkheadConfig() { }
32+
private BulkheadConfig() {
33+
}
3334

34-
public int getMaxConcurrentCalls() {
35-
return maxConcurrentCalls;
36-
}
35+
/**
36+
* Returns a builder to create a custom BulkheadConfig.
37+
*
38+
* @return a {@link Builder}
39+
*/
40+
public static Builder custom() {
41+
return new Builder();
42+
}
3743

38-
public long getMaxWaitTime() {
39-
return maxWaitTime;
40-
}
44+
/**
45+
* Creates a default Bulkhead configuration.
46+
*
47+
* @return a default Bulkhead configuration.
48+
*/
49+
public static BulkheadConfig ofDefaults() {
50+
return new Builder().build();
51+
}
4152

42-
/**
43-
* Returns a builder to create a custom BulkheadConfig.
44-
*
45-
* @return a {@link Builder}
46-
*/
47-
public static Builder custom(){
48-
return new Builder();
49-
}
53+
public int getMaxConcurrentCalls() {
54+
return maxConcurrentCalls;
55+
}
5056

51-
/**
52-
* Creates a default Bulkhead configuration.
53-
*
54-
* @return a default Bulkhead configuration.
55-
*/
56-
public static BulkheadConfig ofDefaults() {
57-
return new Builder().build();
58-
}
57+
public long getMaxWaitTime() {
58+
return maxWaitTime;
59+
}
5960

60-
public static class Builder {
61+
public static class Builder {
6162

62-
private BulkheadConfig config = new BulkheadConfig();
63+
private BulkheadConfig config = new BulkheadConfig();
6364

64-
/**
65-
* Configures the max amount of concurrent calls the bulkhead will support.
66-
*
67-
* @param maxConcurrentCalls max concurrent calls
68-
* @return the BulkheadConfig.Builder
69-
*/
70-
public Builder maxConcurrentCalls(int maxConcurrentCalls) {
71-
if (maxConcurrentCalls < 1) {
72-
throw new IllegalArgumentException("maxConcurrentCalls must be a positive integer value >= 1");
73-
}
74-
config.maxConcurrentCalls = maxConcurrentCalls;
75-
return this;
76-
}
65+
/**
66+
* Configures the max amount of concurrent calls the bulkhead will support.
67+
*
68+
* @param maxConcurrentCalls max concurrent calls
69+
* @return the BulkheadConfig.Builder
70+
*/
71+
public Builder maxConcurrentCalls(int maxConcurrentCalls) {
72+
if (maxConcurrentCalls < 1) {
73+
throw new IllegalArgumentException("maxConcurrentCalls must be a positive integer value >= 1");
74+
}
75+
config.maxConcurrentCalls = maxConcurrentCalls;
76+
return this;
77+
}
7778

78-
/**
79-
* Configures a maximum amount of time in ms the calling thread will wait to enter the bulkhead. If bulkhead has space available, entry
80-
* is guaranteed and immediate. If bulkhead is full, calling threads will contest for space, if it becomes available. maxWaitTime can be set to 0.
81-
*
82-
* Note: for threads running on an event-loop or equivalent (rx computation pool, etc), setting maxWaitTime to 0 is highly recommended. Blocking
83-
* an event-loop thread will most likely have a negative effect on application throughput.
84-
*
85-
* @param maxWaitTime maximum wait time for bulkhead entry
86-
* @return the BulkheadConfig.Builder
87-
*/
88-
public Builder maxWaitTime(long maxWaitTime) {
89-
if (maxWaitTime < 0) {
90-
throw new IllegalArgumentException("maxWaitTime must be a positive integer value >= 0");
91-
}
92-
config.maxWaitTime = maxWaitTime;
93-
return this;
94-
}
79+
/**
80+
* Configures a maximum amount of time in ms the calling thread will wait to enter the bulkhead. If bulkhead has space available, entry
81+
* is guaranteed and immediate. If bulkhead is full, calling threads will contest for space, if it becomes available. maxWaitTime can be set to 0.
82+
* <p>
83+
* Note: for threads running on an event-loop or equivalent (rx computation pool, etc), setting maxWaitTime to 0 is highly recommended. Blocking
84+
* an event-loop thread will most likely have a negative effect on application throughput.
85+
*
86+
* @param maxWaitTime maximum wait time for bulkhead entry
87+
* @return the BulkheadConfig.Builder
88+
*/
89+
public Builder maxWaitTime(long maxWaitTime) {
90+
if (maxWaitTime < 0) {
91+
throw new IllegalArgumentException("maxWaitTime must be a positive integer value >= 0");
92+
}
93+
config.maxWaitTime = maxWaitTime;
94+
return this;
95+
}
9596

96-
/**
97-
* Builds a BulkheadConfig
98-
*
99-
* @return the BulkheadConfig
100-
*/
101-
public BulkheadConfig build() {
102-
return config;
103-
}
104-
}
97+
/**
98+
* Builds a BulkheadConfig
99+
*
100+
* @return the BulkheadConfig
101+
*/
102+
public BulkheadConfig build() {
103+
return config;
104+
}
105+
}
105106
}

0 commit comments

Comments
 (0)