5

当我从 Gradle 任务运行集成测试时,它们失败了。

org.springframework.data.solr.UncategorizedSolrException: **SolrCore 'collection1' is not available due to init failure: Error opening new searcher; nested exception is org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Error opening new searcher**
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:122)
at org.springframework.data.solr.core.SolrTemplate.saveDocuments(SolrTemplate.java:206)
at org.springframework.data.solr.core.SolrTemplate.saveDocuments(SolrTemplate.java:201)

org.apache.lucene.store.LockObtainFailedException:锁获取超时:NativeFSLock@/opt/solr/example/solr/collection1/data/index/write.lock

当我直接在 Intellij 中运行集成测试时,测试运行成功。这是我对嵌入式服务器的 bean 定义。我添加了destroyMethod,它没有效果。

 @Bean(destroyMethod = "shutdown")
public SolrServer solrServer(org.apache.commons.configuration.Configuration configuration)  {

    EmbeddedSolrServerFactory factory;
    try {
        factory = new EmbeddedSolrServerFactory(configuration.getString("solr.home"));
    } catch (ParserConfigurationException | IOException | SAXException e) {
        String errorMsg = "Encountered an exception while initializing the SolrServer bean.";
        log.error(errorMsg, e);
        throw new OrdersClientRuntimeException(errorMsg, e);
    }
    return factory.getSolrServer();
}

这是日志。一切似乎都在正确关闭。

2014-09-02 17:32:15.757 thread="Thread-6" level="DEBUG" logger="o.s.b.f.s.DisposableBeanAdapter" - **Invoking destroy method 'shutdown' on bean with name 'solrServer'**
2014-09-02 17:32:15.759 thread="Thread-8" level="DEBUG" logger="o.s.b.f.s.DefaultListableBeanFactory" - Retrieved dependent beans for bean 'solrDocumentRepository': [net.nike.orders.client.search.repository.DocumentRepositorySpec]
2014-09-02 17:32:15.759 thread="Thread-6" level="INFO " logger="org.apache.solr.core.CoreContainer" - **Shutting down CoreContainer instance=179265569**
2014-09-02 17:32:15.760 thread="Thread-8" level="DEBUG" logger="o.s.b.f.s.DisposableBeanAdapter" - **Invoking destroy method 'shutdown' on bean with name 'solrServer'**
2014-09-02 17:32:15.760 thread="Thread-8" level="INFO " logger="org.apache.solr.core.CoreContainer" - **Shutting down CoreContainer instance=1604485329**
2014-09-02 17:32:15.762 thread="Thread-6" level="INFO " logger="org.apache.solr.core.SolrCore" - [collection1]  **CLOSING SolrCore** org.apache.solr.core.SolrCore@28da98e2
2014-09-02 17:32:15.769 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - **Connection manager is shutting down**
2014-09-02 17:32:15.769 thread="Thread-6" level="INFO " logger="**org.apache.solr.update.UpdateHandler" - closing** DirectUpdateHandler2{commits=23,autocommit maxTime=15000ms,autocommits=0,soft autocommits=2,optimizes=0,rollbacks=0,expungeDeletes=0,docsPending=0,adds=0,deletesById=0,deletesByQuery=0,errors=0,cumulative_adds=33,cumulative_deletesById=32,cumulative_deletesByQuery=0,cumulative_errors=0,transaction_logs_total_size=5302,transaction_logs_total_number=10}
2014-09-02 17:32:15.771 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager shut down
2014-09-02 17:32:15.773 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager is shutting down
2014-09-02 17:32:15.774 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager shut down

这是我的环境信息:

  • Linux 薄荷 17
  • 索尔 4.9.0
  • Solr 测试框架 4.9.0
  • 甲骨文Java 1.7
  • Spring Data Solr 1.2.2.RELEASE
  • 智能 13.1.4
  • 摇篮 1.12
  • 测试是在 Spock 中开发的

任何帮助将不胜感激。谢谢!

4

3 回答 3

2

我在测试中遇到了同样的事情,但 unlockOnStartup 标志对我不起作用。我最终更改了锁定类型(并将 unlockOnStartup 注释掉):

<lockType>${solr.lock.type:single}</lockType>
<!--<unlockOnStartup>true</unlockOnStartup>-->

关于默认锁类型(本机)的注释让我觉得我没有在测试运行之间干净地关闭服务器,但我还没有找到它:(

         native = NativeFSLockFactory - uses OS native file locking.
                  Do not use when multiple solr webapps in the same
                  JVM are attempting to share a single index.
于 2014-10-04T20:33:51.667 回答
0

刚刚遇到类似的问题并解决了。

EmbeddedSolrServer在我的单元测试中使用并在运行时动态创建新内核。

创建时请CoreContainer务必在测试后调用 shutdown()。

还要确保SolrCore在测试后关闭所有实例。

调用coreContainer.create(CoreDescriptor, name, ...)会打开一个 SolrCore,您必须手动关闭它。

通过传递 coreName创建时EmbeddedSolrServer,SolrCore 没有打开!打开和关闭由EmbeddedSolrServer每个请求/操作处理。

于 2015-03-11T10:26:08.127 回答
-1

好的,所以我能够通过更改来解决问题

<unlockOnStartup>true</unlockOnStartup>

在 solrconfig.xml 文件中。

于 2014-09-11T16:55:29.960 回答