diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b35fade1..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: 2 -jobs: - build: - machine: - image: "ubuntu-2004:202111-02" - environment: - _JAVA_OPTIONS: "-Xms1024m -Xmx2048m" - TERM: dumb - branches: - ignore: - - gh-pages # list of branches to ignore - steps: - - run: - name: Install OpenJDK 17 - command: | - wget -qO - https://adoptium.jfrog.io/adoptium/api/gpg/key/public | sudo apt-key add - - sudo add-apt-repository --yes https://adoptium.jfrog.io/adoptium/deb/ - sudo apt-get update && sudo apt-get install temurin-17-jdk - sudo update-alternatives --set java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java - sudo update-alternatives --set javac /usr/lib/jvm/temurin-17-jdk-amd64/bin/javac - java -version - - checkout - # - restore_cache: - # key: sc-circuitbreaker-{{ .Branch }} - - run: - name: "Download dependencies" - command: | - ./mvnw -s .settings.xml -U --fail-never dependency:go-offline || true - - save_cache: - key: sc-circuitbreaker-{{ .Branch }} - paths: - - ~/.m2 - - run: - name: "Running build" - command: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn - - run: - name: "Aggregate test results" - when: always - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/target/.*-reports/.*" -exec cp {} ~/junit/ \; - bash <(curl -s https://codecov.io/bash) - - store_artifacts: - path: ~/junit/ - destination: artifacts - - store_test_results: - path: ~/junit/ - destination: testartifacts diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0d996cf9..00000000 --- a/.editorconfig +++ /dev/null @@ -1,18 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -# top-most EditorConfig file -root = true - -[*] -indent_style = tab -indent_size = 4 -end_of_line = lf -insert_final_newline = true - -[*.yml] -indent_style = space -indent_size = 2 - -[*.yaml] -indent_style = space -indent_size = 2 \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index aeafef9d..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -**Describe the bug** -Please provide details of the problem, including the version of Spring Cloud that you -are using. - -**Sample** -If possible, please provide a test case or sample application that reproduces -the problem. This makes it much easier for us to diagnose the problem and to verify that -we have fixed it. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index bbcbbe7d..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 00000000..3f193e65 --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,53 @@ +name: Deploy Docs +run-name: ${{ format('{0} ({1})', github.workflow, github.event.inputs.build-refname || 'all') }} +on: + workflow_dispatch: + inputs: + build-refname: + description: Enter git refname to build (e.g., 5.7.x). + required: false + push: + branches: docs-build +env: + GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }} +permissions: + contents: write +jobs: + build: + if: github.repository_owner == 'spring-cloud' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 5 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Set up refname build + if: github.event.inputs.build-refname + run: | + git fetch --depth 1 https://github.com/$GITHUB_REPOSITORY ${{ github.event.inputs.build-refname }} + export BUILD_REFNAME=${{ github.event.inputs.build-refname }} + echo "BUILD_REFNAME=$BUILD_REFNAME" >> $GITHUB_ENV + export BUILD_VERSION=$(git cat-file --textconv FETCH_HEAD:pom.xml | python3 -c "import xml.etree.ElementTree as xml; from sys import stdin; print(xml.parse(stdin).getroot().find('{http://maven.apache.org/POM/4.0.0}version').text)") + echo BUILD_VERSION=$BUILD_VERSION >> $GITHUB_ENV + - name: Run Antora + run: | + ./mvnw --no-transfer-progress -B antora + - name: Publish Docs + uses: spring-io/spring-doc-actions/rsync-antora-reference@v0.0.11 + with: + docs-username: ${{ secrets.DOCS_USERNAME }} + docs-host: ${{ secrets.DOCS_HOST }} + docs-ssh-key: ${{ secrets.DOCS_SSH_KEY }} + docs-ssh-host-key: ${{ secrets.DOCS_SSH_HOST_KEY }} + site-path: target/antora/site + - name: Bust Cloudflare Cache + uses: spring-io/spring-doc-actions/bust-cloudflare-antora-cache@v0.0.11 + with: + context-root: spring-cloud-circuitbreaker + cloudflare-zone-id: ${{ secrets.CLOUDFLARE_ZONE_ID }} + cloudflare-cache-token: ${{ secrets.CLOUDFLARE_CACHE_TOKEN }} diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml deleted file mode 100644 index 0bdc4c79..00000000 --- a/.github/workflows/maven.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Build - -on: - push: - branches: [ main, 2.1.x ] - pull_request: - branches: [ main, 2.1.x ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: Build with Maven - run: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn - - name: Publish Test Report - uses: mikepenz/action-junit-report@v2 - if: always() # always run even if the previous step fails - with: - report_paths: '**/surefire-reports/TEST-*.xml' - - name: Archive code coverage results - uses: actions/upload-artifact@v2 - with: - name: surefire-reports - path: '**/surefire-reports/*' diff --git a/.gitignore b/.gitignore index 42f20702..6be8a4a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,22 @@ -*~ -#* -*# -.#* -.classpath -.project +target/ .settings/ +.project +.classpath +*.orig .springBeans -target/ -bin/ -_site/ -.idea +.factorypath +.sts4-cache +.ant-targets-build.xml +src/ant/.ant-targets-upload-dist.xml +*.sonar4clipse* +.DS_Store *.iml *.ipr *.iws -.factorypath -*.log -.shelf -*.swp -*.swo -.flattened-pom.xml +/.idea/ +*.graphml +node +node_modules +build +package.json +package-lock.json diff --git a/.java-version b/.java-version deleted file mode 100644 index 98d9bcb7..00000000 --- a/.java-version +++ /dev/null @@ -1 +0,0 @@ -17 diff --git a/.mvn/maven.config b/.mvn/maven.config deleted file mode 100644 index 3b8cf46e..00000000 --- a/.mvn/maven.config +++ /dev/null @@ -1 +0,0 @@ --DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java old mode 100755 new mode 100644 index 959fea7b..b901097f --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,117 +1,117 @@ - /* -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 - - https://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. -*/ - + * Copyright 2007-present the original author or authors. + * + * Licensed 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. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; import java.util.Properties; public class MavenWrapperDownloader { - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is - * provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl - * property to use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; - /** - * Name of the property which should be used to override the default download url for - * the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - // If the maven-wrapper.properties exists, read it and check if it contains a - // custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, - MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if (mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream( - mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } - catch (IOException e) { - System.out.println( - "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } - finally { - try { - if (mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } - catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); - File outputFile = new File(baseDirectory.getAbsolutePath(), - MAVEN_WRAPPER_JAR_PATH); - if (!outputFile.getParentFile().exists()) { - if (!outputFile.getParentFile().mkdirs()) { - System.out.println("- ERROR creating output direcrory '" - + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } - catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } - private static void downloadFileFromURL(String urlString, File destination) - throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar old mode 100755 new mode 100644 index 08ebbb67..2cc7d4a5 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties old mode 100755 new mode 100644 index 71793467..642d572c --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/.sdkmanrc b/.sdkmanrc deleted file mode 100644 index 415f9083..00000000 --- a/.sdkmanrc +++ /dev/null @@ -1,3 +0,0 @@ -# Enable auto-env through the sdkman_auto_env config -# Add key=value pairs of SDKs to use below -java=17.0.1-tem diff --git a/.settings.xml b/.settings.xml deleted file mode 100644 index 03645e8c..00000000 --- a/.settings.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - repo.spring.io - ${env.CI_DEPLOY_USERNAME} - ${env.CI_DEPLOY_PASSWORD} - - - - - - spring - - true - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - https://repo.spring.io/release - - false - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - - - diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 62589edd..00000000 --- a/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed 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 - - https://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. diff --git a/README.adoc b/README.adoc index 1598c884..1f5f344f 100644 --- a/README.adoc +++ b/README.adoc @@ -1,754 +1,23 @@ -//// -DO NOT EDIT THIS FILE. IT WAS GENERATED. -Manual changes to this file will be lost when it is generated again. -Edit the files in the src/main/asciidoc/ directory instead. -//// += Spring Cloud Circuitbreaker Docs Build +You're currently viewing the Antora playbook branch. +The playbook branch hosts the docs build that is used to build and publish the production docs site. -:doctype: book -:idprefix: -:idseparator: - -:toc: left -:toclevels: 4 -:tabsize: 4 -:numbered: -:sectanchors: -:sectnums: -:icons: font -:hide-uri-scheme: -:docinfo: shared,private +The Spring Cloud Circuitbreaker reference docs are built using https://antora.org[Antora]. +This README covers how to build the docs in a software branch as well as how to build the production docs site locally. -:sc-ext: java -:project-full-name: Spring Cloud Circuitbreaker -:all: {asterisk}{asterisk} +== Building the Site -= Spring Cloud Circuit Breaker -:doctype: book -:idprefix: -:idseparator: - -:toc: left -:toclevels: 4 -:tabsize: 4 -:numbered: -:sectanchors: -:sectnums: -:icons: font -:hide-uri-scheme: -:docinfo: shared,private +You can build the entire site by invoking the following on the docs-build branch and then viewing the site at `target/site/index.html` -:sc-ext: java -:project-full-name: Spring Cloud Circuitbreaker -:all: {asterisk}{asterisk} - -*{spring-cloud-version}* - -## Usage Documentation - -The Spring Cloud CircuitBreaker project contains implementations for Resilience4J and Spring Retry. -The APIs implemented in Spring Cloud CircuitBreaker live in Spring Cloud Commons. The usage documentation -for these APIs are located in the https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#spring-cloud-circuit-breaker[Spring Cloud Commons documentation]. - -=== Configuring Resilience4J Circuit Breakers - -==== Starters - -There are two starters for the Resilience4J implementations, one for reactive applications and one for non-reactive applications. - -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j` - non-reactive applications -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j` - reactive applications - -==== Auto-Configuration -You can disable the Resilience4J auto-configuration by setting -`spring.cloud.circuitbreaker.resilience4j.enabled` to `false`. - -==== Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .build()); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()).build()); -} ----- -==== - -===== Customizing The ExecutorService -If you would like to configure the `ExecutorService` which executes the circuit breaker you can do so using the `Resilience4JCircuitBreakerFactory`. - -For example if you would like to use a context aware `ExecutorService` you could do the following. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> { - ContextAwareScheduledThreadPoolExecutor executor = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool().corePoolSize(5) - .build(); - factory.configureExecutorService(executor); - }; -} ----- -==== - -==== Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addCircuitBreakerCustomizer` -method. -This can be useful for adding event handlers to Resilience4J circuit breakers. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); - }; -} ----- -==== - -==== Circuit Breaker Properties Configuration - -You can configure `CircuitBreaker` and `TimeLimiter` configs or instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -Descending priority from top to bottom. - -* Method(id) config - on specific method or operation -* Service(group) config - on specific application service or operations -* Global default config - -==== -[source,java] ----- -ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName) -Resilience4JCircuitBreakerFactory.create(String id, String groupName) ----- -==== - -===== Global Default Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - default: - registerHealthIndicator: true - slidingWindowSize: 50 - -resilience4j.timelimiter: - configs: - default: - timeoutDuration: 5s - cancelRunningFuture: true +[source,bash] ---- -==== - -===== Configs Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - groupA: - registerHealthIndicator: true - slidingWindowSize: 200 - -resilience4j.timelimiter: - configs: - groupC: - timeoutDuration: 3s - cancelRunningFuture: true +./mvnw antora ---- -==== - -===== Instances Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - instances: - backendA: - registerHealthIndicator: true - slidingWindowSize: 100 - backendB: - registerHealthIndicator: true - slidingWindowSize: 10 - permittedNumberOfCallsInHalfOpenState: 3 - slidingWindowType: TIME_BASED - recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate - -resilience4j.timelimiter: - instances: - backendA: - timeoutDuration: 2s - cancelRunningFuture: true - backendB: - timeoutDuration: 1s - cancelRunningFuture: false ----- -==== - - -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA")` or `Resilience4JCircuitBreakerFactory.create("backendA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")` or `Resilience4JCircuitBreakerFactory.create("backendA", "groupA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC")` or `Resilience4JCircuitBreakerFactory.create("backendC")` will apply `global default properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")` or `Resilience4JCircuitBreakerFactory.create("backendC", "groupC")` will apply `global default CircuitBreaker properties and config groupC TimeLimiter properties` - -For more information on Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Bulkhead pattern supporting -If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead. -You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`. - -Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern: - -* a `SemaphoreBulkhead` which uses Semaphores -* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool. - -By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. To modify the default behavior to use `SemaphoreBulkhead` set the property `spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead` to `true`. - -For more information on implementation -of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead]. - -The `Customizer` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultBulkheadCustomizer() { - return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build()) - .build() -); -} ----- -==== - -==== Specific Bulkhead Configuration - -Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customizer` bean this -is passed a `Resilience4jBulkheadProvider`. - -==== -[source,java] ----- -@Bean -public Customizer slowBulkheadProviderCustomizer() { - return provider -> provider.configure(builder -> builder - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead"); -} ----- -==== - -In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they -have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer` -methods. - -===== Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer customizer() { - return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer) - .onCallFinished(slowFinishedConsumer), "slowBulkhead"); -} ----- -==== - -===== Thread Pool Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer slowThreadPoolBulkheadCustomizer() { - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() - .onCallRejected(slowThreadPoolRejectedConsumer) - .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); -} ----- -==== - -==== Bulkhead Properties Configuration - -You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -==== -[source] ----- -resilience4j.thread-pool-bulkhead: - instances: - backendA: - maxThreadPoolSize: 1 - coreThreadPoolSize: 1 -resilience4j.bulkhead: - instances: - backendB: - maxConcurrentCalls: 10 ----- -==== - -For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Collecting Metrics - -Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right -dependencies are on the classpath. To enable metric collection you must include `org.springframework.boot:spring-boot-starter-actuator`, and `io.github.resilience4j:resilience4j-micrometer`. For more information on the metrics that -get produced when these dependencies are present, see the https://resilience4j.readme.io/docs/micrometer[Resilience4j documentation]. - -NOTE: You don't have to include `micrometer-core` directly as it is brought in by `spring-boot-starter-actuator` - -=== Configuring Spring Retry Circuit Breakers - -Spring Retry provides declarative retry support for Spring applications. -A subset of the project includes the ability to implement circuit breaker functionality. -Spring Retry provides a circuit breaker implementation via a combination of it's -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java[`CircuitBreakerRetryPolicy`] -and a https://github.com/spring-projects/spring-retry#stateful-retry[stateful retry]. -All circuit breakers created using Spring Retry will be created using the `CircuitBreakerRetryPolicy` and a -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/support/DefaultRetryState.java[`DefaultRetryState`]. -Both of these classes can be configured using `SpringRetryConfigBuilder`. - -==== Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`SpringRetryCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new SpringRetryConfigBuilder(id) - .retryPolicy(new TimeoutRetryPolicy()).build()); -} ----- -==== - -==== Specific Circuit Breaker Configuration -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`SpringRetryCircuitBreakerFactory`. +== Building a Specific Branch -==== -[source,java] +[source,bash] ---- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); -} +./mvnw antora ---- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addRetryTemplateCustomizers` -method. -This can be useful for adding event handlers to the `RetryTemplate`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addRetryTemplateCustomizers(retryTemplate -> retryTemplate.registerListener(new RetryListener() { - - @Override - public boolean open(RetryContext context, RetryCallback callback) { - return false; - } - - @Override - public void close(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - - @Override - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - })); -} ----- -==== - -== Building - - -:jdkversion: 17 - -=== Basic Compile and Test - -To build the source you will need to install JDK {jdkversion}. - -Spring Cloud uses Maven for most build-related activities, and you -should be able to get off the ground quite quickly by cloning the -project you are interested in and typing - ----- -$ ./mvnw install ----- - -NOTE: You can also install Maven (>=3.3.3) yourself and run the `mvn` command -in place of `./mvnw` in the examples below. If you do that you also -might need to add `-P spring` if your local Maven settings do not -contain repository declarations for spring pre-release artifacts. - -NOTE: Be aware that you might need to increase the amount of memory -available to Maven by setting a `MAVEN_OPTS` environment variable with -a value like `-Xmx512m -XX:MaxPermSize=128m`. We try to cover this in -the `.mvn` configuration, so if you find you have to do it to make a -build succeed, please raise a ticket to get the settings added to -source control. - -The projects that require middleware (i.e. Redis) for testing generally -require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. - - -=== Documentation - -The spring-cloud-build module has a "docs" profile, and if you switch -that on it will try to build asciidoc sources from -`src/main/asciidoc`. As part of that process it will look for a -`README.adoc` and process it by loading all the includes, but not -parsing or rendering it, just copying it to `${main.basedir}` -(defaults to `${basedir}`, i.e. the root of the project). If there are -any changes in the README it will then show up after a Maven build as -a modified file in the correct place. Just commit it and push the change. - -=== Working with the code -If you don't have an IDE preference we would recommend that you use -https://www.springsource.com/developer/sts[Spring Tools Suite] or -https://eclipse.org[Eclipse] when working with the code. We use the -https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools -should also work without issue as long as they use Maven 3.3.3 or better. - -==== Activate the Spring Maven profile -Spring Cloud projects require the 'spring' Maven profile to be activated to resolve -the spring milestone and snapshot repositories. Use your preferred IDE to set this -profile to be active, or you may experience build errors. - -==== Importing into eclipse with m2eclipse -We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with -eclipse. If you don't already have m2eclipse installed it is available from the "eclipse -marketplace". - -NOTE: Older versions of m2e do not support Maven 3.3, so once the -projects are imported into Eclipse you will also need to tell -m2eclipse to use the right profile for the projects. If you -see many different errors related to the POMs in the projects, check -that you have an up to date installation. If you can't upgrade m2e, -add the "spring" profile to your `settings.xml`. Alternatively you can -copy the repository settings from the "spring" profile of the parent -pom into your `settings.xml`. - -==== Importing into eclipse without m2eclipse -If you prefer not to use m2eclipse you can generate eclipse project metadata using the -following command: - -[indent=0] ----- - $ ./mvnw eclipse:eclipse ----- - -The generated eclipse projects can be imported by selecting `import existing projects` -from the `file` menu. - - - -== Contributing - -:spring-cloud-build-branch: master - -Spring Cloud is released under the non-restrictive Apache 2.0 license, -and follows a very standard Github development process, using Github -tracker for issues and merging pull requests into master. If you want -to contribute even something trivial please do not hesitate, but -follow the guidelines below. - -=== Sign the Contributor License Agreement -Before we accept a non-trivial patch or pull request we will need you to sign the -https://cla.pivotal.io/sign/spring[Contributor License Agreement]. -Signing the contributor's agreement does not grant anyone commit rights to the main -repository, but it does mean that we can accept your contributions, and you will get an -author credit if we do. Active contributors might be asked to join the core team, and -given the ability to merge pull requests. - -=== Code of Conduct -This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of -conduct]. By participating, you are expected to uphold this code. Please report -unacceptable behavior to spring-code-of-conduct@pivotal.io. - -=== Code Conventions and Housekeeping -None of these is essential for a pull request, but they will all help. They can also be -added after the original pull request but before a merge. - -* Use the Spring Framework code format conventions. If you use Eclipse - you can import formatter settings using the - `eclipse-code-formatter.xml` file from the - https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring - Cloud Build] project. If using IntelliJ, you can use the - https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter - Plugin] to import the same file. -* Make sure all new `.java` files to have a simple Javadoc class comment with at least an - `@author` tag identifying you, and preferably at least a paragraph on what the class is - for. -* Add the ASF license header comment to all new `.java` files (copy from existing files - in the project) -* Add yourself as an `@author` to the .java files that you modify substantially (more - than cosmetic changes). -* Add some Javadocs and, if you change the namespace, some XSD doc elements. -* A few unit tests would help a lot as well -- someone has to do it. -* If no-one else is using your branch, please rebase it against the current master (or - other target branch in the main project). -* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], - if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit - message (where XXXX is the issue number). - -=== Checkstyle - -Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: - -.spring-cloud-build-tools/ ----- -└── src -    ├── checkstyle -    │   └── checkstyle-suppressions.xml <3> -    └── main -    └── resources -    ├── checkstyle-header.txt <2> -    └── checkstyle.xml <1> ----- -<1> Default Checkstyle rules -<2> File header setup -<3> Default suppression rules - -==== Checkstyle configuration - -Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. - -.pom.xml ----- - -true <1> - true - <2> - true - <3> - - - - - <4> - io.spring.javaformat - spring-javaformat-maven-plugin - - <5> - org.apache.maven.plugins - maven-checkstyle-plugin - - - - - - <5> - org.apache.maven.plugins - maven-checkstyle-plugin - - - - ----- -<1> Fails the build upon Checkstyle errors -<2> Fails the build upon Checkstyle violations -<3> Checkstyle analyzes also the test sources -<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules -<5> Add checkstyle plugin to your build and reporting phases - -If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example: - -.projectRoot/src/checkstyle/checkstyle-suppresions.xml ----- - - - - - - ----- - -It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: - -```bash -$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig -$ touch .springformat -``` - -=== IDE setup - -==== Intellij IDEA - -In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. -The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project. - -.spring-cloud-build-tools/ ----- -└── src -    ├── checkstyle -    │   └── checkstyle-suppressions.xml <3> -    └── main -    └── resources -    ├── checkstyle-header.txt <2> -    ├── checkstyle.xml <1> -    └── intellij -       ├── Intellij_Project_Defaults.xml <4> -       └── Intellij_Spring_Boot_Java_Conventions.xml <5> ----- -<1> Default Checkstyle rules -<2> File header setup -<3> Default suppression rules -<4> Project defaults for Intellij that apply most of Checkstyle rules -<5> Project style conventions for Intellij that apply most of Checkstyle rules - -.Code style - -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style] - -Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. - -.Inspection profiles - -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style] - -Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. - -.Checkstyle - -To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions - -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle] - -Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: - -- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. -- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. -- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. - -IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. - -=== Duplicate Finder - -Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath. - -==== Duplicate Finder configuration - -Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`. - -.pom.xml -[source,xml] ----- - - - - org.basepom.maven - duplicate-finder-maven-plugin - - - ----- - -For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation]. - -You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build. - -If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project: - -[source,xml] ----- - - - - org.basepom.maven - duplicate-finder-maven-plugin - - - org.joda.time.base.BaseDateTime - .*module-info - - - changelog.txt - - - - - - - ----- - diff --git a/docs/antora-playbook.yml b/antora-playbook.yml similarity index 60% rename from docs/antora-playbook.yml rename to antora-playbook.yml index 9a70e676..a58e7a33 100644 --- a/docs/antora-playbook.yml +++ b/antora-playbook.yml @@ -6,38 +6,39 @@ antora: - '@antora/collector-extension' - '@antora/atlas-extension' - require: '@springio/antora-extensions/root-component-extension' - root_component_name: 'PROJECT_WITHOUT_SPRING' - # FIXME: Run antora once using this extension to migrate to the Asciidoc Tabs syntax - # and then remove this extension - - require: '@springio/antora-extensions/tabs-migration-extension' - unwrap_example_block: always - save_result: true + root_component_name: 'cloud-circuitbreaker' site: - title: PROJECT_FULL_NAME - url: https://docs.spring.io/PROJECT_NAME/reference/ + title: Spring Cloud Circuitbreaker + url: https://docs.spring.io/spring-cloud-circuitbreaker/reference + robots: allow +git: + ensure_git_suffix: false content: sources: - - url: ./.. - branches: HEAD + - url: https://github.com/spring-cloud/spring-cloud-circuitbreaker + # Refname matching: + # https://docs.antora.org/antora/latest/playbook/content-refname-matching/ + branches: [ main ] + tags: [ '({4..9}).+({1..9}).+({0..9})?(-{RC,M}+({0..9}))', '!4.1.0-M1' ] start_path: docs - worktrees: true asciidoc: attributes: page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud page-pagination: '' hide-uri-scheme: '@' tabs-sync-option: '@' - chomp: 'all' extensions: - '@asciidoctor/tabs' - '@springio/asciidoctor-extensions' - sourcemap: true urls: + latest_version_segment_strategy: redirect:to latest_version_segment: '' + redirect_facility: httpd +ui: + bundle: + url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip + snapshot: true runtime: log: failure_level: warn format: pretty -ui: - bundle: - url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip diff --git a/docs/.github/workflows/deploy-docs.yml b/docs/.github/workflows/deploy-docs.yml deleted file mode 100644 index be4b92df..00000000 --- a/docs/.github/workflows/deploy-docs.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Deploy Docs -on: - push: - branches-ignore: [ gh-pages ] - tags: '**' - repository_dispatch: - types: request-build-reference # legacy - #schedule: - #- cron: '0 10 * * *' # Once per day at 10am UTC - workflow_dispatch: -permissions: - actions: write -jobs: - build: - runs-on: ubuntu-latest - # if: github.repository_owner == 'spring-cloud' - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: docs-build - fetch-depth: 1 - - name: Dispatch (partial build) - if: github.ref_type == 'branch' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }} - - name: Dispatch (full build) - if: github.ref_type == 'tag' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) diff --git a/docs/antora.yml b/docs/antora.yml deleted file mode 100644 index 15b346da..00000000 --- a/docs/antora.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: PROJECT_WITHOUT_SPRING -version: true -title: PROJECT_NAME -nav: - - modules/ROOT/nav.adoc -ext: - collector: - run: - command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests - local: true - scan: - dir: ./target/classes/antora-resources/ diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc deleted file mode 100644 index bcbc4871..00000000 --- a/docs/modules/ROOT/nav.adoc +++ /dev/null @@ -1,17 +0,0 @@ -* xref:index.adoc[] -* xref:spring-cloud-circuitbreaker.adoc[] -* xref:_attributes.adoc[] -* xref:spring-cloud-circuitbreaker-resilience4j.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/starters.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/auto-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc[] -* xref:spring-cloud-circuitbreaker-spring-retry.adoc[] -** xref:spring-cloud-circuitbreaker-spring-retry/default-configuration.adoc[] -** xref:spring-cloud-circuitbreaker-spring-retry/specific-circuit-breaker-configuration.adoc[] -* xref:README.adoc[] diff --git a/docs/modules/ROOT/pages/README.adoc b/docs/modules/ROOT/pages/README.adoc deleted file mode 100644 index 8b137891..00000000 --- a/docs/modules/ROOT/pages/README.adoc +++ /dev/null @@ -1 +0,0 @@ - diff --git a/docs/modules/ROOT/pages/_attributes.adoc b/docs/modules/ROOT/pages/_attributes.adoc deleted file mode 100644 index a724317b..00000000 --- a/docs/modules/ROOT/pages/_attributes.adoc +++ /dev/null @@ -1,14 +0,0 @@ -:doctype: book -:idprefix: -:idseparator: - -:tabsize: 4 -:numbered: -:sectanchors: -:sectnums: -:icons: font -:hide-uri-scheme: -:docinfo: shared,private - -:sc-ext: java -:project-full-name: Spring Cloud Circuitbreaker -:all: {asterisk}{asterisk} diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc deleted file mode 100644 index 28d346c2..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc +++ /dev/null @@ -1,4 +0,0 @@ -[[configuring-resilience4j-circuit-breakers]] -= Configuring Resilience4J Circuit Breakers -:page-section-summary-toc: 1 - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/auto-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/auto-configuration.adoc deleted file mode 100644 index 4b59d91e..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/auto-configuration.adoc +++ /dev/null @@ -1,7 +0,0 @@ -[[auto-configuration]] -= Auto-Configuration -:page-section-summary-toc: 1 - -You can disable the Resilience4J auto-configuration by setting -`spring.cloud.circuitbreaker.resilience4j.enabled` to `false`. - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc deleted file mode 100644 index c6c9ccae..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc +++ /dev/null @@ -1,32 +0,0 @@ -[[bulkhead-pattern-supporting]] -= Bulkhead pattern supporting - -If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead. -You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`. - -Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern: - -* a `SemaphoreBulkhead` which uses Semaphores -* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool. - -By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. To modify the default behavior to use `SemaphoreBulkhead` set the property `spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead` to `true`. - -For more information on implementation -of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead]. - -The `Customizer` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultBulkheadCustomizer() { - return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build()) - .build() -); -} ----- -==== - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc deleted file mode 100644 index 06c0a708..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc +++ /dev/null @@ -1,24 +0,0 @@ -[[bulkhead-properties-configuration]] -= Bulkhead Properties Configuration -:page-section-summary-toc: 1 - -You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -==== -[source] ----- -resilience4j.thread-pool-bulkhead: - instances: - backendA: - maxThreadPoolSize: 1 - coreThreadPoolSize: 1 -resilience4j.bulkhead: - instances: - backendB: - maxConcurrentCalls: 10 ----- -==== - -For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc deleted file mode 100644 index a08b840e..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc +++ /dev/null @@ -1,94 +0,0 @@ -[[circuit-breaker-properties-configuration]] -= Circuit Breaker Properties Configuration - -You can configure `CircuitBreaker` and `TimeLimiter` configs or instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -Descending priority from top to bottom. - -* Method(id) config - on specific method or operation -* Service(group) config - on specific application service or operations -* Global default config - -==== -[source,java] ----- -ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName) -Resilience4JCircuitBreakerFactory.create(String id, String groupName) ----- -==== - -[[global-default-properties-configuration]] -== Global Default Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - default: - registerHealthIndicator: true - slidingWindowSize: 50 - -resilience4j.timelimiter: - configs: - default: - timeoutDuration: 5s - cancelRunningFuture: true ----- -==== - -[[configs-properties-configuration]] -== Configs Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - groupA: - registerHealthIndicator: true - slidingWindowSize: 200 - -resilience4j.timelimiter: - configs: - groupC: - timeoutDuration: 3s - cancelRunningFuture: true ----- -==== - -[[instances-properties-configuration]] -== Instances Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - instances: - backendA: - registerHealthIndicator: true - slidingWindowSize: 100 - backendB: - registerHealthIndicator: true - slidingWindowSize: 10 - permittedNumberOfCallsInHalfOpenState: 3 - slidingWindowType: TIME_BASED - recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate - -resilience4j.timelimiter: - instances: - backendA: - timeoutDuration: 2s - cancelRunningFuture: true - backendB: - timeoutDuration: 1s - cancelRunningFuture: false ----- -==== - - -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA")` or `Resilience4JCircuitBreakerFactory.create("backendA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")` or `Resilience4JCircuitBreakerFactory.create("backendA", "groupA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC")` or `Resilience4JCircuitBreakerFactory.create("backendC")` will apply `global default properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")` or `Resilience4JCircuitBreakerFactory.create("backendC", "groupC")` will apply `global default CircuitBreaker properties and config groupC TimeLimiter properties` - -For more information on Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc deleted file mode 100644 index 7b999392..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc +++ /dev/null @@ -1,9 +0,0 @@ -[[collecting-metrics]] -= Collecting Metrics -:page-section-summary-toc: 1 - -Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right -dependencies are on the classpath. To enable metric collection you must include `org.springframework.boot:spring-boot-starter-actuator`, and `io.github.resilience4j:resilience4j-micrometer`. For more information on the metrics that -get produced when these dependencies are present, see the https://resilience4j.readme.io/docs/micrometer[Resilience4j documentation]. - -NOTE: You don't have to include `micrometer-core` directly as it is brought in by `spring-boot-starter-actuator` diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc deleted file mode 100644 index 68b6d409..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc +++ /dev/null @@ -1,55 +0,0 @@ -[[default-configuration]] -= Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .build()); -} ----- -==== - -[[reactive-example]] -== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()).build()); -} ----- -==== - -[[customizing-the-executorservice]] -== Customizing The ExecutorService -If you would like to configure the `ExecutorService` which executes the circuit breaker you can do so using the `Resilience4JCircuitBreakerFactory`. - -For example if you would like to use a context aware `ExecutorService` you could do the following. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> { - ContextAwareScheduledThreadPoolExecutor executor = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool().corePoolSize(5) - .build(); - factory.configureExecutorService(executor); - }; -} ----- -==== - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc deleted file mode 100644 index c329a625..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc +++ /dev/null @@ -1,52 +0,0 @@ -[[specific-bulkhead-configuration]] -= Specific Bulkhead Configuration - -Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customizer` bean this -is passed a `Resilience4jBulkheadProvider`. - -==== -[source,java] ----- -@Bean -public Customizer slowBulkheadProviderCustomizer() { - return provider -> provider.configure(builder -> builder - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead"); -} ----- -==== - -In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they -have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer` -methods. - -[[bulkhead-example]] -== Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer customizer() { - return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer) - .onCallFinished(slowFinishedConsumer), "slowBulkhead"); -} ----- -==== - -[[thread-pool-bulkhead-example]] -== Thread Pool Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer slowThreadPoolBulkheadCustomizer() { - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() - .onCallRejected(slowThreadPoolRejectedConsumer) - .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); -} ----- -==== - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc deleted file mode 100644 index 99a07030..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc +++ /dev/null @@ -1,52 +0,0 @@ -[[specific-circuit-breaker-configuration]] -= Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addCircuitBreakerCustomizer` -method. -This can be useful for adding event handlers to Resilience4J circuit breakers. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); -} ----- -==== - -[[reactive-example]] -== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); - }; -} ----- -==== - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc deleted file mode 100644 index ed6fd092..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc +++ /dev/null @@ -1,9 +0,0 @@ -[[starters]] -= Starters -:page-section-summary-toc: 1 - -There are two starters for the Resilience4J implementations, one for reactive applications and one for non-reactive applications. - -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j` - non-reactive applications -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j` - reactive applications - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc deleted file mode 100644 index b36ce73b..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc +++ /dev/null @@ -1,13 +0,0 @@ -[[configuring-spring-retry-circuit-breakers]] -= Configuring Spring Retry Circuit Breakers -:page-section-summary-toc: 1 - -Spring Retry provides declarative retry support for Spring applications. -A subset of the project includes the ability to implement circuit breaker functionality. -Spring Retry provides a circuit breaker implementation via a combination of it's -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java[`CircuitBreakerRetryPolicy`] -and a https://github.com/spring-projects/spring-retry#stateful-retry[stateful retry]. -All circuit breakers created using Spring Retry will be created using the `CircuitBreakerRetryPolicy` and a -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/support/DefaultRetryState.java[`DefaultRetryState`]. -Both of these classes can be configured using `SpringRetryConfigBuilder`. - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/default-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/default-configuration.adoc deleted file mode 100644 index 1352476c..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/default-configuration.adoc +++ /dev/null @@ -1,19 +0,0 @@ -[[default-configuration]] -= Default Configuration -:page-section-summary-toc: 1 - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`SpringRetryCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new SpringRetryConfigBuilder(id) - .retryPolicy(new TimeoutRetryPolicy()).build()); -} ----- -==== - diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/specific-circuit-breaker-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/specific-circuit-breaker-configuration.adoc deleted file mode 100644 index e0d3c259..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry/specific-circuit-breaker-configuration.adoc +++ /dev/null @@ -1,46 +0,0 @@ -[[specific-circuit-breaker-configuration]] -= Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`SpringRetryCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addRetryTemplateCustomizers` -method. -This can be useful for adding event handlers to the `RetryTemplate`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addRetryTemplateCustomizers(retryTemplate -> retryTemplate.registerListener(new RetryListener() { - - @Override - public boolean open(RetryContext context, RetryCallback callback) { - return false; - } - - @Override - public void close(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - - @Override - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - })); -} ----- -==== diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc deleted file mode 100755 index f5afed5a..00000000 --- a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc +++ /dev/null @@ -1,23 +0,0 @@ -[[spring-cloud-circuit-breaker]] -= Spring Cloud Circuit Breaker -:page-section-summary-toc: 1 - -*{spring-cloud-version}* - -## Usage Documentation - -The Spring Cloud CircuitBreaker project contains implementations for Resilience4J and Spring Retry. -The APIs implemented in Spring Cloud CircuitBreaker live in Spring Cloud Commons. The usage documentation -for these APIs are located in the https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#spring-cloud-circuit-breaker[Spring Cloud Commons documentation]. - - - -[[building]] -== Building - -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[] - -[[contributing]] -== Contributing - -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[] diff --git a/docs/pom.xml b/docs/pom.xml deleted file mode 100644 index 98e1a92a..00000000 --- a/docs/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - spring-cloud-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - - spring-cloud-circuitbreaker-docs - pom - Spring Cloud CircuitBreaker Docs - Spring Cloud Docs - - spring-cloud-circuitbreaker - ${basedir}/.. - spring.cloud.circuit.* - deploy - - none - - - - ${project.groupId} - spring-cloud-starter-circuitbreaker-reactor-resilience4j - - - ${project.groupId} - spring-cloud-starter-circuitbreaker-resilience4j - - - ${project.groupId} - spring-cloud-circuitbreaker-spring-retry - - - - src/main/asciidoc - - - - docs - - - - pl.project13.maven - git-commit-id-plugin - - - org.apache.maven.plugins - maven-dependency-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - org.codehaus.mojo - exec-maven-plugin - - - org.asciidoctor - asciidoctor-maven-plugin - - - org.apache.maven.plugins - maven-antrun-plugin - - - maven-deploy-plugin - - - - - - - - diff --git a/docs/src/main/asciidoc/ghpages.sh b/docs/src/main/asciidoc/ghpages.sh deleted file mode 100755 index 55e76be1..00000000 --- a/docs/src/main/asciidoc/ghpages.sh +++ /dev/null @@ -1,330 +0,0 @@ -#!/bin/bash -x - -set -e - -# Set default props like MAVEN_PATH, ROOT_FOLDER etc. -function set_default_props() { - # The script should be executed from the root folder - ROOT_FOLDER=`pwd` - echo "Current folder is ${ROOT_FOLDER}" - - if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then - echo "You're not in the root folder of the project!" - exit 1 - fi - - # Prop that will let commit the changes - COMMIT_CHANGES="no" - MAVEN_PATH=${MAVEN_PATH:-} - echo "Path to Maven is [${MAVEN_PATH}]" - REPO_NAME=${PWD##*/} - echo "Repo name is [${REPO_NAME}]" - SPRING_CLOUD_STATIC_REPO=${SPRING_CLOUD_STATIC_REPO:-git@github.com:spring-cloud/spring-cloud-static.git} - echo "Spring Cloud Static repo is [${SPRING_CLOUD_STATIC_REPO}" -} - -# Check if gh-pages exists and docs have been built -function check_if_anything_to_sync() { - git remote set-url --push origin `git config remote.origin.url | sed -e 's/^git:/https:/'` - - if ! (git remote set-branches --add origin gh-pages && git fetch -q); then - echo "No gh-pages, so not syncing" - exit 0 - fi - - if ! [ -d docs/target/generated-docs ] && ! [ "${BUILD}" == "yes" ]; then - echo "No gh-pages sources in docs/target/generated-docs, so not syncing" - exit 0 - fi -} - -function retrieve_current_branch() { - # Code getting the name of the current branch. For master we want to publish as we did until now - # https://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch - # If there is a branch already passed will reuse it - otherwise will try to find it - CURRENT_BRANCH=${BRANCH} - if [[ -z "${CURRENT_BRANCH}" ]] ; then - CURRENT_BRANCH=$(git symbolic-ref -q HEAD) - CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/} - CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD} - fi - echo "Current branch is [${CURRENT_BRANCH}]" - git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script" -} - -# Switches to the provided value of the release version. We always prefix it with `v` -function switch_to_tag() { - git checkout v${VERSION} -} - -# Build the docs if switch is on -function build_docs_if_applicable() { - if [[ "${BUILD}" == "yes" ]] ; then - ./mvnw clean install -P docs -pl docs -DskipTests - fi -} - -# Get the name of the `docs.main` property -# Get whitelisted branches - assumes that a `docs` module is available under `docs` profile -function retrieve_doc_properties() { - MAIN_ADOC_VALUE=$("${MAVEN_PATH}"mvn -q \ - -Dexec.executable="echo" \ - -Dexec.args='${docs.main}' \ - --non-recursive \ - org.codehaus.mojo:exec-maven-plugin:1.3.1:exec) - echo "Extracted 'main.adoc' from Maven build [${MAIN_ADOC_VALUE}]" - - - WHITELIST_PROPERTY=${WHITELIST_PROPERTY:-"docs.whitelisted.branches"} - WHITELISTED_BRANCHES_VALUE=$("${MAVEN_PATH}"mvn -q \ - -Dexec.executable="echo" \ - -Dexec.args="\${${WHITELIST_PROPERTY}}" \ - org.codehaus.mojo:exec-maven-plugin:1.3.1:exec \ - -P docs \ - -pl docs) - echo "Extracted '${WHITELIST_PROPERTY}' from Maven build [${WHITELISTED_BRANCHES_VALUE}]" -} - -# Stash any outstanding changes -function stash_changes() { - git diff-index --quiet HEAD && dirty=$? || (echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1") - if [ "$dirty" != "0" ]; then git stash; fi -} - -# Switch to gh-pages branch to sync it with current branch -function add_docs_from_target() { - local DESTINATION_REPO_FOLDER - if [[ -z "${DESTINATION}" && -z "${CLONE}" ]] ; then - DESTINATION_REPO_FOLDER=${ROOT_FOLDER} - elif [[ "${CLONE}" == "yes" ]]; then - mkdir -p ${ROOT_FOLDER}/target - local clonedStatic=${ROOT_FOLDER}/target/spring-cloud-static - if [[ ! -e "${clonedStatic}/.git" ]]; then - echo "Cloning Spring Cloud Static to target" - git clone ${SPRING_CLOUD_STATIC_REPO} ${clonedStatic} && git checkout gh-pages - else - echo "Spring Cloud Static already cloned - will pull changes" - cd ${clonedStatic} && git checkout gh-pages && git pull origin gh-pages - fi - DESTINATION_REPO_FOLDER=${clonedStatic}/${REPO_NAME} - mkdir -p ${DESTINATION_REPO_FOLDER} - else - if [[ ! -e "${DESTINATION}/.git" ]]; then - echo "[${DESTINATION}] is not a git repository" - exit 1 - fi - DESTINATION_REPO_FOLDER=${DESTINATION}/${REPO_NAME} - mkdir -p ${DESTINATION_REPO_FOLDER} - echo "Destination was provided [${DESTINATION}]" - fi - cd ${DESTINATION_REPO_FOLDER} - git checkout gh-pages - git pull origin gh-pages - - # Add git branches - ################################################################### - if [[ -z "${VERSION}" ]] ; then - copy_docs_for_current_version - else - copy_docs_for_provided_version - fi - commit_changes_if_applicable -} - - -# Copies the docs by using the retrieved properties from Maven build -function copy_docs_for_current_version() { - if [[ "${CURRENT_BRANCH}" == "master" ]] ; then - echo -e "Current branch is master - will copy the current docs only to the root folder" - for f in docs/target/generated-docs/*; do - file=${f#docs/target/generated-docs/*} - if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then - # Not ignored... - cp -rf $f ${ROOT_FOLDER}/ - git add -A ${ROOT_FOLDER}/$file - fi - done - COMMIT_CHANGES="yes" - else - echo -e "Current branch is [${CURRENT_BRANCH}]" - # https://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin - if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then - mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH} - echo -e "Branch [${CURRENT_BRANCH}] is whitelisted! Will copy the current docs to the [${CURRENT_BRANCH}] folder" - for f in docs/target/generated-docs/*; do - file=${f#docs/target/generated-docs/*} - if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then - # Not ignored... - # We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html - if [[ "${file}" == "${MAIN_ADOC_VALUE}.html" ]] ; then - # We don't want to copy the spring-cloud-sleuth.html - # we want it to be converted to index.html - cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html - git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html - else - cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH} - git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/$file - fi - fi - done - COMMIT_CHANGES="yes" - else - echo -e "Branch [${CURRENT_BRANCH}] is not on the white list! Check out the Maven [${WHITELIST_PROPERTY}] property in - [docs] module available under [docs] profile. Won't commit any changes to gh-pages for this branch." - fi - fi -} - -# Copies the docs by using the explicitly provided version -function copy_docs_for_provided_version() { - local FOLDER=${DESTINATION_REPO_FOLDER}/${VERSION} - mkdir -p ${FOLDER} - echo -e "Current tag is [v${VERSION}] Will copy the current docs to the [${FOLDER}] folder" - for f in ${ROOT_FOLDER}/docs/target/generated-docs/*; do - file=${f#${ROOT_FOLDER}/docs/target/generated-docs/*} - copy_docs_for_branch ${file} ${FOLDER} - done - COMMIT_CHANGES="yes" - CURRENT_BRANCH="v${VERSION}" -} - -# Copies the docs from target to the provided destination -# Params: -# $1 - file from target -# $2 - destination to which copy the files -function copy_docs_for_branch() { - local file=$1 - local destination=$2 - if ! git ls-files -i -o --exclude-standard --directory | grep -q ^${file}$; then - # Not ignored... - # We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html - if [[ ("${file}" == "${MAIN_ADOC_VALUE}.html") || ("${file}" == "${REPO_NAME}.html") ]] ; then - # We don't want to copy the spring-cloud-sleuth.html - # we want it to be converted to index.html - cp -rf $f ${destination}/index.html - git add -A ${destination}/index.html - else - cp -rf $f ${destination} - git add -A ${destination}/$file - fi - fi -} - -function commit_changes_if_applicable() { - if [[ "${COMMIT_CHANGES}" == "yes" ]] ; then - COMMIT_SUCCESSFUL="no" - git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes" - - # Uncomment the following push if you want to auto push to - # the gh-pages branch whenever you commit to master locally. - # This is a little extreme. Use with care! - ################################################################### - if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then - git push origin gh-pages - fi - fi -} - -# Switch back to the previous branch and exit block -function checkout_previous_branch() { - # If -version was provided we need to come back to root project - cd ${ROOT_FOLDER} - git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script" - if [ "$dirty" != "0" ]; then git stash pop; fi - exit 0 -} - -# Assert if properties have been properly passed -function assert_properties() { -echo "VERSION [${VERSION}], DESTINATION [${DESTINATION}], CLONE [${CLONE}]" -if [[ "${VERSION}" != "" && (-z "${DESTINATION}" && -z "${CLONE}") ]] ; then echo "Version was set but destination / clone was not!"; exit 1;fi -if [[ ("${DESTINATION}" != "" && "${CLONE}" != "") && -z "${VERSION}" ]] ; then echo "Destination / clone was set but version was not!"; exit 1;fi -if [[ "${DESTINATION}" != "" && "${CLONE}" == "yes" ]] ; then echo "Destination and clone was set. Pick one!"; exit 1;fi -} - -# Prints the usage -function print_usage() { -cat </` -- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will - switch to gh-pages of that repo and copy the generated docs to `docs//` - -USAGE: - -You can use the following options: - --v|--version - the script will apply the whole procedure for a particular library version --d|--destination - the root of destination folder where the docs should be copied. You have to use the full path. - E.g. point to spring-cloud-static folder. Can't be used with (-c) --b|--build - will run the standard build process after checking out the branch --c|--clone - will automatically clone the spring-cloud-static repo instead of providing the destination. - Obviously can't be used with (-d) - -EOF -} - - -# ========================================== -# ____ ____ _____ _____ _____ _______ -# / ____|/ ____| __ \|_ _| __ \__ __| -# | (___ | | | |__) | | | | |__) | | | -# \___ \| | | _ / | | | ___/ | | -# ____) | |____| | \ \ _| |_| | | | -# |_____/ \_____|_| \_\_____|_| |_| -# -# ========================================== - -while [[ $# > 0 ]] -do -key="$1" -case ${key} in - -v|--version) - VERSION="$2" - shift # past argument - ;; - -d|--destination) - DESTINATION="$2" - shift # past argument - ;; - -b|--build) - BUILD="yes" - ;; - -c|--clone) - CLONE="yes" - ;; - -h|--help) - print_usage - exit 0 - ;; - *) - echo "Invalid option: [$1]" - print_usage - exit 1 - ;; -esac -shift # past argument or value -done - -assert_properties -set_default_props -check_if_anything_to_sync -if [[ -z "${VERSION}" ]] ; then - retrieve_current_branch -else - switch_to_tag -fi -build_docs_if_applicable -retrieve_doc_properties -stash_changes -add_docs_from_target -checkout_previous_branch \ No newline at end of file diff --git a/mvnw b/mvnw index 640b45de..41c0f0c2 100755 --- a/mvnw +++ b/mvnw @@ -8,7 +8,7 @@ # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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 @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script +# Maven Start Up Batch script # # Required ENV vars: # ------------------ @@ -34,136 +34,128 @@ # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- -if [ -z "$MAVEN_SKIP_RC" ]; then +if [ -z "$MAVEN_SKIP_RC" ] ; then - if [ -f /etc/mavenrc ]; then + if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi - if [ -f "$HOME/.mavenrc" ]; then + if [ -f "$HOME/.mavenrc" ] ; then . "$HOME/.mavenrc" fi fi # OS specific support. $var _must_ be set to either true or false. -cygwin=false -darwin=false +cygwin=false; +darwin=false; mingw=false -case "$(uname)" in -CYGWIN*) cygwin=true ;; -MINGW*) mingw=true ;; -Darwin*) - darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="$(/usr/libexec/java_home)" - else - export JAVA_HOME="/Library/Java/Home" +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi fi - fi - ;; + ;; esac -if [ -z "$JAVA_HOME" ]; then - if [ -r /etc/gentoo-release ]; then - JAVA_HOME=$(java-config --jre-home) +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` fi fi -if [ -z "$M2_HOME" ]; then +if [ -z "$M2_HOME" ] ; then ## resolve links - $0 may be a link to maven's home PRG="$0" # need this for relative symlinks - while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then PRG="$link" else - PRG="$(dirname "$PRG")/$link" + PRG="`dirname "$PRG"`/$link" fi done - saveddir=$(pwd) + saveddir=`pwd` - M2_HOME=$(dirname "$PRG")/.. + M2_HOME=`dirname "$PRG"`/.. # make it fully qualified - M2_HOME=$(cd "$M2_HOME" && pwd) + M2_HOME=`cd "$M2_HOME" && pwd` cd "$saveddir" # echo Using m2 at $M2_HOME fi # For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin; then +if $cygwin ; then [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --unix "$M2_HOME") + M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi # For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw; then +if $mingw ; then [ -n "$M2_HOME" ] && - M2_HOME="$( ( - cd "$M2_HOME" - pwd - ))" + M2_HOME="`(cd "$M2_HOME"; pwd)`" [ -n "$JAVA_HOME" ] && - JAVA_HOME="$( ( - cd "$JAVA_HOME" - pwd - ))" - # TODO classpath? + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" fi if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then - if $darwin; then - javaHome="$(dirname \"$javaExecutable\")" - javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" else - javaExecutable="$(readlink -f \"$javaExecutable\")" + javaExecutable="`readlink -f \"$javaExecutable\"`" fi - javaHome="$(dirname \"$javaExecutable\")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` JAVA_HOME="$javaHome" export JAVA_HOME fi fi fi -if [ -z "$JAVACMD" ]; then - if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD="$(which java)" + JAVACMD="`which java`" fi fi -if [ ! -x "$JAVACMD" ]; then +if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute $JAVACMD" >&2 exit 1 fi -if [ -z "$JAVA_HOME" ]; then +if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi @@ -173,24 +165,22 @@ CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - if [ -z "$1" ]; then + if [ -z "$1" ] + then echo "Path not specified to find_maven_basedir" return 1 fi basedir="$1" wdir="$1" - while [ "$wdir" != '/' ]; do - if [ -d "$wdir"/.mvn ]; then + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then basedir=$wdir break fi # workaround for JBEAP-8937 (on Solaris 10/Sparc) if [ -d "${wdir}" ]; then - wdir=$( - cd "$wdir/.." - pwd - ) + wdir=`cd "$wdir/.."; pwd` fi # end of workaround done @@ -200,13 +190,13 @@ find_maven_basedir() { # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' <"$1")" + echo "$(tr -s '\n' ' ' < "$1")" fi } -BASE_DIR=$(find_maven_basedir "$(pwd)") +BASE_DIR=`find_maven_basedir "$(pwd)"` if [ -z "$BASE_DIR" ]; then - exit 1 + exit 1; fi ########################################################################################## @@ -214,58 +204,75 @@ fi # This allows using the maven wrapper in projects that prohibit checking in binary data. ########################################################################################## if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" - while IFS="=" read key value; do - case "$key" in wrapperUrl) - jarUrl="$value" - break - ;; - esac - done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - - if command -v wget >/dev/null; then if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" + echo "Found .mvn/wrapper/maven-wrapper.jar" fi - wget "$jarUrl" -O "$wrapperJarPath" - elif command -v curl >/dev/null; then +else if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." fi - curl -o "$wrapperJarPath" "$jarUrl" - else + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" + echo "Downloading from: $jarUrl" fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." + echo "Found wget ... using wget" fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi fi - fi fi ########################################################################################## # End of extension @@ -280,36 +287,21 @@ MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java if $cygwin; then [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --path --windows "$M2_HOME") + M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` fi -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -echo "Running version check" -VERSION=$(sed '\!//' -e 's!.*$!!') -echo "The found version is [${VERSION}]" +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS -if echo $VERSION | egrep -q 'M|RC'; then - echo Activating \"milestone\" profile for version=\"$VERSION\" - echo $MAVEN_CONFIG | grep -q milestone || MAVEN_CONFIG="$MAVEN_CONFIG -Pmilestone" -else - echo Deactivating \"milestone\" profile for version=\"$VERSION\" - echo $MAVEN_CONFIG | grep -q milestone && MAVEN_CONFIG=$(echo $MAVEN_CONFIG | sed -e 's/-Pmilestone//') -fi - -if echo $VERSION | egrep -q 'RELEASE'; then - echo Activating \"central\" profile for version=\"$VERSION\" - echo $MAVEN_CONFIG | grep -q milestone || MAVEN_CONFIG="$MAVEN_CONFIG -Pcentral" -else - echo Deactivating \"central\" profile for version=\"$VERSION\" - echo $MAVEN_CONFIG | grep -q central && MAVEN_CONFIG=$(echo $MAVEN_CONFIG | sed -e 's/-Pcentral//') -fi +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain exec "$JAVACMD" \ $MAVEN_OPTS \ diff --git a/mvnw.cmd b/mvnw.cmd old mode 100755 new mode 100644 index 080c510d..86115719 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,161 +1,182 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" -FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - echo Found %WRAPPER_JAR% -) else ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" - echo Finished downloading %WRAPPER_JAR% -) -@REM End of extension - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 9eaaf079..7a5cf4cc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,197 +1,70 @@ - - + + + 4.0.0 - spring-cloud-circuitbreaker - pom - 3.1.0-SNAPSHOT + org.springframework.cloud + spring-cloud-circuitbreaker-docs-build + 0.0.1-SNAPSHOT + + Spring Cloud Circuitbreaker Docs Build + Builds Spring Cloud Circuitbreaker Docs. + https://spring.io/projects/spring-cloud-circuitbreaker + + scm:git:https://github.com/spring-cloud/spring-cloud-circuitbreaker.git + + + scm:git:git@github.com:spring-cloud/spring-cloud-circuitbreaker.git + + https://github.com/spring-cloud/spring-cloud-circuitbreaker + + + https://github.com/spring-cloud/spring-cloud-circuitbreaker/issues + - - org.springframework.cloud - spring-cloud-build - 4.1.0-SNAPSHOT - - - - 2.19.1 - jacoco - reuseReports - ${project.basedir}/../target/jacoco.exec - java - 4.1.0-SNAPSHOT + 0.0.3 - - - - org.springframework.cloud - spring-cloud-commons-dependencies - ${spring-cloud-commons.version} - pom - import - - - org.springframework.cloud - spring-cloud-circuitbreaker-dependencies - ${project.version} - pom - import - - - org.springframework.cloud - spring-cloud-test-support - test - ${spring-cloud-commons.version} - - - - - spring-cloud-circuitbreaker-dependencies - spring-cloud-circuitbreaker-resilience4j - spring-cloud-starter-circuitbreaker - docs - spring-cloud-circuitbreaker-spring-retry - + + - org.codehaus.mojo - flatten-maven-plugin - - - org.apache.maven.plugins - maven-eclipse-plugin - ${maven-eclipse-plugin.version} + io.spring.maven.antora + antora-maven-plugin + ${io.spring.maven.antora-version} + true - false - - - .settings/org.eclipse.jdt.ui.prefs - ${maven.multiModuleProjectDirectory}/eclipse/org.eclipse.jdt.ui.prefs - - - .settings/org.eclipse.jdt.core.prefs - ${maven.multiModuleProjectDirectory}/eclipse/org.eclipse.jdt.core.prefs - - + + + + + + + 9d489079e5ec46dbb238909fee5c9c29 + WB1FQYI187 + springcloudcircuitbreaker + - - io.spring.javaformat - spring-javaformat-maven-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - - spring - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - false - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - https://repo.spring.io/release - - false - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - false - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - https://repo.spring.io/libs-release-local - - false - - - - - - sonar - - - - org.jacoco - jacoco-maven-plugin - - - pre-unit-test - - prepare-agent - - - surefireArgLine - ${project.build.directory}/jacoco.exec - - - - post-unit-test - test - - report - - - - ${project.build.directory}/jacoco.exec - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${surefireArgLine} - - - - - - + + + + spring-snapshot + https://repo.spring.io/snapshot + + true + + + false + + + + spring-milestone + https://repo.spring.io/milestone + + diff --git a/spring-cloud-circuitbreaker-dependencies/pom.xml b/spring-cloud-circuitbreaker-dependencies/pom.xml deleted file mode 100644 index ed40d05f..00000000 --- a/spring-cloud-circuitbreaker-dependencies/pom.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - 4.0.0 - - - spring-cloud-dependencies-parent - org.springframework.cloud - 4.1.0-SNAPSHOT - - - - spring-cloud-circuitbreaker-dependencies - 3.1.0-SNAPSHOT - pom - spring-cloud-circuitbreaker-dependencies - Spring Cloud Circuit Breaker Dependencies - - - 2.0.2 - - - - - - io.github.resilience4j - resilience4j-bom - ${resilience4j.version} - pom - import - - - org.springframework.cloud - spring-cloud-circuitbreaker-resilience4j - ${project.version} - - - org.springframework.cloud - spring-cloud-circuitbreaker-spring-retry - ${project.version} - - - org.springframework.cloud - spring-cloud-starter-circuitbreaker-spring-retry - ${project.version} - - - org.springframework.cloud - spring-cloud-starter-circuitbreaker-resilience4j - ${project.version} - - - org.springframework.cloud - spring-cloud-starter-circuitbreaker-reactor-resilience4j - ${project.version} - - - - - - - spring - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - false - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - https://repo.spring.io/release - - false - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/libs-snapshot-local - - true - - - false - - - - spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone-local - - false - - - - - - - diff --git a/spring-cloud-circuitbreaker-resilience4j/pom.xml b/spring-cloud-circuitbreaker-resilience4j/pom.xml deleted file mode 100644 index 92557664..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - spring-cloud-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - .. - - 4.0.0 - - spring-cloud-circuitbreaker-resilience4j - spring-cloud-circuitbreaker-resilience4j - Spring Cloud Resilience4J - - - - org.springframework.cloud - spring-cloud-commons - - - io.micrometer - micrometer-observation - - - io.github.resilience4j - resilience4j-circuitbreaker - - - io.github.resilience4j - resilience4j-timelimiter - - - io.github.resilience4j - resilience4j-spring-boot3 - - - resilience4j-bulkhead - io.github.resilience4j - - - - - io.github.resilience4j - resilience4j-bulkhead - true - - - io.github.resilience4j - resilience4j-reactor - true - - - org.springframework.boot - spring-boot-starter-web - true - - - io.projectreactor - reactor-core - true - - - org.springframework.boot - spring-boot-starter-actuator - true - - - io.github.resilience4j - resilience4j-micrometer - true - - - org.springframework.boot - spring-boot-starter-webflux - test - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - test - - - io.projectreactor - reactor-test - test - - - io.micrometer - micrometer-observation-test - test - - - org.springframework.cloud - spring-cloud-test-support - - - - - diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java deleted file mode 100644 index 6589933a..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.ArrayList; -import java.util.List; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetrics; -import io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetricsPublisher; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import io.micrometer.core.instrument.MeterRegistry; -import jakarta.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Ryan Baxter - * @author Eric Bussieres - * @author Thomas Vitale - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux", - "io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator" }) -@ConditionalOnProperty(name = { "spring.cloud.circuitbreaker.resilience4j.enabled", - "spring.cloud.circuitbreaker.resilience4j.reactive.enabled" }, matchIfMissing = true) -public class ReactiveResilience4JAutoConfiguration { - - @Autowired(required = false) - private List> customizers = new ArrayList<>(); - - @Bean - @ConditionalOnMissingBean(ReactiveCircuitBreakerFactory.class) - public ReactiveResilience4JCircuitBreakerFactory reactiveResilience4JCircuitBreakerFactory( - CircuitBreakerRegistry circuitBreakerRegistry, TimeLimiterRegistry timeLimiterRegistry) { - ReactiveResilience4JCircuitBreakerFactory factory = new ReactiveResilience4JCircuitBreakerFactory( - circuitBreakerRegistry, timeLimiterRegistry); - customizers.forEach(customizer -> customizer.customize(factory)); - return factory; - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux", - "io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetrics", - "io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetricsPublisher" }) - @ConditionalOnBean({ MeterRegistry.class }) - @ConditionalOnMissingBean({ TaggedCircuitBreakerMetricsPublisher.class }) - public static class MicrometerReactiveResilience4JCustomizerConfiguration { - - @Autowired(required = false) - private ReactiveResilience4JCircuitBreakerFactory factory; - - @Autowired(required = false) - private TaggedCircuitBreakerMetrics taggedCircuitBreakerMetrics; - - @Autowired - private MeterRegistry meterRegistry; - - @PostConstruct - public void init() { - if (factory != null) { - if (taggedCircuitBreakerMetrics == null) { - taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics - .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); - } - taggedCircuitBreakerMetrics.bindTo(meterRegistry); - } - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java deleted file mode 100644 index 175e67d6..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.function.Function; - -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator; -import io.github.resilience4j.timelimiter.TimeLimiter; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.util.function.Tuple2; -import reactor.util.function.Tuples; - -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; - -import static org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreaker.CIRCUIT_BREAKER_GROUP_TAG; - -/** - * @author Ryan Baxter - * @author Thomas Vitale - * @author 荒 - */ -public class ReactiveResilience4JCircuitBreaker implements ReactiveCircuitBreaker { - - private final String id; - - private final String groupName; - - private final io.github.resilience4j.circuitbreaker.CircuitBreakerConfig circuitBreakerConfig; - - private final CircuitBreakerRegistry circuitBreakerRegistry; - - private final TimeLimiterConfig timeLimiterConfig; - - private final TimeLimiterRegistry timeLimiterRegistry; - - private final Optional> circuitBreakerCustomizer; - - public ReactiveResilience4JCircuitBreaker(String id, String groupName, - Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config, - CircuitBreakerRegistry circuitBreakerRegistry, TimeLimiterRegistry timeLimiterRegistry, - Optional> circuitBreakerCustomizer) { - this.id = id; - this.groupName = groupName; - this.circuitBreakerConfig = config.getCircuitBreakerConfig(); - this.circuitBreakerRegistry = circuitBreakerRegistry; - this.circuitBreakerCustomizer = circuitBreakerCustomizer; - this.timeLimiterConfig = config.getTimeLimiterConfig(); - this.timeLimiterRegistry = timeLimiterRegistry; - } - - @Override - public Mono run(Mono toRun, Function> fallback) { - Tuple2 tuple = buildCircuitBreakerAndTimeLimiter(); - Mono toReturn = toRun.transform(CircuitBreakerOperator.of(tuple.getT1())) - .timeout(tuple.getT2().getTimeLimiterConfig().getTimeoutDuration()) - // Since we are using the Mono timeout we need to tell the circuit breaker - // about the error - .doOnError(TimeoutException.class, - t -> tuple.getT1().onError(tuple.getT2().getTimeLimiterConfig().getTimeoutDuration().toMillis(), - TimeUnit.MILLISECONDS, t)); - if (fallback != null) { - toReturn = toReturn.onErrorResume(fallback); - } - return toReturn; - } - - @Override - public Flux run(Flux toRun, Function> fallback) { - Tuple2 tuple = buildCircuitBreakerAndTimeLimiter(); - Flux toReturn = toRun.transform(CircuitBreakerOperator.of(tuple.getT1())) - .timeout(tuple.getT2().getTimeLimiterConfig().getTimeoutDuration()) - // Since we are using the Flux timeout we need to tell the circuit breaker - // about the error - .doOnError(TimeoutException.class, - t -> tuple.getT1().onError(tuple.getT2().getTimeLimiterConfig().getTimeoutDuration().toMillis(), - TimeUnit.MILLISECONDS, t)); - if (fallback != null) { - toReturn = toReturn.onErrorResume(fallback); - } - return toReturn; - } - - private Tuple2 buildCircuitBreakerAndTimeLimiter() { - final Map tags = Map.of(CIRCUIT_BREAKER_GROUP_TAG, this.groupName); - CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(id, circuitBreakerConfig, tags); - circuitBreakerCustomizer.ifPresent(customizer -> customizer.customize(circuitBreaker)); - TimeLimiter timeLimiter = this.timeLimiterRegistry.find(this.id) - .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName) - .orElseGet(() -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, tags))); - return Tuples.of(circuitBreaker, timeLimiter); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java deleted file mode 100644 index f14f08d9..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; - -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; - -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.util.Assert; - -/** - * @author Ryan Baxter - * @author Thomas Vitale - * @author 荒 - */ -public class ReactiveResilience4JCircuitBreakerFactory extends - ReactiveCircuitBreakerFactory { - - private Function defaultConfiguration; - - private CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); - - private TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); - - private Map> circuitBreakerCustomizers = new HashMap<>(); - - public ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry circuitBreakerRegistry, - TimeLimiterRegistry timeLimiterRegistry) { - this.circuitBreakerRegistry = circuitBreakerRegistry; - this.timeLimiterRegistry = timeLimiterRegistry; - this.defaultConfiguration = id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) - .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()).build(); - } - - @Override - public ReactiveCircuitBreaker create(String id) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - return this.create(id, id); - } - - /** - * Add support group/service config on Reactive CircuitBreaker. - *
    - *
  • method(id) config - on specific method or operation
  • - *
  • Service(group) config - on specific application service or some operations
  • - *
  • global default config
  • - *
