Skip to content

Commit

Permalink
Issue ReactiveX#146: Initial draft of a Bulkhead with bounded queue a…
Browse files Browse the repository at this point in the history
…nd fixed … (ReactiveX#373)

* Issue ReactiveX#146: Initial draft of a Bulkhead with bounded queue and fixed thread pool.
  • Loading branch information
RobWin authored Apr 9, 2019
1 parent 0389530 commit bb13613
Show file tree
Hide file tree
Showing 21 changed files with 1,941 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before_install:
- chmod +x gradlew
script:
- "./gradlew clean check"
- sonar-scanner
- "./gradlew sonarqube"
after_success:
- test $TRAVIS_BRANCH = "master" && ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
- test $TRAVIS_BRANCH = "master" && ./gradlew asciidoctor
Expand Down
71 changes: 51 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ buildscript {
}
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.3.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'me.champeau.gradle:jmh-gradle-plugin:0.3.1'
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.3"
Expand All @@ -18,17 +16,18 @@ buildscript {
classpath "com.netflix.nebula:gradle-extra-configurations-plugin:4.0.1"
}
}

plugins {
id "org.sonarqube" version "2.7"
}
apply plugin: 'idea'
apply plugin: 'com.github.kt3k.coveralls'
apply from: "${rootDir}/libraries.gradle"

ext {
releaseVersion = '0.14.1'
}

allprojects {
apply plugin: 'net.saliman.cobertura'
apply plugin: 'jacoco'
apply plugin: 'me.champeau.gradle.jmh'
apply plugin: 'com.jfrog.artifactory'

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

dependencies {
compile ( libraries.vavr)
Expand Down Expand Up @@ -87,37 +87,68 @@ configure(project.coreProjects) {

}

cobertura {
coverageIgnoreTrivial = true
coverageExcludes = ['.*io.github.resilience4j.bulkhead.internal.*']
}

jmh {
duplicateClassesStrategy = 'warn'
jmhVersion = '1.17'
}
}

def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }
cobertura {
coverageFormats = ['html', 'xml']
coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
coverageMergeDatafiles = files
sonarqube {
properties {
property "sonar.projectName", "resilience4j"
property "sonar.projectKey", "resilience4j_resilience4j"
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"
property "sonar.projectVersion","0.15.0-SNAPSHOTS"

property "sonar.links.homepage","https://github.com/resilience4j/resilience4j"
property "sonar.links.ci","https://travis-ci.org/resilience4j/resilience4j"
property "sonar.links.scm","https://github.com/resilience4j/resilience4j"
property "sonar.links.issue","https://github.com/resilience4j/resilience4j/issues"

property "sonar.java.source","1.8"
property "sonar.sources","src/main/java"
property "sonar.tests","src/test/java"
property "sonar.java.binaries","build"
property "sonar.java.test.binaries","build"
property "sonar.binaries","build"
// property "sonar.jacoco.reportPaths","build/reports/jacoco/test"

property "sonar.language","java"


property "sonar.sourceEncoding","UTF-8"
}
}
def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"

test {
dependsOn(subprojects.test) // required by cobertura to aggregate report
task jacocoMergeTest(type: JacocoMerge) {
destinationFile = file(allTestCoverageFile)
executionData = project.fileTree(dir: '.', include:'**/build/jacoco/test.exec')
}

tasks.coveralls {
dependsOn 'check'
task jacocoMerge(dependsOn: ['jacocoMergeTest']) {
// used to run the other merge tasks
}

subprojects {
sonarqube {
properties {
property "sonar.jacoco.reportPaths", allTestCoverageFile
}
}
}

tasks.check.dependsOn tasks.jacocoTestReport


test {
dependsOn(subprojects.test) // required by cobertura to aggregate report
}

task wrapper(type: Wrapper) {
gradleVersion = '4.10.2'
}


artifactory {
contextUrl = 'https://oss.jfrog.org'
resolve {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Jan 09 12:41:44 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,83 +23,84 @@
*/
public class BulkheadConfig {

public static final int DEFAULT_MAX_CONCURRENT_CALLS = 25;
public static final long DEFAULT_MAX_WAIT_TIME = 0L;
public static final int DEFAULT_MAX_CONCURRENT_CALLS = 25;
public static final long DEFAULT_MAX_WAIT_TIME = 0L;

private int maxConcurrentCalls = DEFAULT_MAX_CONCURRENT_CALLS;
private long maxWaitTime = DEFAULT_MAX_WAIT_TIME;
private int maxConcurrentCalls = DEFAULT_MAX_CONCURRENT_CALLS;
private long maxWaitTime = DEFAULT_MAX_WAIT_TIME;

private BulkheadConfig() { }
private BulkheadConfig() {
}

public int getMaxConcurrentCalls() {
return maxConcurrentCalls;
}
/**
* Returns a builder to create a custom BulkheadConfig.
*
* @return a {@link Builder}
*/
public static Builder custom() {
return new Builder();
}

public long getMaxWaitTime() {
return maxWaitTime;
}
/**
* Creates a default Bulkhead configuration.
*
* @return a default Bulkhead configuration.
*/
public static BulkheadConfig ofDefaults() {
return new Builder().build();
}

/**
* Returns a builder to create a custom BulkheadConfig.
*
* @return a {@link Builder}
*/
public static Builder custom(){
return new Builder();
}
public int getMaxConcurrentCalls() {
return maxConcurrentCalls;
}

/**
* Creates a default Bulkhead configuration.
*
* @return a default Bulkhead configuration.
*/
public static BulkheadConfig ofDefaults() {
return new Builder().build();
}
public long getMaxWaitTime() {
return maxWaitTime;
}

public static class Builder {
public static class Builder {

private BulkheadConfig config = new BulkheadConfig();
private BulkheadConfig config = new BulkheadConfig();

/**
* Configures the max amount of concurrent calls the bulkhead will support.
*
* @param maxConcurrentCalls max concurrent calls
* @return the BulkheadConfig.Builder
*/
public Builder maxConcurrentCalls(int maxConcurrentCalls) {
if (maxConcurrentCalls < 1) {
throw new IllegalArgumentException("maxConcurrentCalls must be a positive integer value >= 1");
}
config.maxConcurrentCalls = maxConcurrentCalls;
return this;
}
/**
* Configures the max amount of concurrent calls the bulkhead will support.
*
* @param maxConcurrentCalls max concurrent calls
* @return the BulkheadConfig.Builder
*/
public Builder maxConcurrentCalls(int maxConcurrentCalls) {
if (maxConcurrentCalls < 1) {
throw new IllegalArgumentException("maxConcurrentCalls must be a positive integer value >= 1");
}
config.maxConcurrentCalls = maxConcurrentCalls;
return this;
}

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

/**
* Builds a BulkheadConfig
*
* @return the BulkheadConfig
*/
public BulkheadConfig build() {
return config;
}
}
/**
* Builds a BulkheadConfig
*
* @return the BulkheadConfig
*/
public BulkheadConfig build() {
return config;
}
}
}
Loading

0 comments on commit bb13613

Please sign in to comment.