gpt4 book ai didi

spring-boot - gradle-如何在integarion测试之前启动spring boot服务器-使用Maven如此简单

转载 作者:行者123 更新时间:2023-12-03 05:25:24 24 4
gpt4 key购买 nike

我们正在从Maven切换到Gradle。在maven中,我们将通过使用spring-boot-mvane-plugin来启动处于“集成前测试”阶段的Spring Boot服务器,如https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html所述。

   <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>run e2e tests</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run verify</arguments>
</configuration>
</execution>
</executions>
</plugin>

我没有找到在gradle中派生流程的方法。 gradle Spring Boot插件也无济于事。

我怎样才能做到这一点?

最佳答案

我可以通过gradle-spawn-plugin使用它,但是对我来说看起来很复杂

后端/build.gradle

plugins {
id "com.wiredforcode.spawn" version "0.8.2"
}
task startServer(type: SpawnProcessTask, dependsOn: 'bootJar') {
command "java -jar ${projectDir}/build/libs/project-${version}.jar --spring.profiles.active=integration"
ready 'Started'
}
task stopServer(type: KillProcessTask)

前端/build.gradle
task verify(dependsOn: ':backend:startServer', type: NpmTask) {
// Copy from 'dist'
inputs.files(fileTree('tests/e2e'))
dependsOn 'npmBuild'
args = ['run', 'verify']
}
check.dependsOn verify
verify.finalizedBy ':backend:stopServer'

但是请注意一些怪癖:如果您登录到控制台,则会遇到一些问题。首先,一切看起来都很好。但是经过几分钟的测试后,日志记录不再起作用。

许多线程被这样阻塞:
"http-nio-127.0.0.1-8082-exec-2" #27 daemon prio=5 os_prio=0 cpu=462,00ms elapsed=531,88s tid=0x00007f1442a32000 nid=0x76d5 waiting on condition  [0x00007f136f021000]
java.lang.Thread.State: WAITING (parking)
at jdk.internal.misc.Unsafe.park(java.base@11.0.7/Native Method)
- parking to wait for <0x0000000454d81218> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(java.base@11.0.7/LockSupport.java:194)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(java.base@11.0.7/AbstractQueuedSynchronizer.java:885)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(java.base@11.0.7/AbstractQueuedSynchronizer.java:917)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(java.base@11.0.7/AbstractQueuedSynchronizer.java:1240)
at java.util.concurrent.locks.ReentrantLock.lock(java.base@11.0.7/ReentrantLock.java:267)
at ch.qos.logback.core.OutputStreamAppender.writeBytes(OutputStreamAppender.java:197)
at ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:231)
at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:102)
at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:579)

我不知道为什么,但是在我看来gradle-spawn-plugin是STDOUT所做的事情。可能是因为搜索“就绪”字符串。并且由于我们不在生产环境中登录控制台,因此最好在集成测试时不要这样做。因此,我禁用了登录控制台的功能,一切正常。

关于spring-boot - gradle-如何在integarion测试之前启动spring boot服务器-使用Maven如此简单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61454341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com