- * Descending priority from top to bottom. - *

- * @param id operation or method name - * @param groupName service group name - * @return {@link ReactiveResilience4JCircuitBreaker} - */ - @Override - public ReactiveCircuitBreaker create(String id, String groupName) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - Assert.hasText(groupName, "A CircuitBreaker must have a group name."); - Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration defaultConfig = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); - CircuitBreakerConfig circuitBreakerConfig = this.circuitBreakerRegistry.getConfiguration(id) - .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getCircuitBreakerConfig)); - TimeLimiterConfig timeLimiterConfig = this.timeLimiterRegistry.getConfiguration(id) - .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getTimeLimiterConfig)); - Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config = new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(circuitBreakerConfig).timeLimiterConfig(timeLimiterConfig).build(); - return new ReactiveResilience4JCircuitBreaker(id, groupName, config, circuitBreakerRegistry, - timeLimiterRegistry, Optional.ofNullable(circuitBreakerCustomizers.get(id))); - } - - @Override - protected Resilience4JConfigBuilder configBuilder(String id) { - return new Resilience4JConfigBuilder(id); - } - - public CircuitBreakerRegistry getCircuitBreakerRegistry() { - return circuitBreakerRegistry; - } - - public TimeLimiterRegistry getTimeLimiterRegistry() { - return timeLimiterRegistry; - } - - @Override - public void configureDefault( - Function defaultConfiguration) { - this.defaultConfiguration = defaultConfiguration; - } - - public void configureCircuitBreakerRegistry(CircuitBreakerRegistry registry) { - this.circuitBreakerRegistry = registry; - } - - public void addCircuitBreakerCustomizer(Customizer customizer, String... ids) { - for (String id : ids) { - circuitBreakerCustomizers.put(id, customizer); - } - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java deleted file mode 100644 index b728f876..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.ArrayList; -import java.util.List; - -import io.github.resilience4j.bulkhead.Bulkhead; -import io.github.resilience4j.bulkhead.BulkheadRegistry; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.micrometer.tagged.TaggedBulkheadMetrics; -import io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetrics; -import io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetricsPublisher; -import io.github.resilience4j.micrometer.tagged.TaggedThreadPoolBulkheadMetrics; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.observation.ObservationRegistry; -import jakarta.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Ryan Baxter - * @author Eric Bussieres - * @author Andrii Bohutskyi - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(Resilience4JConfigurationProperties.class) -@ConditionalOnProperty(name = { "spring.cloud.circuitbreaker.resilience4j.enabled", - "spring.cloud.circuitbreaker.resilience4j.blocking.enabled" }, matchIfMissing = true) -public class Resilience4JAutoConfiguration { - - @Autowired(required = false) - private List> customizers = new ArrayList<>(); - - @Bean - @ConditionalOnMissingBean(CircuitBreakerFactory.class) - public Resilience4JCircuitBreakerFactory resilience4jCircuitBreakerFactory( - CircuitBreakerRegistry circuitBreakerRegistry, TimeLimiterRegistry timeLimiterRegistry, - @Autowired(required = false) Resilience4jBulkheadProvider bulkheadProvider, - Resilience4JConfigurationProperties resilience4JConfigurationProperties) { - Resilience4JCircuitBreakerFactory factory = new Resilience4JCircuitBreakerFactory(circuitBreakerRegistry, - timeLimiterRegistry, bulkheadProvider, resilience4JConfigurationProperties); - customizers.forEach(customizer -> customizer.customize(factory)); - return factory; - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(Bulkhead.class) - @ConditionalOnProperty(value = "spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled", matchIfMissing = true) - public static class Resilience4jBulkheadConfiguration { - - @Autowired(required = false) - private List> bulkheadCustomizers = new ArrayList<>(); - - @Bean - public Resilience4jBulkheadProvider bulkheadProvider(ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry, - BulkheadRegistry bulkheadRegistry, - Resilience4JConfigurationProperties resilience4JConfigurationProperties) { - Resilience4jBulkheadProvider resilience4jBulkheadProvider = new Resilience4jBulkheadProvider( - threadPoolBulkheadRegistry, bulkheadRegistry, resilience4JConfigurationProperties); - bulkheadCustomizers.forEach(customizer -> customizer.customize(resilience4jBulkheadProvider)); - return resilience4jBulkheadProvider; - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnBean({ MeterRegistry.class }) - public static class MicrometerResilience4JGroupCustomizerConfiguration { - - private static final String RESILIENCE4J_METER_PREFIX = "resilience4j"; - - @Bean - @ConditionalOnProperty(value = "spring.cloud.circuitbreaker.resilience4j.enableGroupMeterFilter", - havingValue = "true", matchIfMissing = true) - MeterFilter resilience4JMeterFilter(Resilience4JConfigurationProperties properties) { - return new MeterFilter() { - @Override - public Meter.Id map(Meter.Id id) { - if (id.getName().startsWith(RESILIENCE4J_METER_PREFIX) - && id.getTag(Resilience4JCircuitBreaker.CIRCUIT_BREAKER_GROUP_TAG) == null) { - return id.withTag(Tag.of(Resilience4JCircuitBreaker.CIRCUIT_BREAKER_GROUP_TAG, - properties.getDefaultGroupTag())); - } - return id; - } - }; - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnBean({ MeterRegistry.class }) - @ConditionalOnClass(name = { "io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetrics", - "io.github.resilience4j.micrometer.tagged.TaggedCircuitBreakerMetricsPublisher" }) - @ConditionalOnMissingBean({ TaggedCircuitBreakerMetricsPublisher.class }) - public static class MicrometerResilience4JCustomizerConfiguration { - - @Autowired(required = false) - private Resilience4JCircuitBreakerFactory factory; - - @Autowired(required = false) - private Resilience4jBulkheadProvider bulkheadProvider; - - @Autowired(required = false) - private TaggedCircuitBreakerMetrics taggedCircuitBreakerMetrics; - - @Autowired - private MeterRegistry meterRegistry; - - @PostConstruct - public void init() { - if (factory != null) { - if (taggedCircuitBreakerMetrics == null) { - taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics - .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); - } - taggedCircuitBreakerMetrics.bindTo(meterRegistry); - } - if (bulkheadProvider != null) { - TaggedBulkheadMetrics.ofBulkheadRegistry(bulkheadProvider.getBulkheadRegistry()).bindTo(meterRegistry); - TaggedThreadPoolBulkheadMetrics - .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) - .bindTo(meterRegistry); - } - if (bulkheadProvider != null) { - TaggedBulkheadMetrics.ofBulkheadRegistry(bulkheadProvider.getBulkheadRegistry()).bindTo(meterRegistry); - TaggedThreadPoolBulkheadMetrics - .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) - .bindTo(meterRegistry); - } - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnBean(ObservationRegistry.class) - public static class ObservationRegistryCustomizerResilience4jCustomizer { - - @Autowired - ObservationRegistry observationRegistry; - - @Autowired(required = false) - private Resilience4JCircuitBreakerFactory factory; - - @PostConstruct - public void init() { - if (this.factory != null) { - this.factory.setObservationRegistry(this.observationRegistry); - } - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java deleted file mode 100644 index b5bf389c..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.function.Function; -import java.util.function.Supplier; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiter; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.Customizer; - -/** - * @author Ryan Baxter - * @author Andrii Bohutskyi - * @author 荒 - */ -public class Resilience4JCircuitBreaker implements CircuitBreaker { - - static final String CIRCUIT_BREAKER_GROUP_TAG = "group"; - - private final String id; - - private final String groupName; - - private Resilience4jBulkheadProvider bulkheadProvider; - - private final io.github.resilience4j.circuitbreaker.CircuitBreakerConfig circuitBreakerConfig; - - private final CircuitBreakerRegistry registry; - - private final TimeLimiterRegistry timeLimiterRegistry; - - private final TimeLimiterConfig timeLimiterConfig; - - private final ExecutorService executorService; - - private final Optional> circuitBreakerCustomizer; - - public Resilience4JCircuitBreaker(String id, String groupName, - io.github.resilience4j.circuitbreaker.CircuitBreakerConfig circuitBreakerConfig, - TimeLimiterConfig timeLimiterConfig, CircuitBreakerRegistry circuitBreakerRegistry, - TimeLimiterRegistry timeLimiterRegistry, ExecutorService executorService, - Optional> circuitBreakerCustomizer, - Resilience4jBulkheadProvider bulkheadProvider) { - this.id = id; - this.groupName = groupName; - this.circuitBreakerConfig = circuitBreakerConfig; - this.registry = circuitBreakerRegistry; - this.timeLimiterRegistry = timeLimiterRegistry; - this.timeLimiterConfig = timeLimiterConfig; - this.executorService = executorService; - this.circuitBreakerCustomizer = circuitBreakerCustomizer; - this.bulkheadProvider = bulkheadProvider; - } - - public Resilience4JCircuitBreaker(String id, String groupName, - io.github.resilience4j.circuitbreaker.CircuitBreakerConfig circuitBreakerConfig, - TimeLimiterConfig timeLimiterConfig, CircuitBreakerRegistry circuitBreakerRegistry, - TimeLimiterRegistry timeLimiterRegistry, - Optional> circuitBreakerCustomizer, - Resilience4jBulkheadProvider bulkheadProvider) { - this(id, groupName, circuitBreakerConfig, timeLimiterConfig, circuitBreakerRegistry, timeLimiterRegistry, null, - circuitBreakerCustomizer, bulkheadProvider); - } - - @Override - public T run(Supplier toRun, Function fallback) { - final Map tags = Map.of(CIRCUIT_BREAKER_GROUP_TAG, this.groupName); - TimeLimiter timeLimiter = this.timeLimiterRegistry.find(this.id) - .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName) - .orElseGet(() -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, tags))); - io.github.resilience4j.circuitbreaker.CircuitBreaker defaultCircuitBreaker = registry.circuitBreaker(this.id, - this.circuitBreakerConfig, tags); - circuitBreakerCustomizer.ifPresent(customizer -> customizer.customize(defaultCircuitBreaker)); - if (bulkheadProvider != null) { - return bulkheadProvider.run(this.groupName, toRun, fallback, defaultCircuitBreaker, timeLimiter, tags); - } - else { - if (executorService != null) { - Supplier> futureSupplier = () -> executorService.submit(toRun::get); - Callable restrictedCall = TimeLimiter.decorateFutureSupplier(timeLimiter, futureSupplier); - Callable callable = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateCallable(defaultCircuitBreaker, restrictedCall); - try { - return callable.call(); - } - catch (Throwable t) { - return fallback.apply(t); - } - } - else { - Supplier decorator = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateSupplier(defaultCircuitBreaker, toRun); - try { - return decorator.get(); - } - catch (Throwable t) { - return fallback.apply(t); - } - } - - } - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java deleted file mode 100644 index 717b7827..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Function; - -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import io.micrometer.observation.ObservationRegistry; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.observation.ObservedCircuitBreaker; -import org.springframework.util.Assert; - -/** - * @author Ryan Baxter - * @author Andrii Bohutskyi - * @author 荒 - */ -public class Resilience4JCircuitBreakerFactory extends - CircuitBreakerFactory { - - private Resilience4jBulkheadProvider bulkheadProvider; - - private Function defaultConfiguration; - - private CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); - - private TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); - - private ExecutorService executorService = Executors.newCachedThreadPool(); - - private ConcurrentHashMap executorServices = new ConcurrentHashMap<>(); - - private Map> circuitBreakerCustomizers = new HashMap<>(); - - private Resilience4JConfigurationProperties resilience4JConfigurationProperties; - - private ObservationRegistry observationRegistry = ObservationRegistry.NOOP; - - public Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry circuitBreakerRegistry, - TimeLimiterRegistry timeLimiterRegistry, Resilience4jBulkheadProvider bulkheadProvider) { - this(circuitBreakerRegistry, timeLimiterRegistry, bulkheadProvider, new Resilience4JConfigurationProperties()); - } - - public Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry circuitBreakerRegistry, - TimeLimiterRegistry timeLimiterRegistry, Resilience4jBulkheadProvider bulkheadProvider, - Resilience4JConfigurationProperties resilience4JConfigurationProperties) { - this.circuitBreakerRegistry = circuitBreakerRegistry; - this.timeLimiterRegistry = timeLimiterRegistry; - this.bulkheadProvider = bulkheadProvider; - this.defaultConfiguration = id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) - .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()).build(); - this.resilience4JConfigurationProperties = resilience4JConfigurationProperties; - } - - @Override - protected Resilience4JConfigBuilder configBuilder(String id) { - return new Resilience4JConfigBuilder(id); - } - - @Override - public void configureDefault( - Function defaultConfiguration) { - this.defaultConfiguration = defaultConfiguration; - } - - public void configureCircuitBreakerRegistry(CircuitBreakerRegistry registry) { - this.circuitBreakerRegistry = registry; - } - - public CircuitBreakerRegistry getCircuitBreakerRegistry() { - return this.circuitBreakerRegistry; - } - - public TimeLimiterRegistry getTimeLimiterRegistry() { - return this.timeLimiterRegistry; - } - - public Resilience4jBulkheadProvider getBulkheadProvider() { - return this.bulkheadProvider; - } - - public void configureExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - - @Override - public org.springframework.cloud.client.circuitbreaker.CircuitBreaker create(String id) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - Resilience4JCircuitBreaker resilience4JCircuitBreaker = create(id, id, this.executorService); - return tryObservedCircuitBreaker(resilience4JCircuitBreaker); - } - - @Override - public org.springframework.cloud.client.circuitbreaker.CircuitBreaker create(String id, String groupName) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - Assert.hasText(groupName, "A CircuitBreaker must have a group name."); - final ExecutorService groupExecutorService = executorServices.computeIfAbsent(groupName, - group -> Executors.newCachedThreadPool()); - Resilience4JCircuitBreaker resilience4JCircuitBreaker = create(id, groupName, groupExecutorService); - return tryObservedCircuitBreaker(resilience4JCircuitBreaker); - } - - private org.springframework.cloud.client.circuitbreaker.CircuitBreaker tryObservedCircuitBreaker( - Resilience4JCircuitBreaker resilience4JCircuitBreaker) { - if (this.observationRegistry.isNoop()) { - return resilience4JCircuitBreaker; - } - return new ObservedCircuitBreaker(resilience4JCircuitBreaker, this.observationRegistry); - } - - public void addCircuitBreakerCustomizer(Customizer customizer, String... ids) { - for (String id : ids) { - circuitBreakerCustomizers.put(id, customizer); - } - } - - /** - * Add support group/service config on CircuitBreaker. - *

    - *
  • method(id) config - on specific method or operation
  • - *
  • Service(group) config - on specific application service or some operations
  • - *
  • global default config
  • - *
- * Descending priority from top to bottom. - *

- * @param id operation or method name - * @param groupName service group name - * @return {@link Resilience4JCircuitBreaker} - */ - private Resilience4JCircuitBreaker create(String id, String groupName, - ExecutorService circuitBreakerExecutorService) { - Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration defaultConfig = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); - CircuitBreakerConfig circuitBreakerConfig = this.circuitBreakerRegistry.getConfiguration(id) - .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getCircuitBreakerConfig)); - TimeLimiterConfig timeLimiterConfig = this.timeLimiterRegistry.getConfiguration(id) - .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getTimeLimiterConfig)); - if (resilience4JConfigurationProperties.isDisableThreadPool()) { - return new Resilience4JCircuitBreaker(id, groupName, circuitBreakerConfig, timeLimiterConfig, - circuitBreakerRegistry, timeLimiterRegistry, Optional.ofNullable(circuitBreakerCustomizers.get(id)), - bulkheadProvider); - } - else { - return new Resilience4JCircuitBreaker(id, groupName, circuitBreakerConfig, timeLimiterConfig, - circuitBreakerRegistry, timeLimiterRegistry, circuitBreakerExecutorService, - Optional.ofNullable(circuitBreakerCustomizers.get(id)), bulkheadProvider); - } - - } - - public void setObservationRegistry(ObservationRegistry observationRegistry) { - this.observationRegistry = observationRegistry; - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigBuilder.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigBuilder.java deleted file mode 100644 index 24710f99..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigBuilder.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; - -import org.springframework.cloud.client.circuitbreaker.ConfigBuilder; - -/** - * @author Ryan Baxter - */ -public class Resilience4JConfigBuilder - implements ConfigBuilder { - - private String id; - - private TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.ofDefaults(); - - private CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.ofDefaults(); - - public Resilience4JConfigBuilder(String id) { - this.id = id; - } - - public Resilience4JConfigBuilder timeLimiterConfig(TimeLimiterConfig config) { - this.timeLimiterConfig = config; - return this; - } - - public Resilience4JConfigBuilder circuitBreakerConfig(CircuitBreakerConfig circuitBreakerConfig) { - this.circuitBreakerConfig = circuitBreakerConfig; - return this; - } - - @Override - public Resilience4JCircuitBreakerConfiguration build() { - Resilience4JCircuitBreakerConfiguration config = new Resilience4JCircuitBreakerConfiguration(); - config.setId(id); - config.setCircuitBreakerConfig(circuitBreakerConfig); - config.setTimeLimiterConfig(timeLimiterConfig); - return config; - } - - public static class Resilience4JCircuitBreakerConfiguration { - - private String id; - - private TimeLimiterConfig timeLimiterConfig; - - private CircuitBreakerConfig circuitBreakerConfig; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TimeLimiterConfig getTimeLimiterConfig() { - return timeLimiterConfig; - } - - public void setTimeLimiterConfig(TimeLimiterConfig timeLimiterConfig) { - this.timeLimiterConfig = timeLimiterConfig; - } - - public CircuitBreakerConfig getCircuitBreakerConfig() { - return circuitBreakerConfig; - } - - public void setCircuitBreakerConfig(CircuitBreakerConfig circuitBreakerConfig) { - this.circuitBreakerConfig = circuitBreakerConfig; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigurationProperties.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigurationProperties.java deleted file mode 100644 index fcfc2ea7..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JConfigurationProperties.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @author Ryan Baxter - */ -@ConfigurationProperties("spring.cloud.circuitbreaker.resilience4j") -public class Resilience4JConfigurationProperties { - - private boolean enableGroupMeterFilter = true; - - private String defaultGroupTag = "none"; - - private boolean enableSemaphoreDefaultBulkhead = false; - - private boolean disableThreadPool = false; - - public boolean isEnableGroupMeterFilter() { - return enableGroupMeterFilter; - } - - public void setEnableGroupMeterFilter(boolean enableGroupMeterFilter) { - this.enableGroupMeterFilter = enableGroupMeterFilter; - } - - public String getDefaultGroupTag() { - return defaultGroupTag; - } - - public void setDefaultGroupTag(String defaultGroupTag) { - this.defaultGroupTag = defaultGroupTag; - } - - public boolean isEnableSemaphoreDefaultBulkhead() { - return enableSemaphoreDefaultBulkhead; - } - - public void setEnableSemaphoreDefaultBulkhead(boolean enableSemaphoreDefaultBulkhead) { - this.enableSemaphoreDefaultBulkhead = enableSemaphoreDefaultBulkhead; - } - - public boolean isDisableThreadPool() { - return disableThreadPool; - } - - public void setDisableThreadPool(boolean disableThreadPool) { - this.disableThreadPool = disableThreadPool; - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadConfigurationBuilder.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadConfigurationBuilder.java deleted file mode 100644 index 307fb8bd..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadConfigurationBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2013-2020 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.bulkhead.BulkheadConfig; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig; - -/** - * @author Andrii Bohutskyi - */ -public class Resilience4jBulkheadConfigurationBuilder { - - private BulkheadConfig bulkheadConfig = BulkheadConfig.ofDefaults(); - - private ThreadPoolBulkheadConfig threadPoolBulkheadConfig = ThreadPoolBulkheadConfig.ofDefaults(); - - public Resilience4jBulkheadConfigurationBuilder bulkheadConfig(BulkheadConfig bulkheadConfig) { - this.bulkheadConfig = bulkheadConfig; - return this; - } - - public Resilience4jBulkheadConfigurationBuilder threadPoolBulkheadConfig( - ThreadPoolBulkheadConfig threadPoolBulkheadConfig) { - this.threadPoolBulkheadConfig = threadPoolBulkheadConfig; - return this; - } - - public BulkheadConfiguration build() { - BulkheadConfiguration configuration = new BulkheadConfiguration(); - configuration.setBulkheadConfig(this.bulkheadConfig); - configuration.setThreadPoolBulkheadConfig(this.threadPoolBulkheadConfig); - return configuration; - } - - public static class BulkheadConfiguration { - - private BulkheadConfig bulkheadConfig; - - private ThreadPoolBulkheadConfig threadPoolBulkheadConfig; - - public void setBulkheadConfig(BulkheadConfig bulkheadConfig) { - this.bulkheadConfig = bulkheadConfig; - } - - public ThreadPoolBulkheadConfig getThreadPoolBulkheadConfig() { - return threadPoolBulkheadConfig; - } - - public void setThreadPoolBulkheadConfig(ThreadPoolBulkheadConfig threadPoolBulkheadConfig) { - this.threadPoolBulkheadConfig = threadPoolBulkheadConfig; - } - - public BulkheadConfig getBulkheadConfig() { - return bulkheadConfig; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java deleted file mode 100644 index 32b4f654..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Future; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -import io.github.resilience4j.bulkhead.Bulkhead; -import io.github.resilience4j.bulkhead.BulkheadRegistry; -import io.github.resilience4j.bulkhead.ThreadPoolBulkhead; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.timelimiter.TimeLimiter; - -import org.springframework.cloud.client.circuitbreaker.Customizer; - -/** - * @author Andrii Bohutskyi - */ -public class Resilience4jBulkheadProvider { - - private final ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry; - - private final BulkheadRegistry bulkheadRegistry; - - private final ConcurrentHashMap configurations = new ConcurrentHashMap<>(); - - private Function defaultConfiguration; - - private boolean semaphoreDefaultBulkhead = false; - - public Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry, - BulkheadRegistry bulkheadRegistry, - Resilience4JConfigurationProperties resilience4JConfigurationProperties) { - this.bulkheadRegistry = bulkheadRegistry; - this.threadPoolBulkheadRegistry = threadPoolBulkheadRegistry; - defaultConfiguration = id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(this.bulkheadRegistry.getDefaultConfig()) - .threadPoolBulkheadConfig(this.threadPoolBulkheadRegistry.getDefaultConfig()).build(); - this.semaphoreDefaultBulkhead = resilience4JConfigurationProperties.isEnableSemaphoreDefaultBulkhead(); - } - - public void configureDefault( - Function defaultConfiguration) { - this.defaultConfiguration = defaultConfiguration; - } - - public void configure(Consumer consumer, String... ids) { - for (String id : ids) { - Resilience4jBulkheadConfigurationBuilder builder = new Resilience4jBulkheadConfigurationBuilder(); - consumer.accept(builder); - Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = builder.build(); - configurations.put(id, configuration); - } - } - - public void addBulkheadCustomizer(Customizer customizer, String... ids) { - for (String id : ids) { - Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); - Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig()); - customizer.customize(bulkhead); - } - } - - public void addThreadPoolBulkheadCustomizer(Customizer customizer, String... ids) { - for (String id : ids) { - Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); - ThreadPoolBulkhead threadPoolBulkhead = threadPoolBulkheadRegistry.bulkhead(id, - configuration.getThreadPoolBulkheadConfig()); - customizer.customize(threadPoolBulkhead); - } - } - - protected BulkheadRegistry getBulkheadRegistry() { - return bulkheadRegistry; - } - - protected ThreadPoolBulkheadRegistry getThreadPoolBulkheadRegistry() { - return threadPoolBulkheadRegistry; - } - - public T run(String id, Supplier toRun, Function fallback, CircuitBreaker circuitBreaker, - TimeLimiter timeLimiter, Map tags) { - Supplier> bulkheadCall = decorateBulkhead(id, tags, toRun); - final Callable timeLimiterCall = decorateTimeLimiter(bulkheadCall, timeLimiter); - final Callable circuitBreakerCall = circuitBreaker.decorateCallable(timeLimiterCall); - try { - return circuitBreakerCall.call(); - } - catch (Throwable t) { - return fallback.apply(t); - } - } - - private Supplier> decorateBulkhead(final String id, final Map tags, - final Supplier supplier) { - Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); - - if (semaphoreDefaultBulkhead - || (bulkheadRegistry.find(id).isPresent() && !threadPoolBulkheadRegistry.find(id).isPresent())) { - Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig(), tags); - Supplier> completionStageSupplier = () -> CompletableFuture.supplyAsync(supplier); - return Bulkhead.decorateCompletionStage(bulkhead, completionStageSupplier); - } - else { - ThreadPoolBulkhead threadPoolBulkhead = threadPoolBulkheadRegistry.bulkhead(id, - configuration.getThreadPoolBulkheadConfig(), tags); - return threadPoolBulkhead.decorateSupplier(supplier); - } - } - - private Callable decorateTimeLimiter(final Supplier> supplier, TimeLimiter timeLimiter) { - final Supplier> futureSupplier = () -> supplier.get().toCompletableFuture(); - return timeLimiter.decorateFutureSupplier(futureSupplier); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 7d91959a..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "properties": [ - { - "defaultValue": "true", - "name": "spring.cloud.circuitbreaker.resilience4j.enabled", - "description": "Enables Resilience4J auto-configuration.", - "type": "java.lang.Boolean" - }, - { - "defaultValue": "true", - "name": "spring.cloud.circuitbreaker.resilience4j.blocking.enabled", - "description": "Enables blocking Resilience4J auto-configuration.", - "type": "java.lang.Boolean" - }, - { - "defaultValue": "true", - "name": "spring.cloud.circuitbreaker.resilience4j.reactive.enabled", - "description": "Enables ReactiveResilience4J auto-configuration.", - "type": "java.lang.Boolean" - }, - { - "defaultValue": "true", - "name": "spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled", - "description": "Enables to use of the Bulkhead by Resilience4j.", - "type": "java.lang.Boolean" - } - ] -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 7d762b8e..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JAutoConfiguration -org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JAutoConfiguration diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java deleted file mode 100644 index 06bb4377..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.Optional; - -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiter; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import reactor.core.publisher.Mono; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author Thomas Vitale - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ReactiveResilience4JAutoConfigurationPropertyTest.class) -@EnableAutoConfiguration -@ActiveProfiles(profiles = "test-properties") -public class ReactiveResilience4JAutoConfigurationPropertyTest { - - @Autowired - ReactiveResilience4JCircuitBreakerFactory factory; - - @Test - public void testCircuitBreakerPropertiesPopulated() { - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - assertThat(circuitBreakerRegistry).isNotNull(); - assertThat(circuitBreakerRegistry.find("test_circuit")).isPresent(); - assertThat( - circuitBreakerRegistry.find("test_circuit").get().getCircuitBreakerConfig().getMinimumNumberOfCalls()) - .isEqualTo(5); - } - - @Test - public void testTimeLimiterPropertiesPopulated() { - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry).isNotNull(); - assertThat(timeLimiterRegistry.find("test_circuit")).isPresent(); - assertThat(timeLimiterRegistry.find("test_circuit").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofSeconds(18)); - } - - @Test - public void testDefaultCircuitBreakerPropertiesPopulated() { - factory.create("default_circuitBreaker").run(Mono.just("result")); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - assertThat(circuitBreakerRegistry).isNotNull(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker").get().getCircuitBreakerConfig() - .getMinimumNumberOfCalls()).isEqualTo(20); - } - - @Test - public void testDefaultTimeLimiterPropertiesPopulated() { - factory.create("default_circuitBreaker").run(Mono.just("result")); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry).isNotNull(); - assertThat(timeLimiterRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(timeLimiterRegistry.find("default_circuitBreaker").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofMillis(150)); - } - - @Test - public void testTestGroupCircuitBreakerPropertiesPopulated() { - factory.create("a_in_test_group", "test_group").run(Mono.just("result")); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("a_in_test_group"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(30); - } - - @Test - public void testTestGroupTimeLimiterPropertiesPopulated() { - factory.create("a_in_test_group", "test_group").run(Mono.just("result")); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - Optional timeLimiter = timeLimiterRegistry.find("a_in_test_group"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofMillis(500)); - } - - @Test - public void testTestCircuitTimeLimiterPropertiesPopulated() { - factory.create("test_circuit", "test_group").run(Mono.just("result")); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - Optional timeLimiter = timeLimiterRegistry.find("test_circuit"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofSeconds(18)); - } - - @Test - public void testTestCircuitCircuitBreakerPropertiesPopulated() { - factory.create("test_circuit", "test_group").run(Mono.just("result")); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("test_circuit"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(5); - } - - @Test - public void testTestIdCircuitBreakerPropertiesPopulated() { - factory.create("test_id", "test_group").run(Mono.just("result")); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("test_id"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(10); - } - - @Test - public void testTestGroupInstanceTimeLimiterPropertiesPopulated() { - factory.create("a_in_test_group_instance", "test_group_instance").run(Mono.just("result")); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry.find("a_in_test_group_instance")).isNotPresent(); - Optional timeLimiter = timeLimiterRegistry.find("test_group_instance"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofMillis(600)); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java deleted file mode 100644 index f038247e..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; - -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author Ryan Baxter - * @author Thomas Vitale - */ -@RunWith(ModifiedClassPathRunner.class) -@ClassPathExclusions({ "micrometer-core-*.jar", "resilience4j-micrometer-*.jar" }) -public class ReactiveResilience4JAutoConfigurationWithoutMetricsTest { - - static ReactiveResilience4JCircuitBreakerFactory circuitBreakerFactory = spy( - new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults())); - - @Test - public void testWithoutMetrics() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { - verify(circuitBreakerFactory, times(0)).getCircuitBreakerRegistry(); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestApp { - - @Bean - ReactiveResilience4JCircuitBreakerFactory circuitBreakerFactory() { - return circuitBreakerFactory; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java deleted file mode 100644 index a3935f24..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.List; -import java.util.Map; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnErrorEvent; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnSuccessEvent; -import io.github.resilience4j.core.EventConsumer; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Ryan Baxter - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, - classes = ReactiveResilience4JCircuitBreakerIntegrationTest.Application.class, - properties = { "management.endpoints.web.exposure.include=*" }) -@DirtiesContext -public class ReactiveResilience4JCircuitBreakerIntegrationTest { - - @Mock - static EventConsumer slowErrorConsumer; - - @Mock - static EventConsumer slowSuccessConsumer; - - @Mock - static EventConsumer normalErrorConsumer; - - @Mock - static EventConsumer normalSuccessConsumer; - - @Mock - static EventConsumer slowFluxErrorConsumer; - - @Mock - static EventConsumer slowFluxSuccessConsumer; - - @Mock - static EventConsumer normalFluxErrorConsumer; - - @Mock - static EventConsumer normalFluxSuccessConsumer; - - @LocalServerPort - int port = 0; - - @Autowired - ReactiveResilience4JCircuitBreakerIntegrationTest.Application.DemoControllerService service; - - @Autowired - private WebTestClient webClient; - - @Before - public void setup() { - service.setPort(port); - } - - @Test - public void test() { - StepVerifier.create(service.normal()).expectNext("normal").expectComplete().verify(); - verify(normalErrorConsumer, times(0)).consumeEvent(any()); - verify(normalSuccessConsumer, times(1)).consumeEvent(any()); - StepVerifier.withVirtualTime(() -> service.slow()).expectSubscription().expectNoEvent(Duration.ofSeconds(2)) - .expectNext("fallback").expectComplete().verify(); - verify(slowErrorConsumer, times(1)).consumeEvent(any()); - verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - StepVerifier.create(service.normalFlux()).expectNext("normalflux").verifyComplete(); - verify(normalFluxErrorConsumer, times(0)).consumeEvent(any()); - verify(normalFluxSuccessConsumer, times(1)).consumeEvent(any()); - StepVerifier.create(service.slowFlux()).expectNext("fluxfallback").verifyComplete(); - verify(slowFluxErrorConsumer, times(1)).consumeEvent(any()); - verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - assertThat( - ((List) webClient.get().uri("/actuator/metrics").exchange().expectStatus().isOk().expectBody(Map.class) - .returnResult().getResponseBody().get("names")).contains("resilience4j.circuitbreaker.calls")) - .isTrue(); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - public Mono slow() { - return Mono.just("slow").delayElement(Duration.ofSeconds(3)); - } - - @GetMapping("/normal") - public Mono normal() { - return Mono.just("normal"); - } - - @GetMapping("/slowflux") - public Flux slowFlux() { - return Flux.just("slow", "flux").delayElements(Duration.ofSeconds(3)); - } - - @GetMapping("normalflux") - public Flux normalFlux() { - return Flux.just("normal", "flux"); - } - - @Bean - public Customizer slowCusomtizer() { - return factory -> { - factory.configureDefault( - id -> new Resilience4JConfigBuilder(id).circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig( - TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .build()); - factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowFluxErrorConsumer).onSuccess(slowFluxSuccessConsumer), "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); - }; - } - - @Service - public static class DemoControllerService { - - private int port = 0; - - private final ReactiveCircuitBreakerFactory cbFactory; - - private final ReactiveCircuitBreaker circuitBreakerSlow; - - DemoControllerService(ReactiveCircuitBreakerFactory cbFactory) { - this.cbFactory = cbFactory; - this.circuitBreakerSlow = cbFactory.create("slow"); - } - - public Mono slow() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/slow").retrieve() - .bodyToMono(String.class).transform(it -> circuitBreakerSlow.run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - - public Mono normal() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/normal").retrieve() - .bodyToMono(String.class).transform(it -> cbFactory.create("normal").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - - public Flux slowFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/slowflux").retrieve() - .bodyToFlux(new ParameterizedTypeReference() { - }).transform(it -> cbFactory.create("slowflux").run(it, t -> { - t.printStackTrace(); - return Flux.just("fluxfallback"); - })); - } - - public Flux normalFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/normalflux") - .retrieve().bodyToFlux(String.class) - .transform(it -> cbFactory.create("normalflux").run(it, t -> { - t.printStackTrace(); - return Flux.just("fluxfallback"); - })); - } - - public void setPort(int port) { - this.port = port; - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java deleted file mode 100644 index 352ee51b..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.util.Arrays; -import java.util.Collections; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Ryan Baxter - * @author Thomas Vitale - */ -public class ReactiveResilience4JCircuitBreakerTest { - - @Test - public void runMono() { - ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults()).create("foo"); - assertThat(Mono.just("foobar").transform(cb::run).block()).isEqualTo("foobar"); - } - - @Test - public void runMonoWithFallback() { - ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults()).create("foo"); - assertThat(Mono.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Mono.just("fallback"))) - .block()).isEqualTo("fallback"); - } - - @Test - public void runFlux() { - ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults()).create("foo"); - assertThat(Flux.just("foobar", "hello world").transform(cb::run).collectList().block()) - .isEqualTo(Arrays.asList("foobar", "hello world")); - } - - @Test - public void runFluxWithFallback() { - ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults()).create("foo"); - assertThat(Flux.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Flux.just("fallback"))) - .collectList().block()).isEqualTo(Collections.singletonList("fallback")); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java deleted file mode 100644 index fcdbf968..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2013-2021 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author Ryan Baxter - */ -@RunWith(SpringRunner.class) -public class Resilience4JAutoConfigurationMetricsConfigRun { - - static ReactiveResilience4JCircuitBreakerFactory reactiveCircuitBreakerFactory = spy( - new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults())); - - static Resilience4JCircuitBreakerFactory circuitBreakerFactory = spy( - new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), - mock(Resilience4jBulkheadProvider.class), new Resilience4JConfigurationProperties())); - - @Test - public void testWithMetricsConfigReactive() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .properties("resilience4j.circuitbreaker.metrics.legacy.enabled").sources(TestAppReactive.class) - .run()) { - verify(reactiveCircuitBreakerFactory, times(1)).getCircuitBreakerRegistry(); - } - } - - @Test - public void testWithMetricsConfig() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .properties("resilience4j.circuitbreaker.metrics.legacy.enabled").sources(TestApp.class).run()) { - verify(circuitBreakerFactory, times(1)).getCircuitBreakerRegistry(); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestAppReactive { - - @Bean - ReactiveResilience4JCircuitBreakerFactory reativeCircuitBreakerFactory() { - return reactiveCircuitBreakerFactory; - } - - @Bean - Resilience4JCircuitBreakerFactory circuitBreakerFactory() { - return circuitBreakerFactory; - } - - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestApp { - - @Bean - Resilience4JCircuitBreakerFactory circuitBreakerFactory() { - return circuitBreakerFactory; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java deleted file mode 100644 index 11ed10e4..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2013-2020 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.Optional; - -import io.github.resilience4j.bulkhead.BulkheadRegistry; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.circuitbreaker.CircuitBreaker; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiter; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author Andrii Bohutskyi - * @author 荒 - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Resilience4JAutoConfigurationPropertyTest.class) -@EnableAutoConfiguration -@ActiveProfiles(profiles = "test-properties") -public class Resilience4JAutoConfigurationPropertyTest { - - @Autowired - Resilience4JCircuitBreakerFactory factory; - - @Test - public void testCircuitBreakerPropertiesPopulated() { - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - assertThat(circuitBreakerRegistry).isNotNull(); - assertThat(circuitBreakerRegistry.find("test_circuit")).isPresent(); - assertThat( - circuitBreakerRegistry.find("test_circuit").get().getCircuitBreakerConfig().getMinimumNumberOfCalls()) - .isEqualTo(5); - } - - @Test - public void testTimeLimiterPropertiesPopulated() { - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry).isNotNull(); - assertThat(timeLimiterRegistry.find("test_circuit")).isPresent(); - assertThat(timeLimiterRegistry.find("test_circuit").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofSeconds(18)); - } - - @Test - public void testThreadPoolBulkheadPropertiesPopulated() { - ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry = factory.getBulkheadProvider() - .getThreadPoolBulkheadRegistry(); - assertThat(threadPoolBulkheadRegistry).isNotNull(); - assertThat(threadPoolBulkheadRegistry.find("test_circuit")).isPresent(); - assertThat(threadPoolBulkheadRegistry.find("test_circuit").get().getBulkheadConfig().getMaxThreadPoolSize()) - .isEqualTo(100); - } - - @Test - public void testBulkheadPropertiesPopulated() { - BulkheadRegistry bulkheadRegistry = factory.getBulkheadProvider().getBulkheadRegistry(); - assertThat(bulkheadRegistry).isNotNull(); - assertThat(bulkheadRegistry.find("test_circuit")).isPresent(); - assertThat(bulkheadRegistry.find("test_circuit").get().getBulkheadConfig().getMaxConcurrentCalls()) - .isEqualTo(50); - } - - @Test - public void testDefaultCircuitBreakerPropertiesPopulated() { - factory.create("default_circuitBreaker").run(() -> "result"); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - assertThat(circuitBreakerRegistry).isNotNull(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker").get().getCircuitBreakerConfig() - .getMinimumNumberOfCalls()).isEqualTo(20); - } - - @Test - public void testDefaultTimeLimiterPropertiesPopulated() { - factory.create("default_circuitBreaker").run(() -> "result"); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry).isNotNull(); - assertThat(timeLimiterRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(timeLimiterRegistry.find("default_circuitBreaker").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofMillis(150)); - } - - @Test - public void testDefaultThreadPoolBulkheadPropertiesPopulated() { - factory.create("default_circuitBreaker").run(() -> "result"); - ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry = factory.getBulkheadProvider() - .getThreadPoolBulkheadRegistry(); - assertThat(threadPoolBulkheadRegistry).isNotNull(); - assertThat(threadPoolBulkheadRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(threadPoolBulkheadRegistry.find("default_circuitBreaker").get().getBulkheadConfig() - .getMaxThreadPoolSize()).isEqualTo(50); - } - - @Test - public void testTestGroupCircuitBreakerPropertiesPopulated() { - factory.create("a_in_test_group", "test_group").run(() -> "result"); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("a_in_test_group"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(30); - } - - @Test - public void testTestGroupTimeLimiterPropertiesPopulated() { - factory.create("a_in_test_group", "test_group").run(() -> "result"); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - Optional timeLimiter = timeLimiterRegistry.find("a_in_test_group"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofMillis(500)); - } - - @Test - public void testTestCircuitTimeLimiterPropertiesPopulated() { - factory.create("test_circuit", "test_group").run(() -> "result"); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - Optional timeLimiter = timeLimiterRegistry.find("test_circuit"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofSeconds(18)); - } - - @Test - public void testTestCircuitCircuitBreakerPropertiesPopulated() { - factory.create("test_circuit", "test_group").run(() -> "result"); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("test_circuit"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(5); - } - - @Test - public void testTestIdCircuitBreakerPropertiesPopulated() { - factory.create("test_id", "test_group").run(() -> "result"); - CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); - Optional circuitBreaker = circuitBreakerRegistry.find("test_id"); - assertThat(circuitBreaker).isPresent(); - assertThat(circuitBreaker.get().getCircuitBreakerConfig().getMinimumNumberOfCalls()).isEqualTo(10); - } - - @Test - public void testTestGroupInstanceTimeLimiterPropertiesPopulated() { - factory.create("a_in_test_group_instance", "test_group_instance").run(() -> "result"); - TimeLimiterRegistry timeLimiterRegistry = factory.getTimeLimiterRegistry(); - assertThat(timeLimiterRegistry.find("a_in_test_group_instance")).isNotPresent(); - Optional timeLimiter = timeLimiterRegistry.find("test_group_instance"); - assertThat(timeLimiter).isPresent(); - assertThat(timeLimiter.get().getTimeLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofMillis(600)); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java deleted file mode 100644 index 2499cff8..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.spy; - -/** - * @author Ryan Baxter - */ -public class Resilience4JAutoConfigurationTests { - - static Resilience4JCircuitBreakerFactory circuitBreakerFactory = spy( - new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), - null, new Resilience4JConfigurationProperties())); - - @Test - public void meterFilterEnabled() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(Resilience4JAutoConfigurationTests.TestApp.class).run()) { - assertThat(context.getBean("resilience4JMeterFilter")).isNotNull(); - } - } - - @Test - public void meterFilterDisabled() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(Resilience4JAutoConfigurationTests.TestApp.class) - .properties("spring.cloud.circuitbreaker.resilience4j.enableGroupMeterFilter=false").run()) { - assertThat(context.containsBean("resilience4JMeterFilter")).isFalse(); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestApp { - - @Bean - Resilience4JCircuitBreakerFactory circuitBreakerFactory() { - return circuitBreakerFactory; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java deleted file mode 100644 index db9b7bd5..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013-2020 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; -import org.springframework.context.ConfigurableApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Andrii Bohutskyi - */ -@RunWith(ModifiedClassPathRunner.class) -@ClassPathExclusions("resilience4j-bulkhead-*.jar") -public class Resilience4JAutoConfigurationWithoutBulkheadTest { - - @Test - public void testWithoutBulkhead() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { - assertThat(context.containsBean("bulkheadProvider")).isFalse(); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestApp { - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java deleted file mode 100644 index 0ca3e7ef..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; - -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author Ryan Baxter - */ -@RunWith(ModifiedClassPathRunner.class) -@ClassPathExclusions({ "micrometer-core-*.jar", "resilience4j-micrometer-*.jar", "reactor-core-*.jar", - "reactor-netty-*.jar", "spring-webflux-*.jar" }) -public class Resilience4JAutoConfigurationWithoutMetricsTest { - - static Resilience4JCircuitBreakerFactory circuitBreakerFactory = spy( - new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), - null, new Resilience4JConfigurationProperties())); - - @Test - public void testWithoutMetrics() { - try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { - verify(circuitBreakerFactory, times(0)).getCircuitBreakerRegistry(); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class TestApp { - - @Bean - Resilience4JCircuitBreakerFactory circuitBreakerFactory() { - return circuitBreakerFactory; - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java deleted file mode 100644 index 1b06f038..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright 2013-2020 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import io.github.resilience4j.bulkhead.BulkheadConfig; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig; -import io.github.resilience4j.bulkhead.event.BulkheadOnCallFinishedEvent; -import io.github.resilience4j.bulkhead.event.BulkheadOnCallRejectedEvent; -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnErrorEvent; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnSuccessEvent; -import io.github.resilience4j.core.EventConsumer; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Andrii Bohutskyi - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = Resilience4JBulkheadIntegrationTest.Application.class, - properties = { "management.endpoints.web.exposure.include=*" }) -@DirtiesContext -public class Resilience4JBulkheadIntegrationTest { - - @Mock - static EventConsumer slowErrorConsumer; - - @Mock - static EventConsumer slowSuccessConsumer; - - @Mock - static EventConsumer normalErrorConsumer; - - @Mock - static EventConsumer normalSuccessConsumer; - - @Autowired - Application.DemoControllerService service; - - @Autowired - private TestRestTemplate rest; - - @Test - public void testSlow() { - assertThat(service.slow()).isEqualTo("fallback"); - verify(slowErrorConsumer, times(1)).consumeEvent(any()); - verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - } - - @Test - public void testNormal() { - assertThat(service.normal()).isEqualTo("normal"); - verify(normalErrorConsumer, times(0)).consumeEvent(any()); - verify(normalSuccessConsumer, times(1)).consumeEvent(any()); - } - - @Test - public void testSlowResponsesDontFailSubsequentGoodRequests() { - assertThat(service.slowOnDemand(5000)).isEqualTo("fallback"); - assertThat(service.slowOnDemand(0)).isEqualTo("normal"); - } - - @Test - public void testBulkheadTwoParallelSlowOneNotPermitted() throws InterruptedException { - ExecutorService executorService = Executors.newFixedThreadPool(2); - executorService.submit(() -> service.slowBulkhead()); - executorService.submit(() -> service.slowBulkhead()); - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - - verify(Application.slowRejectedConsumer, times(1)).consumeEvent(any()); - verify(Application.slowFinishedConsumer, times(1)).consumeEvent(any()); - } - - @Test - public void testThreadPoolBulkheadThreeParallelSlowOneNotPermitted() throws InterruptedException { - ExecutorService executorService = Executors.newFixedThreadPool(3); - executorService.submit(() -> service.slowThreadPoolBulkhead()); - executorService.submit(() -> service.slowThreadPoolBulkhead()); - executorService.submit(() -> service.slowThreadPoolBulkhead()); - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - - verify(Application.slowThreadPoolFinishedConsumer, times(2)).consumeEvent(any()); - verify(Application.slowThreadPoolRejectedConsumer, times(1)).consumeEvent(any()); - } - - @Test - public void testResilience4JMetricsAvailable() { - assertThat(service.normal()).isEqualTo("normal"); - assertThat(((List) rest.getForObject("/actuator/metrics", Map.class).get("names")) - .contains("resilience4j.bulkhead.max.thread.pool.size")).isTrue(); - - assertThat(((List) rest - .getForObject("/actuator/metrics/resilience4j.bulkhead.max.thread.pool.size?tag=group:none", Map.class) - .get("availableTags"))).hasSize(1); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @RestController - protected static class Application { - - private static final Log LOG = LogFactory.getLog(Application.class); - - @GetMapping("/slow") - public String slow() throws InterruptedException { - Thread.sleep(3000); - return "slow"; - } - - @GetMapping("/normal") - public String normal() { - return "normal"; - } - - @GetMapping("/slowOnDemand") - public String slowOnDemand(@RequestHeader HttpHeaders headers) { - if (headers.containsKey("delayInMilliseconds")) { - String delayString = headers.getFirst("delayInMilliseconds"); - LOG.info("delay header: " + delayString); - if (delayString != null) { - try { - Thread.sleep(Integer.parseInt(delayString)); - } - catch (NumberFormatException | InterruptedException e) { - e.printStackTrace(); - } - } - } - else { - LOG.info("No delay header present"); - } - - return "normal"; - } - - @GetMapping("/slowBulkhead") - public String slowBulkhead() throws InterruptedException { - Thread.sleep(3000); - return "slowBulkhead"; - } - - @GetMapping("/slowThreadPoolBulkhead") - public String slowThreadPoolBulkhead() throws InterruptedException { - Thread.sleep(3000); - return "slowThreadPoolBulkhead"; - } - - @Bean - public Customizer slowCustomizer() { - doAnswer(invocation -> { - CircuitBreakerOnErrorEvent event = invocation.getArgument(0, CircuitBreakerOnErrorEvent.class); - LOG.info(event.getCircuitBreakerName() + " error: " + event.getEventType() + " duration: " - + event.getElapsedDuration().getSeconds()); - return null; - }).when(slowErrorConsumer).consumeEvent(any(CircuitBreakerOnErrorEvent.class)); - doAnswer(invocation -> { - CircuitBreakerOnSuccessEvent event = invocation.getArgument(0, CircuitBreakerOnSuccessEvent.class); - LOG.info(event.getCircuitBreakerName() + " success: " + event.getEventType() + " duration: " - + event.getElapsedDuration().getSeconds()); - return null; - }).when(slowSuccessConsumer).consumeEvent(any(CircuitBreakerOnSuccessEvent.class)); - doAnswer(invocation -> { - CircuitBreakerOnErrorEvent event = invocation.getArgument(0, CircuitBreakerOnErrorEvent.class); - LOG.info(event.getCircuitBreakerName() + " error: " + event.getEventType() + " duration: " - + event.getElapsedDuration().getSeconds()); - return null; - }).when(normalErrorConsumer).consumeEvent(any(CircuitBreakerOnErrorEvent.class)); - doAnswer(invocation -> { - CircuitBreakerOnSuccessEvent event = invocation.getArgument(0, CircuitBreakerOnSuccessEvent.class); - LOG.info(event.getCircuitBreakerName() + " success: " + event.getEventType() + " duration: " - + event.getElapsedDuration().getSeconds()); - return null; - }).when(normalSuccessConsumer).consumeEvent(any(CircuitBreakerOnSuccessEvent.class)); - return factory -> { - factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()), - "slow"); - factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); - }; - } - - static EventConsumer slowRejectedConsumer = Mockito.mock(EventConsumer.class); - static EventConsumer slowFinishedConsumer = Mockito.mock(EventConsumer.class); - - @Bean - public Customizer slowBulkheadProviderCustomizer() { - doAnswer(invocationOnMock -> { - BulkheadOnCallRejectedEvent event = invocationOnMock.getArgument(0, BulkheadOnCallRejectedEvent.class); - LOG.info(event.getBulkheadName() + " rejected: " + event.getEventType()); - return null; - }).when(slowRejectedConsumer).consumeEvent(any(BulkheadOnCallRejectedEvent.class)); - doAnswer(invocationOnMock -> { - BulkheadOnCallFinishedEvent event = invocationOnMock.getArgument(0, BulkheadOnCallFinishedEvent.class); - LOG.info(event.getBulkheadName() + " finished: " + event.getEventType()); - return null; - }).when(slowFinishedConsumer).consumeEvent(any(BulkheadOnCallFinishedEvent.class)); - return provider -> { - provider.configure( - builder -> builder.bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()), - "slowBulkhead"); - provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer).onCallFinished(slowFinishedConsumer), "slowBulkhead"); - }; - } - - static EventConsumer slowThreadPoolRejectedConsumer = Mockito - .mock(EventConsumer.class); - static EventConsumer slowThreadPoolFinishedConsumer = Mockito - .mock(EventConsumer.class); - - @Bean - Customizer slowBulkheadThreadPoolProviderCustomizer() { - return provider -> provider - .configure( - builder -> builder.threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom() - .coreThreadPoolSize(1).maxThreadPoolSize(1).queueCapacity(1).build()), - "slowThreadPoolBulkhead"); - } - - @Bean - public Customizer slowThreadPoolCustomizer() { - return factory -> factory.configure( - builder -> builder.timeLimiterConfig( - TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(8)).build()), - "slowThreadPoolBulkhead"); - } - - @Bean - public Customizer slowThreadPoolBulkheadCustomizer() { - doAnswer(invocationOnMock -> { - BulkheadOnCallRejectedEvent event = invocationOnMock.getArgument(0, BulkheadOnCallRejectedEvent.class); - LOG.info(event.getBulkheadName() + " threadpool rejected: " + event.getEventType()); - return null; - }).when(slowThreadPoolRejectedConsumer).consumeEvent(any(BulkheadOnCallRejectedEvent.class)); - doAnswer(invocationOnMock -> { - BulkheadOnCallFinishedEvent event = invocationOnMock.getArgument(0, BulkheadOnCallFinishedEvent.class); - LOG.info(event.getBulkheadName() + " threadpool finished: " + event.getEventType()); - return null; - }).when(slowThreadPoolFinishedConsumer).consumeEvent(any(BulkheadOnCallFinishedEvent.class)); - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead - .getEventPublisher().onCallRejected(slowThreadPoolRejectedConsumer) - .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); - } - - @Service - public static class DemoControllerService { - - private TestRestTemplate rest; - - private final CircuitBreakerFactory cbFactory; - - private final CircuitBreaker circuitBreakerSlow; - - DemoControllerService(TestRestTemplate rest, CircuitBreakerFactory cbFactory) { - this.rest = rest; - this.cbFactory = cbFactory; - this.circuitBreakerSlow = cbFactory.create("slow"); - } - - public String slow() { - return circuitBreakerSlow.run(() -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - - public String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); - } - - public String slowOnDemand(int delayInMilliseconds) { - LOG.info("delay: " + delayInMilliseconds); - return circuitBreakerSlow - .run(() -> rest - .exchange("/slowOnDemand", HttpMethod.GET, - createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) - .getBody(), t -> "fallback"); - } - - public String slowBulkhead() { - return cbFactory.create("slowBulkhead").run(() -> rest.getForObject("/slowBulkhead", String.class), - t -> "fallback"); - } - - public String slowThreadPoolBulkhead() { - return cbFactory.create("slowThreadPoolBulkhead") - .run(() -> rest.getForObject("/slowThreadPoolBulkhead", String.class), t -> "fallback"); - } - - private HttpEntity createEntityWithOptionalDelayHeader(int delayInMilliseconds) { - HttpHeaders headers = new HttpHeaders(); - if (delayInMilliseconds > 0) { - headers.set("delayInMilliseconds", Integer.toString(delayInMilliseconds)); - } - return new HttpEntity<>(null, headers); - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java deleted file mode 100644 index b1c9427c..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnErrorEvent; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnSuccessEvent; -import io.github.resilience4j.core.EventConsumer; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationHandler; -import io.micrometer.observation.ObservationRegistry; -import io.micrometer.observation.tck.ObservationContextAssert; -import org.assertj.core.api.BDDAssertions; -import org.junit.Test; -import org.junit.jupiter.api.BeforeEach; -import org.junit.runner.RunWith; -import org.mockito.Mock; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Ryan Baxter - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = Resilience4JCircuitBreakerIntegrationTest.Application.class, - properties = { "management.endpoints.web.exposure.include=*", - "spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled=false" }) -@DirtiesContext -public class Resilience4JCircuitBreakerIntegrationTest { - - @Mock - static EventConsumer slowErrorConsumer; - - @Mock - static EventConsumer slowSuccessConsumer; - - @Mock - static EventConsumer normalErrorConsumer; - - @Mock - static EventConsumer normalSuccessConsumer; - - @Autowired - Application.DemoControllerService service; - - @Autowired - Application.MyObservationHandler myObservationHandler; - - @Autowired - private TestRestTemplate rest; - - @BeforeEach - void setup() { - myObservationHandler.contexts.clear(); - } - - @Test - public void testSlow() { - assertThat(service.slow()).isEqualTo("fallback"); - verify(slowErrorConsumer, times(1)).consumeEvent(any()); - verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - } - - @Test - public void testNormal() { - assertThat(service.normal()).isEqualTo("normal"); - verify(normalErrorConsumer, times(0)).consumeEvent(any()); - verify(normalSuccessConsumer, times(1)).consumeEvent(any()); - } - - @Test - public void testSlowResponsesDontFailSubsequentGoodRequests() { - assertThat(service.slowOnDemand(5000)).isEqualTo("fallback"); - assertThat(service.slowOnDemand(0)).isEqualTo("normal"); - } - - @Test - public void testResilience4JMetricsAvailable() { - assertThat(service.normal()).isEqualTo("normal"); - assertThat(((List) rest.getForObject("/actuator/metrics", Map.class).get("names")) - .contains("resilience4j.circuitbreaker.calls")).isTrue(); - - // CircuitBreaker and TimeLimiter should have 3 metrics: name, kind, group - assertThat(((List) rest.getForObject("/actuator/metrics/resilience4j.circuitbreaker.calls", Map.class) - .get("availableTags"))).hasSize(3); - assertThat(((List) rest.getForObject("/actuator/metrics/resilience4j.timelimiter.calls", Map.class) - .get("availableTags"))).hasSize(3); - } - - @Test - public void testObservationRegistry() throws InterruptedException { - // :( some other test from this class is putting an additional context after some - // time - Thread.sleep(100); - myObservationHandler.contexts.clear(); - - assertThat(service.withObservationRegistry()).isEqualTo("fallback"); - - // CircuitBreaker should have 3 observations: my.observation, for supplier and for - // function - // TODO: Convert to usage of test registry assert with the next micrometer release - List contexts = myObservationHandler.contexts; - assertThat(contexts).hasSize(3); - assertThat(contexts.get(0)).satisfies(context -> ObservationContextAssert.then(context) - .hasNameEqualTo("spring.cloud.circuitbreaker").hasContextualNameEqualTo("circuit-breaker") - .hasLowCardinalityKeyValue("spring.cloud.circuitbreaker.type", "supplier")); - BDDAssertions.then(contexts.get(1)).satisfies(context -> ObservationContextAssert.then(context) - .hasNameEqualTo("spring.cloud.circuitbreaker").hasContextualNameEqualTo("circuit-breaker fallback") - .hasLowCardinalityKeyValue("spring.cloud.circuitbreaker.type", "function")); - BDDAssertions.then(contexts.get(2)) - .satisfies(context -> ObservationContextAssert.then(context).hasNameEqualTo("my.observation")); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - public String slow() throws InterruptedException { - Thread.sleep(3000); - return "slow"; - } - - @GetMapping("/exception") - public String exception() { - throw new IllegalStateException("BOOM!"); - } - - @GetMapping("/normal") - public String normal() { - return "normal"; - } - - @GetMapping("/slowOnDemand") - public String slowOnDemand(@RequestHeader HttpHeaders headers) { - if (headers.containsKey("delayInMilliseconds")) { - String delayString = headers.getFirst("delayInMilliseconds"); - if (delayString != null) { - try { - Thread.sleep(Integer.parseInt(delayString)); - } - catch (NumberFormatException | InterruptedException e) { - e.printStackTrace(); - } - } - } - - return "normal"; - } - - @Bean - public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), - "slow"); - factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); - }; - } - - @Component - public static class MyObservationHandler implements ObservationHandler { - - List contexts = new ArrayList<>(); - - @Override - public void onStop(Observation.Context context) { - this.contexts.add(context); - } - - @Override - public boolean supportsContext(Observation.Context context) { - return true; - } - - } - - @Service - public static class DemoControllerService { - - private TestRestTemplate rest; - - private final CircuitBreakerFactory cbFactory; - - private final CircuitBreaker circuitBreakerSlow; - - private final ObservationRegistry observationRegistry; - - DemoControllerService(TestRestTemplate rest, CircuitBreakerFactory cbFactory, - ObservationRegistry observationRegistry) { - this.rest = rest; - this.cbFactory = cbFactory; - this.circuitBreakerSlow = cbFactory.create("slow"); - this.observationRegistry = observationRegistry; - } - - public String slow() { - return circuitBreakerSlow.run(() -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - - public String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); - } - - public String withObservationRegistry() { - return Observation.createNotStarted("my.observation", observationRegistry) - .observe(() -> cbFactory.create("exception").run( - () -> new RestTemplate().getForObject("/exception", String.class), t -> "fallback")); - } - - public String slowOnDemand(int delayInMilliseconds) { - return circuitBreakerSlow - .run(() -> rest - .exchange("/slowOnDemand", HttpMethod.GET, - createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) - .getBody(), t -> "fallback"); - } - - private HttpEntity createEntityWithOptionalDelayHeader(int delayInMilliseconds) { - HttpHeaders headers = new HttpHeaders(); - if (delayInMilliseconds > 0) { - headers.set("delayInMilliseconds", Integer.toString(delayInMilliseconds)); - } - return new HttpEntity<>(null, headers); - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java deleted file mode 100644 index a8e57541..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import io.github.resilience4j.bulkhead.BulkheadRegistry; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.timelimiter.TimeLimiterRegistry; -import org.junit.Before; -import org.junit.Test; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Ryan Baxter - * @author Andrii Bohutskyi - */ -public class Resilience4JCircuitBreakerTest { - - Resilience4JConfigurationProperties properties = null; - - @Before - public void before() { - properties = new Resilience4JConfigurationProperties(); - } - - @Test - public void run() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - } - - @Test - public void runWithOutProperties() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null).create("foo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - } - - @Test - public void runWithGroupName() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null).create("foo", "groupFoo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - - } - - @Test - public void runWithoutThreadPool() { - properties.setDisableThreadPool(true); - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo", "groupFoo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - - } - - @Test - public void runWithFallback() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo"); - assertThat((String) cb.run(() -> { - throw new RuntimeException("boom"); - }, t -> "fallback")).isEqualTo("fallback"); - } - - @Test - public void runWithFallbackAndGroupName() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo", "groupFoo"); - assertThat((String) cb.run(() -> { - throw new RuntimeException("boom"); - }, t -> "fallback")).isEqualTo("fallback"); - } - - @Test - public void runWithBulkheadProvider() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), - new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), - new Resilience4JConfigurationProperties()), - properties).create("foo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - } - - @Test - public void runWithBulkheadProviderAndGroupName() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), - new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), - new Resilience4JConfigurationProperties()), - properties).create("foo", "groupFoo"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - } - - @Test - public void runWithFallbackBulkheadProvider() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), - new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), - new Resilience4JConfigurationProperties()), - properties).create("foo"); - assertThat((String) cb.run(() -> { - throw new RuntimeException("boom"); - }, t -> "fallback")).isEqualTo("fallback"); - } - - @Test - public void runWithFallbackBulkheadProviderAndGroupName() { - CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), - new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), - new Resilience4JConfigurationProperties()), - properties).create("foo", "groupFoo"); - assertThat((String) cb.run(() -> { - throw new RuntimeException("boom"); - }, t -> "fallback")).isEqualTo("fallback"); - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java deleted file mode 100644 index 100512f1..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.resilience4j; - -import java.time.Duration; -import java.util.Map; - -import io.github.resilience4j.bulkhead.BulkheadConfig; -import io.github.resilience4j.bulkhead.BulkheadRegistry; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadConfig; -import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnErrorEvent; -import io.github.resilience4j.circuitbreaker.event.CircuitBreakerOnSuccessEvent; -import io.github.resilience4j.core.EventConsumer; -import io.github.resilience4j.timelimiter.TimeLimiterConfig; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Robert McNees - */ -@SpringBootTest(webEnvironment = RANDOM_PORT, - classes = Resilience4JDefaultSemaphoreBulkheadIntegrationTest.Application.class, - properties = { "management.endpoints.web.exposure.include=*", - "spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead=true" }) -@DirtiesContext -public class Resilience4JDefaultSemaphoreBulkheadIntegrationTest { - - @Mock - static EventConsumer slowErrorConsumer; - - @Mock - static EventConsumer slowSuccessConsumer; - - @Autowired - Resilience4JDefaultSemaphoreBulkheadIntegrationTest.Application.DemoControllerService service; - - @Autowired - Resilience4JConfigurationProperties configurationProperties; - - @Autowired - private TestRestTemplate rest; - - @SpyBean - private ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry; - - @SpyBean - private BulkheadRegistry bulkheadRegistry; - - @Test - public void testSlowUsesSemaphoreBulkheadDefault() { - - assertThat(service.slow()).isEqualTo("fallback"); - verify(slowErrorConsumer, times(1)).consumeEvent(any()); - verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - - verify(this.threadPoolBulkheadRegistry, times(0)).bulkhead(any(String.class), - any(ThreadPoolBulkheadConfig.class), any(Map.class)); - - verify(this.bulkheadRegistry, times(1)).bulkhead(any(String.class), any(BulkheadConfig.class), any(Map.class)); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - public String slow() throws InterruptedException { - Thread.sleep(3000); - return "slow"; - } - - @Bean - public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), - "slow"); - factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); - }; - } - - @Service - public static class DemoControllerService { - - private final CircuitBreakerFactory cbFactory; - - private final CircuitBreaker circuitBreakerSlow; - - private final TestRestTemplate rest; - - DemoControllerService(TestRestTemplate rest, CircuitBreakerFactory cbFactory) { - this.rest = rest; - this.cbFactory = cbFactory; - this.circuitBreakerSlow = cbFactory.create("slow"); - } - - public String slow() { - return circuitBreakerSlow.run(() -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/resources/application-test-properties.properties b/spring-cloud-circuitbreaker-resilience4j/src/test/resources/application-test-properties.properties deleted file mode 100644 index 865304cc..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/resources/application-test-properties.properties +++ /dev/null @@ -1,14 +0,0 @@ -resilience4j.circuitbreaker.configs.default.minimumNumberOfCalls=20 -resilience4j.timelimiter.configs.default.timeout-duration=150ms -resilience4j.thread-pool-bulkhead.configs.default.max-thread-pool-size=50 - -resilience4j.circuitbreaker.configs.test_group.minimumNumberOfCalls=30 -resilience4j.circuitbreaker.configs.test_id.minimumNumberOfCalls=10 -resilience4j.timelimiter.configs.test_group.timeout-duration=500ms -resilience4j.timelimiter.instances.test_group_instance.timeout-duration=600ms - -resilience4j.circuitbreaker.instances.test_circuit.minimumNumberOfCalls=5 -resilience4j.timelimiter.instances.test_circuit.timeout-duration=18s - -resilience4j.thread-pool-bulkhead.instances.test_circuit.max-thread-pool-size=100 -resilience4j.bulkhead.instances.test_circuit.max-concurrent-calls=50 diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/spring-cloud-circuitbreaker-resilience4j/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index ca6ee9ce..00000000 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline \ No newline at end of file diff --git a/spring-cloud-circuitbreaker-spring-retry/pom.xml b/spring-cloud-circuitbreaker-spring-retry/pom.xml deleted file mode 100644 index fcedeee1..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - spring-cloud-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - - spring-cloud-circuitbreaker-spring-retry - - - - org.springframework.cloud - spring-cloud-commons - - - org.springframework.boot - spring-boot-starter - - - org.springframework.retry - spring-retry - - - org.springframework.boot - spring-boot-starter-web - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfiguration.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfiguration.java deleted file mode 100644 index 2d1bf05c..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.util.List; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.lang.Nullable; -import org.springframework.retry.support.RetryTemplate; - -/** - * @author Ryan Baxter - * @author Eric Bussieres - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(RetryTemplate.class) -public class SpringRetryAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(CircuitBreakerFactory.class) - public CircuitBreakerFactory springRetryCircuitBreakerFactory( - @Nullable List> customizers) { - - SpringRetryCircuitBreakerFactory factory = new SpringRetryCircuitBreakerFactory(); - if (customizers != null) { - customizers.forEach(customizer -> customizer.customize(factory)); - } - return factory; - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreaker.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreaker.java deleted file mode 100644 index a696fac3..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreaker.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.util.function.Function; -import java.util.function.Supplier; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.retry.support.DefaultRetryState; -import org.springframework.retry.support.RetryTemplate; - -/** - * @author Ryan Baxter - */ -public class SpringRetryCircuitBreaker implements CircuitBreaker { - - private final String id; - - private final SpringRetryConfig config; - - private final Customizer retryTemplateCustomizer; - - private final RetryTemplate retryTemplate; - - public SpringRetryCircuitBreaker(String id, SpringRetryConfig config, - Customizer retryTemplateCustomizer) { - this.id = id; - this.config = config; - this.retryTemplateCustomizer = retryTemplateCustomizer; - this.retryTemplate = new RetryTemplate(); - } - - @Override - public T run(Supplier toRun, Function fallback) { - - retryTemplate.setBackOffPolicy(config.getBackOffPolicy()); - retryTemplate.setRetryPolicy(config.getRetryPolicy()); - - if (retryTemplateCustomizer != null) { - retryTemplateCustomizer.customize(retryTemplate); - } - - return retryTemplate.execute(context -> toRun.get(), context -> fallback.apply(context.getLastThrowable()), - new DefaultRetryState(id, config.isForceRefreshState(), config.getStateClassifier())); - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerFactory.java deleted file mode 100644 index ee839dfb..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.retry.support.RetryTemplate; -import org.springframework.util.Assert; - -/** - * @author Ryan Baxter - */ -public class SpringRetryCircuitBreakerFactory - extends CircuitBreakerFactory { - - private Function defaultConfig = id -> new SpringRetryConfigBuilder(id).build(); - - private final Map> retryTemplateCustomizers = new HashMap<>(); - - @Override - protected SpringRetryConfigBuilder configBuilder(String id) { - return new SpringRetryConfigBuilder(id); - } - - @Override - public void configureDefault(Function defaultConfiguration) { - this.defaultConfig = defaultConfiguration; - } - - @Override - public CircuitBreaker create(String id) { - Assert.hasText(id, "A circuit breaker must have an id"); - SpringRetryConfig config = getConfigurations().computeIfAbsent(id, defaultConfig); - return new SpringRetryCircuitBreaker(id, config, retryTemplateCustomizers.get(id)); - } - - public void addRetryTemplateCustomizers(Customizer customizer, String... ids) { - for (String id : ids) { - this.retryTemplateCustomizers.put(id, customizer); - } - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfig.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfig.java deleted file mode 100644 index 0b4fc778..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfig.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import org.springframework.classify.Classifier; -import org.springframework.retry.RetryPolicy; -import org.springframework.retry.backoff.BackOffPolicy; - -/** - * @author Ryan Baxter - */ -public class SpringRetryConfig { - - private String id; - - private BackOffPolicy backOffPolicy; - - private RetryPolicy retryPolicy; - - private boolean forceRefreshState; - - private Classifier stateClassifier; - - boolean isForceRefreshState() { - return forceRefreshState; - } - - SpringRetryConfig setForceRefreshState(boolean forceRefreshState) { - this.forceRefreshState = forceRefreshState; - return this; - } - - Classifier getStateClassifier() { - return stateClassifier; - } - - SpringRetryConfig setStateClassifier(Classifier stateClassifier) { - this.stateClassifier = stateClassifier; - return this; - } - - RetryPolicy getRetryPolicy() { - return retryPolicy; - } - - SpringRetryConfig setRetryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - return this; - } - - String getId() { - return id; - } - - SpringRetryConfig setId(String id) { - this.id = id; - return this; - } - - BackOffPolicy getBackOffPolicy() { - return backOffPolicy; - } - - SpringRetryConfig setBackOffPolicy(BackOffPolicy backOffPolicy) { - this.backOffPolicy = backOffPolicy; - return this; - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java deleted file mode 100644 index 2babf8ba..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import org.springframework.classify.Classifier; -import org.springframework.cloud.client.circuitbreaker.ConfigBuilder; -import org.springframework.retry.RetryPolicy; -import org.springframework.retry.backoff.BackOffPolicy; -import org.springframework.retry.backoff.NoBackOffPolicy; -import org.springframework.retry.policy.CircuitBreakerRetryPolicy; -import org.springframework.retry.support.DefaultRetryState; - -/** - * Allows consumers to easily construct a {@link SpringRetryConfig} object. - * - * @author Ryan Baxter - */ -public class SpringRetryConfigBuilder implements ConfigBuilder { - - private final String id; - - private BackOffPolicy backOffPolicy = new NoBackOffPolicy(); - - private RetryPolicy retryPolicy = new CircuitBreakerRetryPolicy(); - - private boolean forceRefreshState = false; - - private Classifier stateClassifier = classifiable -> false; - - /** - * Constructor. - * @param id The id of the circuit breaker. - */ - public SpringRetryConfigBuilder(String id) { - this.id = id; - } - - /** - * Sets the backoff policy when retrying a failed request. - * @param backOffPolicy The {@link BackOffPolicy} to use. - * @return The builder. - */ - public SpringRetryConfigBuilder backOffPolicy(BackOffPolicy backOffPolicy) { - this.backOffPolicy = backOffPolicy; - return this; - } - - /** - * Sets the {@link RetryPolicy} to use. The {@code RetryPolicy} set here will be - * wrapped in a {@link CircuitBreakerRetryPolicy}. - * @param retryPolicy The {@code RetryPolicy} to use. - * @return The builder. - */ - public SpringRetryConfigBuilder retryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = new CircuitBreakerRetryPolicy(retryPolicy); - return this; - } - - /** - * Forces a refresh on the {@link DefaultRetryState} object. - * @param refresh true to refresh, false otherwise. - * @return The builder. - */ - public SpringRetryConfigBuilder forceRefreshState(boolean refresh) { - this.forceRefreshState = refresh; - return this; - } - - /** - * The {@link Classifier} used by the {@link DefaultRetryState} object. - * @param classifier The {@code Classifier} to set. - * @return The builder. - */ - public SpringRetryConfigBuilder stateClassifier(Classifier classifier) { - this.stateClassifier = classifier; - return this; - } - - @Override - public SpringRetryConfig build() { - return new SpringRetryConfig().setBackOffPolicy(backOffPolicy).setId(id).setRetryPolicy(retryPolicy) - .setForceRefreshState(forceRefreshState).setStateClassifier(stateClassifier); - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-circuitbreaker-spring-retry/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 77608364..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -org.springframework.cloud.circuitbreaker.springretry.SpringRetryAutoConfiguration diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java deleted file mode 100644 index bf62cfb7..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.ResolvableType; - -/** - * @author wind57 - */ -class SpringRetryAutoConfigurationTests { - - @Nested - class NoCustomizers { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)); - - @Test - void testNoCustomizers() { - - contextRunner.run(context -> { - String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); - Assertions.assertEquals(0, arr.length, "Default auto-configuration must not have any customizers"); - - @SuppressWarnings("rawtypes") - Map map = context.getBeansOfType(CircuitBreakerFactory.class); - Assertions.assertEquals(1, map.size(), "Spring Retry Circuit Breaker must be present"); - }); - - } - - } - - @Nested - class WithEmptyCustomizers { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) - .withConfiguration(AutoConfigurations.of(ListWithEmptyCustomizers.class)); - - @Test - void testWithCustomizers() { - - contextRunner.run(context -> { - String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); - Assertions.assertEquals(1, arr.length); - Assertions.assertArrayEquals(arr, new String[] { "customizers" }); - - @SuppressWarnings("rawtypes") - Map map = context.getBeansOfType(CircuitBreakerFactory.class); - Assertions.assertEquals(1, map.size()); - }); - - } - - @Configuration - static class ListWithEmptyCustomizers { - - @Bean - List> customizers() { - return Collections.emptyList(); - } - - } - - } - - @Nested - @ExtendWith(OutputCaptureExtension.class) - class WithCustomizers { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) - .withConfiguration(AutoConfigurations.of(WithCustomizers.MyConfig.class)); - - @Test - void testCustomizer(CapturedOutput output) { - - contextRunner.run(context -> { - String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); - Assertions.assertEquals(1, arr.length); - Assertions.assertArrayEquals(arr, new String[] { "customizers" }); - - @SuppressWarnings("rawtypes") - Map map = context.getBeansOfType(CircuitBreakerFactory.class); - Assertions.assertEquals(1, map.size()); - }); - Assertions.assertTrue(output.getOut().contains("trying to customize")); - - } - - @Configuration - static class MyConfig { - - @Bean - List> customizers() { - return Collections.singletonList(factory -> { - System.out.println("trying to customize"); - }); - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java deleted file mode 100644 index baf8e081..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.time.Duration; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.retry.RetryCallback; -import org.springframework.retry.RetryContext; -import org.springframework.retry.RetryListener; -import org.springframework.retry.policy.SimpleRetryPolicy; -import org.springframework.retry.policy.TimeoutRetryPolicy; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Ryan Baxter - */ -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringRetryCircuitBreakerIntegrationTest.Application.class) -class SpringRetryCircuitBreakerIntegrationTest { - - @Autowired - private Application.DemoControllerService service; - - @Test - void testSlow() { - assertThat(service.slow()).isEqualTo("fallback"); - service.verifyTimesSlowInvoked(); - } - - @Test - void testNormal() { - assertThat(service.normal()).isEqualTo("normal"); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - String slow() throws InterruptedException { - Thread.sleep(3000); - return "slow"; - } - - @GetMapping("/normal") - String normal() { - return "normal"; - } - - @Bean - RestTemplateBuilder restTemplateBuilder() { - return new RestTemplateBuilder().setReadTimeout(Duration.ofSeconds(1)); - } - - @Bean - Customizer factoryCustomizer() { - return factory -> { - factory.configureDefault( - id -> new SpringRetryConfigBuilder(id).retryPolicy(new TimeoutRetryPolicy()).build()); - factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); - factory.addRetryTemplateCustomizers( - retryTemplate -> retryTemplate.registerListener(new RetryListener() { - - @Override - public boolean open(RetryContext context, - RetryCallback callback) { - return false; - } - - @Override - public void close(RetryContext context, - RetryCallback callback, Throwable throwable) { - - } - - @Override - public void onError(RetryContext context, - RetryCallback callback, Throwable throwable) { - - } - })); - }; - } - - @Service - private static class DemoControllerService { - - private final TestRestTemplate rest; - - private final CircuitBreakerFactory cbFactory; - - private final CircuitBreaker circuitBreakerSlow; - - DemoControllerService(TestRestTemplate rest, CircuitBreakerFactory cbFactory) { - this.rest = spy(rest); - this.cbFactory = cbFactory; - this.circuitBreakerSlow = cbFactory.create("slow"); - } - - String slow() { - for (int i = 0; i < 10; i++) { - circuitBreakerSlow.run(() -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - return circuitBreakerSlow.run(() -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - - String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); - } - - void verifyTimesSlowInvoked() { - verify(rest, times(1)).getForObject(eq("/slow"), eq(String.class)); - } - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerTest.java b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerTest.java deleted file mode 100644 index d15549de..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed 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 - * - * https://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. - */ - -package org.springframework.cloud.circuitbreaker.springretry; - -import java.util.function.Supplier; - -import org.junit.jupiter.api.Test; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.retry.RetryCallback; -import org.springframework.retry.RetryContext; -import org.springframework.retry.RetryListener; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author Ryan Baxter - */ -class SpringRetryCircuitBreakerTest { - - @Test - void testCreate() { - CircuitBreaker cb = new SpringRetryCircuitBreakerFactory().create("foo"); - assertThat(cb.run(() -> "foo")).isEqualTo("foo"); - } - - @Test - void testFallback() { - SpringRetryCircuitBreakerFactory factory = new SpringRetryCircuitBreakerFactory(); - Supplier spyedSup = spy(new Supplier() { - @Override - public String get() { - throw new RuntimeException("boom"); - } - }); - CircuitBreaker cb = factory.create("foo"); - for (int i = 0; i < 10; i++) { - cb.run(spyedSup, t -> "fallback"); - } - assertThat(cb.run(spyedSup, t -> "fallback")).isEqualTo("fallback"); - // This will only be called 3 times because the SimpleRetryPolicy will trip the - // circuit after the 3rd attempt. - verify(spyedSup, times(3)).get(); - } - - @Test - public void testRetryCustomizer() { - SpringRetryCircuitBreakerFactory factory = new SpringRetryCircuitBreakerFactory(); - CustomListener listener = new CustomListener(); - factory.addRetryTemplateCustomizers(rt -> rt.setListeners(new RetryListener[] { listener }), "with-customizer"); - - String result = factory.create("with-customizer").run(() -> "foo"); - assertThat(result).isEqualTo("foo"); - assertThat(listener.toCheck[0]).isEqualTo("check-me-please"); - } - - private static class CustomListener implements RetryListener { - - private final String[] toCheck = new String[1]; - - @Override - public boolean open(RetryContext context, RetryCallback callback) { - return true; - } - - @Override - public void close(RetryContext context, RetryCallback callback, - Throwable throwable) { - toCheck[0] = "check-me-please"; - } - - @Override - public void onError(RetryContext context, RetryCallback callback, - Throwable throwable) { - - } - - } - -} diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/resources/logback-test.xml b/spring-cloud-circuitbreaker-spring-retry/src/test/resources/logback-test.xml deleted file mode 100644 index f3fa67ba..00000000 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/resources/logback-test.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/spring-cloud-starter-circuitbreaker/pom.xml b/spring-cloud-starter-circuitbreaker/pom.xml deleted file mode 100644 index 08a497ad..00000000 --- a/spring-cloud-starter-circuitbreaker/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - spring-cloud-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - - spring-cloud-starter-circuitbreaker - - spring-cloud-starter-circuitbreaker-resilience4j - spring-cloud-starter-circuitbreaker-spring-retry - spring-cloud-starter-circuitbreaker-reactor-resilience4j - - pom - - - diff --git a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/pom.xml b/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/pom.xml deleted file mode 100644 index 2f98c7fa..00000000 --- a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - spring-cloud-starter-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - - spring-cloud-starter-circuitbreaker-reactor-resilience4j - - - - org.springframework.cloud - spring-cloud-starter - - - org.springframework.cloud - spring-cloud-circuitbreaker-resilience4j - - - io.github.resilience4j - resilience4j-circuitbreaker - - - io.github.resilience4j - resilience4j-timelimiter - - - io.github.resilience4j - resilience4j-reactor - - - - - diff --git a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/src/main/resources/META-INF/spring.provides b/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/src/main/resources/META-INF/spring.provides deleted file mode 100644 index 92b84ece..00000000 --- a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-reactor-resilience4j/src/main/resources/META-INF/spring.provides +++ /dev/null @@ -1 +0,0 @@ -provides: spring-cloud-circuitbreaker-reactor-resilience4j diff --git a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/pom.xml b/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/pom.xml deleted file mode 100644 index 3d4dcc72..00000000 --- a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - spring-cloud-starter-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - spring-cloud-starter-circuitbreaker-resilience4j - - - - org.springframework.cloud - spring-cloud-starter - - - org.springframework.cloud - spring-cloud-circuitbreaker-resilience4j - - - io.github.resilience4j - resilience4j-circuitbreaker - - - io.github.resilience4j - resilience4j-timelimiter - - - diff --git a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/src/main/resources/META-INF/spring.provides b/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/src/main/resources/META-INF/spring.provides deleted file mode 100644 index d68b6ca6..00000000 --- a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-resilience4j/src/main/resources/META-INF/spring.provides +++ /dev/null @@ -1 +0,0 @@ -provides: spring-cloud-circuitbreaker-resilience4j \ No newline at end of file diff --git a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-spring-retry/pom.xml b/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-spring-retry/pom.xml deleted file mode 100644 index c12148ca..00000000 --- a/spring-cloud-starter-circuitbreaker/spring-cloud-starter-circuitbreaker-spring-retry/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - spring-cloud-starter-circuitbreaker - org.springframework.cloud - 3.1.0-SNAPSHOT - - 4.0.0 - - spring-cloud-starter-circuitbreaker-spring-retry - - - - org.springframework.cloud - spring-cloud-starter - - - org.springframework.cloud - spring-cloud-circuitbreaker-spring-retry - - - org.springframework.retry - spring-retry - - - - - diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml deleted file mode 100644 index 462303e4..00000000 --- a/src/checkstyle/checkstyle-suppressions.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/supplemental-ui/partials/nav-search.hbs b/supplemental-ui/partials/nav-search.hbs new file mode 100644 index 00000000..5e379552 --- /dev/null +++ b/supplemental-ui/partials/nav-search.hbs @@ -0,0 +1,11 @@ +{{#if env.ALGOLIA_API_KEY}} +

+{{/if}} diff --git a/supplemental-ui/partials/search.hbs b/supplemental-ui/partials/search.hbs new file mode 100644 index 00000000..384e505f --- /dev/null +++ b/supplemental-ui/partials/search.hbs @@ -0,0 +1,27 @@ + +{{#if env.ALGOLIA_API_KEY}} + + + + + + + + +{{/if}}