Spring message appears several times during the test run - spring-boot

I am currently using spring-boot with the org.testcontainers library to pass test in docker . But I noticed that the following message appears several times :
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.20.RELEASE)
It appears up to 4 times , 2 of them with the following message :
11:33:23.733 [main] INFO org.springframework.web.context.support.GenericWebApplicationContext - Refreshing org.springframework.web.context.support.GenericWebApplicationContext#13ffeba4: startup date [Wed Jun 16 11:33:23 CEST 2021]; root of context hierarchy
Some messages that have caught my attention, first time that appears (the only one I think necessary)
11:31:48.515 [main] INFO org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 0 (http)
11:31:49.019 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 5416 ms
2 : It does not appear Why?
3:
11:35:06.738 [main] INFO org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 0 (http)
11:35:06.764 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1569 ms
4:
11:36:19.343 [main] INFO org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 0 (http)
11:36:19.362 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 454 ms
The message always pops up after a specific test, for example the third time during this test.
#Category(OneTest.class)
public class PasswordEncryptionTest
{
#Test
public void passwordEncryptionTest()
{
PasswordEncryption passwordEncryption = new PasswordEncryption();
try
{
String password = "passwordExample";
String encrypted = passwordEncryption.encryptPassword(password.toCharArray());
String decrypted = passwordEncryption.decryptPassword(encrypted.toCharArray());
assertEquals(password, decrypted);
}
catch (PasswordDecryptionException e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
}
Is this normal ? Because it is the message that appears when you start the application and that it appears 4 times, that is what I noticed.
Can it be affecting the performance of the tests?
Pd: They are messages, after passing the tests many times, in different environments, they are not the result of chance. I have seen no relationship in the times between the different appearances. (It does not follow a time pattern)
spring-boot 1.5.20
junit47
org.testcontainers 1.13.0
Docker windows 2.2.0.3

Related

How to Suspend/Delay java unit tests

Is there a way to suspend java ( springboot ) unit tests execution when running mvn test and resume them later ?
So I have this test class :
#SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
class JavaAppApplicationTests {
#Test
void contextLoads() {}
#Test
#RepeatedTest(10)
public void testApplication() {
JavaAppApplication javaApp = new JavaAppApplication();
String result = javaApp.sanitize();
assertEquals(result, "{\"key1\":\"value1\",\"type\":\"Booking\",\"sid\":\"A435211\",\"region\":\"ASIA\",\"fetchFromFile\":\"false\",\"service\":\"true\",\"isEom\":\"true\"}");
}
}
And when I run mvn test, I see in the console logs the following :
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.6)
2022-05-17 11:00:29.481 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : Starting JavaAppApplicationTests using Java 17-internal on neo-VirtualBox with PID 58143 (started by neo in /home/neo/Desktop/spring-vulnerable-app)
2022-05-17 11:00:29.483 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : No active profile set, falling back to 1 default profile: "default"
2022-05-17 11:00:30.542 INFO 58143 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-17 11:00:30.561 INFO 58143 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-17 11:00:30.561 INFO 58143 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-05-17 11:00:30.749 INFO 58143 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-05-17 11:00:30.749 INFO 58143 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1230 ms
2022-05-17 11:00:31.497 INFO 58143 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-17 11:00:31.507 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : Started JavaAppApplicationTests in 2.452 seconds (JVM running for 3.887)
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4 s - in com.elastisys.javaapp.JavaAppApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
The JavaApplicationTests is started with a specific PID and a defined port and then tests are executed.
What I am looking for is a way to start the application and wait for a specific period before executing all the tests ( like it's suspended )
Thanks in advance

Deploying gradle spring boot app profile don't work in heroku

The application stands up on the default profile, but should be on herok. What's wrong with my setup?
Procfile:
web: java -Dspring.profiles.active=heroku -jar build/libs/todo-api-all.jar
aplication-heroku.properties:
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
# App Properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://localhost:5432/test
spring.datasource.username=xxxx
spring.datasource.password=xxxx
logs:
2022-03-17T22:16:37.062638+00:00 heroku[web.1]: Starting process with command `java -Dspring.profiles.active=heroku -jar build/libs/todo-api-all.jar`
2022-03-17T22:16:37.769060+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2022-03-17T22:16:37.772288+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UT
F-8
2022-03-17T22:16:38.078366+00:00 app[web.1]:
2022-03-17T22:16:38.078397+00:00 app[web.1]: . ____ _ __ _ _
2022-03-17T22:16:38.078410+00:00 app[web.1]: /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
2022-03-17T22:16:38.078428+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2022-03-17T22:16:38.078446+00:00 app[web.1]: \\/ ___)| |_)| | | | | || (_| | ) ) ) )
2022-03-17T22:16:38.078463+00:00 app[web.1]: ' |____| .__|_| |_|_| |_\__, | / / / /
2022-03-17T22:16:38.078481+00:00 app[web.1]: =========|_|==============|___/=/_/_/_/
2022-03-17T22:16:38.080265+00:00 app[web.1]: :: Spring Boot ::
2022-03-17T22:16:38.080285+00:00 app[web.1]:
2022-03-17T22:16:38.151045+00:00 app[web.1]: 22:16:38.149 [main] INFO be.ordina.jworks.todoapi.TodoApplication - Starting TodoApplication using Java 17.0.2 o
n b96d702f-a867-4f6c-a1e7-a1c9c48b6f27 with PID 4 (/app/build/libs/todo-api-all.jar started by u47513 in /app)
2022-03-17T22:16:38.151382+00:00 app[web.1]: 22:16:38.151 [main] DEBUG be.ordina.jworks.todoapi.TodoApplication - Running with Spring Boot, Spring
2022-03-17T22:16:38.152810+00:00 app[web.1]: 22:16:38.152 [main] INFO be.ordina.jworks.todoapi.TodoApplication - No active profile set, falling back to 1 def
ault profile: "default"
2022-03-17T22:16:38.153431+00:00 app[web.1]: 22:16:38.153 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class be.ordina.jworks.tod
oapi.TodoApplication

