gpt4 book ai didi

java - TestContainers、Couchbase 和 Spring Boot - ScheduledFutureTask 被 ScheduledThreadPoolExecutor 拒绝

转载 作者:行者123 更新时间:2023-11-30 10:00:21 27 4
gpt4 key购买 nike

我们正在为我们的 Spring Boot 2.1.7.RELEASECouchbase 数据库创建集成测试。

我们正在使用 testcontainers当测试运行完成时我们得到这个错误:

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@da0432 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@238be2[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]


在我们的 pom 中:

    <dependency>
<groupId>org.testcontainers</groupId>
<artifactId>couchbase</artifactId>
<version>1.12.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.12.1</version>
<scope>test</scope>
</dependency>

在我们的“集成测试配置”类中:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MyApplication.class, IntegrationTestConfig.CouchbaseTestConfig.class},
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public abstract class IntegrationTestConfig{

@ClassRule
public static CouchbaseContainer couchbaseContainer = new CouchbaseContainer()
.withIndex(true)
.withQuery(true)
.withClusterAdmin("clusterUser", "clusterPassword")
.withNewBucket(DefaultBucketSettings.builder()
.enableFlush(true)
.name("bucketName")
.password("bucketPassword")
.quota(100)
.replicas(0)
.type(BucketType.COUCHBASE)
.build());

@BeforeClass
public static void beforeClass() throws IOException{
log.debug("Starting containers...");
couchbaseContainer.start();
}

@AfterClass
public static void afterClass(){
log.debug("Stopping containers...");
couchbaseContainer.stop();
}

在我们的 IntegrationTest 类中:

public class MyIntegrationTest extends IntegrationTestConfig{

@LocalServerPort
private int port;

@Test
public void testSomething(){
....
}

当尝试运行集成测试时,我们在控制台中看到:

    ℹ︎ Checking the system...
✔ Docker version should be at least 1.6.0
✔ Docker environment should have more than 2GB free disk space

然后我们在控制台中得到这个一两秒钟:

DEBUG [IntegrationTestConfig] - Starting containers... 
DEBUG [IntegrationTestConfig] - Stopping containers...

然后我们得到这个错误:

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@d87cbb rejected from java.util.concurrent.ScheduledThreadPoolExecutor@1486dd9[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533)
at java.util.concurrent.ScheduledThreadPoolExecutor.submit(ScheduledThreadPoolExecutor.java:632)
at rx.internal.schedulers.NewThreadWorker.scheduleActual(NewThreadWorker.java:277)
at com.couchbase.client.core.env.CoreScheduler$EventLoopWorker.schedule(CoreScheduler.java:174)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.schedule(OperatorObserveOn.java:188)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$1.request(OperatorObserveOn.java:145)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.init(OperatorObserveOn.java:139)
at rx.internal.operators.OperatorObserveOn.call(OperatorObserveOn.java:75)
at rx.internal.operators.OperatorObserveOn.call(OperatorObserveOn.java:40)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:44)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.subscribe(Observable.java:10423)
at rx.Observable.subscribe(Observable.java:10390)
at com.couchbase.client.core.utils.Blocking.blockForSingle(Blocking.java:70)
at com.couchbase.client.java.CouchbaseCluster.disconnect(CouchbaseCluster.java:417)
at com.couchbase.client.java.CouchbaseCluster.disconnect(CouchbaseCluster.java:412)
at org.testcontainers.couchbase.CouchbaseContainer.stopCluster(CouchbaseContainer.java:198)
at org.testcontainers.couchbase.CouchbaseContainer.stop(CouchbaseContainer.java:193)
at org.testcontainers.containers.GenericContainer.finished(GenericContainer.java:829)
at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:36)
at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:30)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

最佳答案

您可能需要以守护进程模式运行您的数据库,这样它就不会自动停止:https://www.testcontainers.org/modules/databases/#running-container-in-daemon-mode

关于java - TestContainers、Couchbase 和 Spring Boot - ScheduledFutureTask 被 ScheduledThreadPoolExecutor 拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58049666/

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