-
Notifications
You must be signed in to change notification settings - Fork 5
Defer tomcat startup #32
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
Open
apnicjim
wants to merge
10
commits into
APNIC-net:develop
Choose a base branch
from
apnicjim:defer_tomcat_startup
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
894c325
Refactor default properties into property file
apnicjim bc92168
Refactor RipeDbLoader to bean
apnicjim ad685a6
Test data is loaded before service is started
apnicjim 4e4e7a3
Load data before starting service
apnicjim 31acb64
Removed unused import
apnicjim a5210d0
Allow time to start test container before marking unhealthy
apnicjim fb9d8d4
Revert "Allow time to start test container before marking unhealthy"
apnicjim 1ac9e92
Fix the initial data load from hanging
apnicjim 96312ae
Fix scheduled refresh of data
apnicjim 03970bf
Merge branch 'develop' into defer_tomcat_startup
apnicjim 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,11 @@ | ||
| package net.apnic.whowas; | ||
|
|
||
| import java.util.Properties; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class App { | ||
|
|
||
| public static void main(String[] args) | ||
| { | ||
| SpringApplication app = new SpringApplication(App.class); | ||
| Properties defaultProps = new Properties(); | ||
|
|
||
| defaultProps.setProperty( | ||
| "spring.mvc.throw-exception-if-no-handler-found", "true"); | ||
| defaultProps.setProperty("spring.resources.add-mappings", "false"); | ||
| defaultProps.setProperty("spring.mvc.favicon.enabled", "false"); | ||
| defaultProps.setProperty("management.add-application-context-header", "false"); | ||
| app.setDefaultProperties(defaultProps); | ||
| app.run(args); | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(App.class, args); | ||
| } | ||
| } |
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
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,58 @@ | ||
| package net.apnic.whowas; | ||
|
|
||
| import net.apnic.whowas.loaders.RipeDbLoader; | ||
| import org.junit.Test; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; | ||
| import org.springframework.context.ApplicationListener; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
|
||
| import static org.hamcrest.core.Is.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| public class InitialisationTest { | ||
|
|
||
| @Test | ||
| public void initialDataIsLoadedBeforeServletIsStarted() { | ||
| ConcurrentLinkedQueue<String> events = new ConcurrentLinkedQueue<>(); | ||
|
|
||
| System.setProperty("server.port", "0"); | ||
| System.setProperty("management.port", "-1"); | ||
|
|
||
| SpringApplication springApplication = new SpringApplication(App.class); | ||
| springApplication.addInitializers(configurableApplicationContext -> | ||
| configurableApplicationContext.addBeanFactoryPostProcessor(beanFactory -> | ||
| beanFactory.registerResolvableDependency( | ||
| RipeDbLoader.class, new RipeDbLoader(new JdbcTemplate()) { | ||
| @Override | ||
| public void loadWith(RevisionConsumer consumer) { | ||
| sleep(1000); | ||
| events.add("Data loaded"); | ||
| } | ||
| } | ||
| ) | ||
| ) | ||
| ); | ||
| springApplication.addListeners( | ||
| (ApplicationListener<EmbeddedServletContainerInitializedEvent>) applicationEvent -> | ||
| events.add("Servlet container started") | ||
| ); | ||
|
|
||
| try(ConfigurableApplicationContext context = springApplication.run()) { | ||
| assertThat("Data was loaded before tomcat was initialised", | ||
| new ArrayList<>(events).get(0), is("Data loaded")); | ||
| } | ||
| } | ||
|
|
||
| private static void sleep(int millis) { | ||
| try { | ||
| Thread.sleep(millis); | ||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |
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.
Note that spring says @transactional should not be relied upon in @PostConstruct as the proxy may not be fully initialised.
https://docs.spring.io/spring/docs/5.0.3.BUILD-SNAPSHOT/spring-framework-reference/data-access.html#transaction-declarative-annotations