Native Spring function bundled as a docker image not working on AWS lambda

I'm trying to run an AWS Lambda using Docker image build by paketobuildpacks/builder using spring-native + spring-cloud-function-aws, but it's not handling incoming values, justs starts and returns an error, did I missed something?
Log output:
START RequestId: f7a451f1-f43b-4ba0-be3d-58526bfa0d10 Version: $LATEST
2021-06-30 00:20:58.229 INFO 8 --- [ main] o.s.nativex.NativeListener : This application is bootstrapped with code generated with Spring AOT
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.1)
2021-06-30 00:20:58.251 INFO 8 --- [ main] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on 169.254.41.117 with PID 8 (started by sbx_user1051 in /workspace)
2021-06-30 00:20:58.251 INFO 8 --- [ main] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2021-06-30 00:20:58.551 INFO 8 --- [ main] o.s.boot.SpringApplication : Started application in 0.42 seconds (JVM running for 0.421)
END RequestId: f7a451f1-f43b-4ba0-be3d-58526bfa0d10
REPORT RequestId: f7a451f1-f43b-4ba0-be3d-58526bfa0d10 Duration: 840.41 ms Billed Duration: 841 ms Memory Size: 128 MB Max Memory Used: 29 MB
RequestId: f7a451f1-f43b-4ba0-be3d-58526bfa0d10 Error: Runtime exited without providing a reason
Runtime.ExitError
Find my configs below:
Gradle Plugins:
kotlin("jvm")
kotlin("plugin.spring")
id("io.spring.dependency-management")
id("org.springframework.boot")
id("org.springframework.experimental.aot")
id("org.graalvm.buildtools.native")
Dependencies:
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springframework.cloud:spring-cloud-function-adapter-aws")
implementation("com.amazonaws:aws-lambda-java-events:2.0.2")
implementation("com.amazonaws:aws-lambda-java-core:1.1.0")
GraalVM plugin config:
tasks.withType<BootBuildImage> {
builder = "paketobuildpacks/builder:tiny"
environment = mapOf("BP_NATIVE_IMAGE" to "true")
}
App sources:
#SpringBootApplication
class LinkGeneratorApplication: ApplicationContextInitializer<GenericApplicationContext> {
override fun initialize(applicationContext: GenericApplicationContext) {
applicationContext.registerBean(
"function",
FunctionRegistration::class.java,
{
FunctionRegistration(Function<Input, Result> { Result("Here") })
.type(
FunctionType
.from(Input::class.java)
.to(Result::class.java)
.type
)
}
)
}
}
data class Input(val sellerId: String, val ownerId: String, val market: String)
data class Result(val message: String)
fun main(args: Array<String>) {
runApplication<LinkGeneratorApplication>(*args)
}

Docker Compose with Two Spring Boot Application get "message": "I/O error on GET request for \"http://127.0.0.1:8010/....: Connection refused"

