- 
                Notifications
    You must be signed in to change notification settings 
- Fork 96
Add Spring Boot integration. #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      8634184
              
                Add Spring Boot integration.
              
              
                bsideup dace989
              
                fix the agent dependency
              
              
                bsideup 7cf13e6
              
                Add the docs
              
              
                bsideup c712448
              
                Fix the order
              
              
                bsideup 2caafaa
              
                Merge branch 'master' into spring_integration
              
              
                bsideup 7999799
              
                https all the things!
              
              
                bsideup 11ec189
              
                Merge branch 'master' into spring_integration
              
              
                bsideup File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Spring support | ||
|  | ||
| BlockHound Spring module will automatically install the agent at a very early stage of Spring Boot application's startup. | ||
|  | ||
| ## Getting it | ||
| Download it from repo.spring.io or Maven Central repositories (stable releases only): | ||
|  | ||
| ```groovy | ||
| repositories { | ||
| maven { url 'https://repo.spring.io/milestone' } | ||
| // maven { url 'https://repo.spring.io/snapshot' } | ||
| } | ||
|  | ||
| dependencies { | ||
| testCompile 'io.projectreactor.tools:blockhound-spring:$LATEST_RELEASE' | ||
| // testCompile 'io.projectreactor.tools:blockhound-spring:$LATEST_SNAPSHOT' | ||
| } | ||
| ``` | ||
| Where: | ||
| `$LATEST_RELEASE` is:  | ||
| `$LATEST_SNAPSHOT` is:  | ||
|  | ||
| ## Custom config | ||
| The listener will call `install()` without the arguments (see [customization](./customization.md) for details). | ||
|  | ||
| If you want to apply your custom integration, register it as any other integration as documented [here](./custom_integrations.md). | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| plugins { | ||
| id "java" | ||
| id "maven-publish" | ||
| } | ||
|  | ||
| sourceCompatibility = targetCompatibility = 8 | ||
|  | ||
| repositories { | ||
| jcenter() | ||
| } | ||
|  | ||
| dependencies { | ||
| compile project(path: ":agent", configuration: 'shadow') | ||
|  | ||
| compileOnly 'org.springframework.boot:spring-boot:2.1.3.RELEASE' | ||
|  | ||
| testCompile 'junit:junit:4.12' | ||
| testCompile 'org.assertj:assertj-core:3.11.1' | ||
| testCompile 'org.springframework.boot:spring-boot:2.1.3.RELEASE' | ||
| testCompile 'io.projectreactor:reactor-core:3.2.2.RELEASE' | ||
| } | ||
|  | ||
| test { | ||
| forkEvery = 1 | ||
| maxParallelForks = 1 | ||
| } | ||
|  | ||
| task sourcesJar(type: Jar) { | ||
| classifier 'sources' | ||
| from sourceSets.main.allJava | ||
| } | ||
|  | ||
| publishing { | ||
| publications { | ||
| mavenJava(MavenPublication) { publication -> | ||
| from components.java | ||
| artifact sourcesJar | ||
|  | ||
| artifactId 'blockhound-spring' | ||
| } | ||
| } | ||
| } | 
        
          
          
            75 changes: 75 additions & 0 deletions
          
          75 
        
  spring/src/main/java/reactor/blockhound/spring/BlockHoundRunListener.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (c) 2019-Present Pivotal Software Inc, All Rights Reserved. | ||
| * | ||
| * 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 reactor.blockhound.spring; | ||
|  | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.SpringApplicationRunListener; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
| import org.springframework.core.Ordered; | ||
| import org.springframework.core.env.ConfigurableEnvironment; | ||
| import reactor.BlockHound; | ||
| import reactor.blockhound.integration.BlockHoundIntegration; | ||
|  | ||
| /** | ||
| * This {@link SpringApplicationRunListener} installs the agent when an app is starting | ||
| * by calling {@link BlockHound#install(BlockHoundIntegration...)}. | ||
| */ | ||
| public class BlockHoundRunListener implements SpringApplicationRunListener, Ordered { | ||
|  | ||
| public BlockHoundRunListener(SpringApplication application, String[] args) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public int getOrder() { | ||
| return Ordered.HIGHEST_PRECEDENCE; | ||
| } | ||
|  | ||
| @Override | ||
| public void starting() { | ||
| BlockHound.install(); | ||
| } | ||
|  | ||
| @Override | ||
| public void environmentPrepared(ConfigurableEnvironment environment) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public void contextPrepared(ConfigurableApplicationContext context) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public void contextLoaded(ConfigurableApplicationContext context) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public void started(ConfigurableApplicationContext context) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public void running(ConfigurableApplicationContext context) { | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
| public void failed(ConfigurableApplicationContext context, Throwable exception) { | ||
|  | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Run Listeners | ||
| org.springframework.boot.SpringApplicationRunListener=\ | ||
| reactor.blockhound.spring.BlockHoundRunListener | 
        
          
          
            55 changes: 55 additions & 0 deletions
          
          55 
        
  spring/src/test/java/reactor/blockhound/spring/BlockHoundRunListenerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (c) 2019-Present Pivotal Software Inc, All Rights Reserved. | ||
| * | ||
| * 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 reactor.blockhound.spring; | ||
|  | ||
| import org.assertj.core.api.AbstractThrowableAssert; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.Test; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import reactor.core.publisher.Mono; | ||
| import reactor.core.scheduler.Schedulers; | ||
|  | ||
| import java.io.Closeable; | ||
|  | ||
| public class BlockHoundRunListenerTest { | ||
|  | ||
| @Test | ||
| public void shouldInstallOnRun() throws Exception { | ||
| assertThatBlockingCall().doesNotThrowAnyException(); | ||
|  | ||
| try (Closeable __ = new SpringApplication(DummyAppConfiguration.class).run()) { | ||
| assertThatBlockingCall().hasMessageContaining("Blocking call!"); | ||
| } | ||
| } | ||
|  | ||
| private AbstractThrowableAssert<?, ? extends Throwable> assertThatBlockingCall() { | ||
| return Assertions.assertThatCode(() -> { | ||
| Mono | ||
| .fromCallable(() -> { | ||
| Thread.sleep(1); | ||
| return ""; | ||
| }) | ||
| .subscribeOn(Schedulers.parallel()) | ||
| .block(); | ||
| }); | ||
| } | ||
|  | ||
| @Configuration | ||
| static class DummyAppConfiguration { | ||
| } | ||
|  | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philwebb does it have to be public, or I can make it internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philwebb, has the Boot team considered making the methods in
SpringApplicationRunListenerinterfacedefaultmethods now that Java 8 is the baseline?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will add an issue. That API is somewhat unusual as it mainly exists to break a package tangle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philwebb anything to say about the visibility of this class? 😊