gpt4 book ai didi

java - 如何避免 JUnit App Engine LocalSearchService 中的 LockObtainFailedException?

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:19 25 4
gpt4 key购买 nike

我正在使用 App Engine 标准环境,我的服务使用 Search API .

所以基本上在我的服务中我会做类似的事情:

IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
index.putAsync(document);

但是当我运行 JUnit 测试时,我经常遇到以下异常:

Apr 17, 2018 11:25:33 AM com.google.appengine.api.search.dev.LocalSearchService indexDocumentForApp SEVERE: Unable to access index com.google.appengine.repackaged.org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/Users/freddyboucher/Private/Programming/LearnKeeper/learnkeeper-server/WEB-INF/appengine-generated/indexes/dGVzdA/Qk9PS1M..P/write.lock at com.google.appengine.repackaged.org.apache.lucene.store.Lock.obtain(Lock.java:85) at com.google.appengine.repackaged.org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1562) at com.google.appengine.repackaged.org.apache.lucene.index.IndexWriter.(IndexWriter.java:1090) at com.google.appengine.api.search.dev.LocalSearchService.getIndexWriter(LocalSearchService.java:800) at com.google.appengine.api.search.dev.LocalSearchService.indexDocumentForApp(LocalSearchService.java:290) at com.google.appengine.api.search.dev.LocalSearchService.indexDocument(LocalSearchService.java:268) 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 com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.invokeApiMethodJava(ApiProxyLocalImpl.java:657) at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:612) at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:569) at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:541) at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:533) at java.security.AccessController.doPrivileged(Native Method) at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:530) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

最佳答案

它没有在任何地方记录,只是添加:

LocalSearchServiceTestConfig.getLocalSearchService().stop()

在我的@After方法中解决了这个问题。

我还发现添加有用:

FileUtils.deleteDirectory(new File("WEB-INF"));

所以最终的解决方案是:

  @After
public void tearDown() throws Exception {
LocalSearchServiceTestConfig.getLocalSearchService().stop();
FileUtils.deleteDirectory(new File("WEB-INF"));
...
}

关于java - 如何避免 JUnit App Engine LocalSearchService 中的 LockObtainFailedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49877094/

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