I have two small Spring Boot applications that exposes a rest API:
app-one
Get Request
- http://localhost:8010/api/stock/AAPL
Response:
{
"name": "AAPL",
"value": 219.9
}
app-two
Get Request
- http://localhost:8080/api/trade/APPL/buy/10
Response
{
"id": 1,
"stock": {
"name": "APPL",
"value": 219.9
},
"quantity": 10,
"total": 2199.0
}
When I run this two apps on my localhost without Docker I get the correct response from both APIs.
When I run the apps using the Docker Compose, the first API app-one responds OK, but the app-two returns an error:
"message": "I/O error on GET request for \"http://127.0.0.1:8010/api/stock/APPL\": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)",
"path": "/api/trade/APPL/buy/10"
This is my docker-compose.yml configuration file:
version: "3.7"
services:
app-one:
image: ibercode/app-one
ports:
- "8010:8010"
expose:
- "8010"
app-two:
build: .
ports:
- "8080:8080"
depends_on:
- app-one
environment:
- APP_ONE_URI=http://127.0.0.1:8010/api/stock/
And this is the output after I run the command docker-compose up
$ docker-compose up
Starting app-two_app-one_1 ... done
Starting app-two_app-two_1 ... done
Attaching to app-two_app-one_1, app-two_app-two_1
app-one_1 |
app-one_1 | . ____ _ __ _ _
app-one_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-one_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-one_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-one_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-one_1 | =========|_|==============|___/=/_/_/_/
app-one_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-one_1 |
app-one_1 | 2019-09-18 08:28:07.287 INFO 1 --- [ main] com.ibercode.AppOneApplication : Starting AppOneApplication vlatest on a090eb18a661 with PID 1 (/app.jar started by root in /)
app-one_1 | 2019-09-18 08:28:07.291 INFO 1 --- [ main] com.ibercode.AppOneApplication : No active profile set, falling back to default profiles: default
app-two_1 |
app-two_1 | . ____ _ __ _ _
app-two_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-two_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-two_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-two_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-two_1 | =========|_|==============|___/=/_/_/_/
app-two_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-two_1 |
app-two_1 | 2019-09-18 08:28:08.308 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Starting AppTwoApplication vlatest on 973897f9ea8d with PID 1 (/app.jar started by root in /)
app-two_1 | 2019-09-18 08:28:08.325 INFO 1 --- [ main] com.ibercode.AppTwoApplication : No active profile set, falling back to default profiles: default
app-one_1 | 2019-09-18 08:28:10.448 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)
app-one_1 | 2019-09-18 08:28:10.536 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-one_1 | 2019-09-18 08:28:10.537 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:10.731 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-one_1 | 2019-09-18 08:28:10.744 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3313 ms
app-one_1 | 2019-09-18 08:28:11.283 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:11.488 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:11.701 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''
app-one_1 | 2019-09-18 08:28:11.705 INFO 1 --- [ main] com.ibercode.AppOneApplication : Started AppOneApplication in 5.488 seconds (JVM running for 6.129)
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3281 ms
app-two_1 | 2019-09-18 08:28:12.077 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:12.249 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
app-two_1 | 2019-09-18 08:28:12.251 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Started AppTwoApplication in 5.016 seconds (JVM running for 5.955)
Any idea or suggestions?
Thanks
It seem you are trying to access app-1 from app-2 with the URL http://127.0.0.1:8010/api/stock/APPL. However you can't access the other container under 127.0.0.1 from another container.
You can access another service in the compose file by service name. That means, you need to configure your app-2 application to look for the host app-one, i.e. APP_ONE_URI=http://app-one/api/stock/.
You can read more about Compose networking here https://docs.docker.com/compose/networking/.

'Run as Spring Boot App' on STS but "webpage is not available" in the browser [duplicate]

This question already has answers here:
Why does my Spring Boot App always shutdown immediately after starting?
(23 answers)
Closed 7 years ago.
Like the title said, I right click on the spring boot project and Run as Spring Boot App. This is what I saw in the Console window of STS:
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.2.RELEASE)
2016-01-30 21:06:29.124 INFO 6584 --- [ main] l.IssueManagerApplication : Starting IssueManagerApplication on LVN with PID 6584 (E:\_WORKSPACE\SPRING_BOOT\issue-manager\target\classes started by Le in E:\_WORKSPACE\SPRING_BOOT\issue-manager)
2016-01-30 21:06:29.130 INFO 6584 --- [ main] l.IssueManagerApplication : No active profile set, falling back to default profiles: default
2016-01-30 21:06:29.249 INFO 6584 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#12d575ec: startup date [Sat Jan 30 21:06:29 EET 2016]; root of context hierarchy
2016-01-30 21:06:31.208 INFO 6584 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-01-30 21:06:32.032 INFO 6584 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-30 21:06:32.077 INFO 6584 --- [ main] l.IssueManagerApplication : Started IssueManagerApplication in 4.163 seconds (JVM running for 6.548)
2016-01-30 21:06:32.078 INFO 6584 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#12d575ec: startup date [Sat Jan 30 21:06:29 EET 2016]; root of context hierarchy
2016-01-30 21:06:32.084 INFO 6584 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
And when I open localhost:8080, it just displayed a grey page saying "This webpage is not available". Apparently the server does not start at all or it started but then stopped right after that.
I already tried run mvn spring-boot:run, it also log out information as above plus BUILD SUCCESS and stops even without me Ctrl + C. So I dont know how to run my "hello world" spring-boot application.
I resolved the issue by adding this in my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Thanks to this post:
Why my Spring Boot App always shutdown

Resources