Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8ed0b1a2
Commit
8ed0b1a2
authored
Dec 20, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-19417
parents
8b4c6c2c
3cadde09
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
18 deletions
+49
-18
TomcatServletWebServerFactoryTests.java
...b/embedded/tomcat/TomcatServletWebServerFactoryTests.java
+1
-1
AbstractReactiveWebServerFactoryTests.java
...eactive/server/AbstractReactiveWebServerFactoryTests.java
+23
-5
AbstractServletWebServerFactoryTests.java
.../servlet/server/AbstractServletWebServerFactoryTests.java
+25
-12
No files found.
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java
View file @
8ed0b1a2
...
@@ -328,7 +328,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
...
@@ -328,7 +328,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
}
}
@Test
@Test
void
startupFailureDoesNotResultInUnstoppedThreadsBeingReported
(
CapturedOutput
output
)
throws
IO
Exception
{
void
startupFailureDoesNotResultInUnstoppedThreadsBeingReported
(
CapturedOutput
output
)
throws
Exception
{
super
.
portClashOfPrimaryConnectorResultsInPortInUseException
();
super
.
portClashOfPrimaryConnectorResultsInPortInUseException
();
assertThat
(
output
).
doesNotContain
(
"appears to have started a thread named [main]"
);
assertThat
(
output
).
doesNotContain
(
"appears to have started a thread named [main]"
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java
View file @
8ed0b1a2
...
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
...
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
import
java.security.KeyStore
;
import
java.security.KeyStore
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.concurrent.Callable
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLException
;
import
javax.net.ssl.SSLException
;
...
@@ -87,12 +88,15 @@ public abstract class AbstractReactiveWebServerFactoryTests {
...
@@ -87,12 +88,15 @@ public abstract class AbstractReactiveWebServerFactoryTests {
protected
abstract
AbstractReactiveWebServerFactory
getFactory
();
protected
abstract
AbstractReactiveWebServerFactory
getFactory
();
@Test
@Test
void
specificPort
()
{
void
specificPort
()
throws
Exception
{
AbstractReactiveWebServerFactory
factory
=
getFactory
();
AbstractReactiveWebServerFactory
factory
=
getFactory
();
int
specificPort
=
SocketUtils
.
findAvailableTcpPort
(
41000
);
int
specificPort
=
doWithRetry
(()
->
{
factory
.
setPort
(
specificPort
);
int
port
=
SocketUtils
.
findAvailableTcpPort
(
41000
);
this
.
webServer
=
factory
.
getWebServer
(
new
EchoHandler
());
factory
.
setPort
(
port
);
this
.
webServer
.
start
();
this
.
webServer
=
factory
.
getWebServer
(
new
EchoHandler
());
this
.
webServer
.
start
();
return
port
;
});
Mono
<
String
>
result
=
getWebClient
().
build
().
post
().
uri
(
"/test"
).
contentType
(
MediaType
.
TEXT_PLAIN
)
Mono
<
String
>
result
=
getWebClient
().
build
().
post
().
uri
(
"/test"
).
contentType
(
MediaType
.
TEXT_PLAIN
)
.
body
(
BodyInserters
.
fromValue
(
"Hello World"
)).
exchange
()
.
body
(
BodyInserters
.
fromValue
(
"Hello World"
)).
exchange
()
.
flatMap
((
response
)
->
response
.
bodyToMono
(
String
.
class
));
.
flatMap
((
response
)
->
response
.
bodyToMono
(
String
.
class
));
...
@@ -108,6 +112,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
...
@@ -108,6 +112,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
@Test
@Test
void
basicSslFromFileSystem
()
{
void
basicSslFromFileSystem
()
{
testBasicSslWithKeyStore
(
"src/test/resources/test.jks"
,
"password"
);
testBasicSslWithKeyStore
(
"src/test/resources/test.jks"
,
"password"
);
}
}
protected
final
void
testBasicSslWithKeyStore
(
String
keyStore
,
String
keyPassword
)
{
protected
final
void
testBasicSslWithKeyStore
(
String
keyStore
,
String
keyPassword
)
{
...
@@ -329,6 +334,19 @@ public abstract class AbstractReactiveWebServerFactoryTests {
...
@@ -329,6 +334,19 @@ public abstract class AbstractReactiveWebServerFactoryTests {
assertThat
(
body
).
isEqualTo
(
"https"
);
assertThat
(
body
).
isEqualTo
(
"https"
);
}
}
private
<
T
>
T
doWithRetry
(
Callable
<
T
>
action
)
throws
Exception
{
Exception
lastFailure
=
null
;
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
return
action
.
call
();
}
catch
(
Exception
ex
)
{
lastFailure
=
ex
;
}
}
throw
new
IllegalStateException
(
"Action was not successful in 10 attempts"
,
lastFailure
);
}
protected
static
class
EchoHandler
implements
HttpHandler
{
protected
static
class
EchoHandler
implements
HttpHandler
{
public
EchoHandler
()
{
public
EchoHandler
()
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java
View file @
8ed0b1a2
...
@@ -44,6 +44,7 @@ import java.util.EnumSet;
...
@@ -44,6 +44,7 @@ import java.util.EnumSet;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.zip.GZIPInputStream
;
import
java.util.zip.GZIPInputStream
;
...
@@ -246,10 +247,13 @@ public abstract class AbstractServletWebServerFactoryTests {
...
@@ -246,10 +247,13 @@ public abstract class AbstractServletWebServerFactoryTests {
@Test
@Test
void
specificPort
()
throws
Exception
{
void
specificPort
()
throws
Exception
{
AbstractServletWebServerFactory
factory
=
getFactory
();
AbstractServletWebServerFactory
factory
=
getFactory
();
int
specificPort
=
SocketUtils
.
findAvailableTcpPort
(
41000
);
int
specificPort
=
doWithRetry
(()
->
{
factory
.
setPort
(
specificPort
);
int
port
=
SocketUtils
.
findAvailableTcpPort
(
41000
);
this
.
webServer
=
factory
.
getWebServer
(
exampleServletRegistration
());
factory
.
setPort
(
port
);
this
.
webServer
.
start
();
this
.
webServer
=
factory
.
getWebServer
(
exampleServletRegistration
());
this
.
webServer
.
start
();
return
port
;
});
assertThat
(
getResponse
(
"http://localhost:"
+
specificPort
+
"/hello"
)).
isEqualTo
(
"Hello World"
);
assertThat
(
getResponse
(
"http://localhost:"
+
specificPort
+
"/hello"
)).
isEqualTo
(
"Hello World"
);
assertThat
(
this
.
webServer
.
getPort
()).
isEqualTo
(
specificPort
);
assertThat
(
this
.
webServer
.
getPort
()).
isEqualTo
(
specificPort
);
}
}
...
@@ -823,7 +827,7 @@ public abstract class AbstractServletWebServerFactoryTests {
...
@@ -823,7 +827,7 @@ public abstract class AbstractServletWebServerFactoryTests {
}
}
@Test
@Test
protected
void
portClashOfPrimaryConnectorResultsInPortInUseException
()
throws
IO
Exception
{
protected
void
portClashOfPrimaryConnectorResultsInPortInUseException
()
throws
Exception
{
doWithBlockedPort
((
port
)
->
{
doWithBlockedPort
((
port
)
->
{
assertThatExceptionOfType
(
RuntimeException
.
class
).
isThrownBy
(()
->
{
assertThatExceptionOfType
(
RuntimeException
.
class
).
isThrownBy
(()
->
{
AbstractServletWebServerFactory
factory
=
getFactory
();
AbstractServletWebServerFactory
factory
=
getFactory
();
...
@@ -835,7 +839,7 @@ public abstract class AbstractServletWebServerFactoryTests {
...
@@ -835,7 +839,7 @@ public abstract class AbstractServletWebServerFactoryTests {
}
}
@Test
@Test
void
portClashOfSecondaryConnectorResultsInPortInUseException
()
throws
IO
Exception
{
void
portClashOfSecondaryConnectorResultsInPortInUseException
()
throws
Exception
{
doWithBlockedPort
((
port
)
->
{
doWithBlockedPort
((
port
)
->
{
assertThatExceptionOfType
(
RuntimeException
.
class
).
isThrownBy
(()
->
{
assertThatExceptionOfType
(
RuntimeException
.
class
).
isThrownBy
(()
->
{
AbstractServletWebServerFactory
factory
=
getFactory
();
AbstractServletWebServerFactory
factory
=
getFactory
();
...
@@ -1131,19 +1135,28 @@ public abstract class AbstractServletWebServerFactoryTests {
...
@@ -1131,19 +1135,28 @@ public abstract class AbstractServletWebServerFactoryTests {
return
bean
;
return
bean
;
}
}
protected
final
void
doWithBlockedPort
(
BlockedPortAction
action
)
throws
IOException
{
private
<
T
>
T
doWithRetry
(
Callable
<
T
>
action
)
throws
Exception
{
int
port
=
SocketUtils
.
findAvailableTcpPort
(
40000
);
Exception
lastFailure
=
null
;
ServerSocket
serverSocket
=
new
ServerSocket
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
try
{
serverSocket
.
bind
(
new
InetSocketAddress
(
port
));
return
action
.
call
();
break
;
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
lastFailure
=
ex
;
}
}
}
}
throw
new
IllegalStateException
(
"Action was not successful in 10 attempts"
,
lastFailure
);
}
protected
final
void
doWithBlockedPort
(
BlockedPortAction
action
)
throws
Exception
{
ServerSocket
serverSocket
=
new
ServerSocket
();
int
blockedPort
=
doWithRetry
(()
->
{
int
port
=
SocketUtils
.
findAvailableTcpPort
(
40000
);
serverSocket
.
bind
(
new
InetSocketAddress
(
port
));
return
port
;
});
try
{
try
{
action
.
run
(
p
ort
);
action
.
run
(
blockedP
ort
);
}
}
finally
{
finally
{
serverSocket
.
close
();
serverSocket
.
close
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment