Skip to content

Instantly share code, notes, and snippets.

@lucapiccinelli
Created May 27, 2020 06:09
Show Gist options
  • Save lucapiccinelli/d7ef5b01a9fec83ff88852c65dcf7229 to your computer and use it in GitHub Desktop.
Save lucapiccinelli/d7ef5b01a9fec83ff88852c65dcf7229 to your computer and use it in GitHub Desktop.
@Test
fun `GIVEN springboot in certain state WHEN a restart happens THEN it should preserve the state`(){
val restTemplate = TestRestTemplate()
var webserverPort = Random.nextInt(10000, 10100)
val appContext = SpringApplication.run(MainApplication::class.java, "--server.port=$webserverPort")
restTemplate.getForObject<String>("http://localhost:$webserverPort/hello") shouldBe "Ok 0"
appContext.registerShutdownHook()
webserverPort = Random.nextInt(10000, 10100)
val newContext = SpringApplication.run(MainApplication::class.java, "--server.port=$webserverPort")
restTemplate.getForObject<String>("http://localhost:$webserverPort/hello") shouldBe "Ok 1"
newContext.registerShutdownHook()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment