I have written a search component to be used with SOLR. I want to debug it. I tried debugging the SOLR itself using remote debugging feature of eclipse but it doesn't work for plugin and shows source not found.
Then I tried including my plugin project as source project but that did not work either. The debugger doesn't stops at breakpoints for plugin.
Any help in this regard shall be greatly appreciated!
答案 0 :(得分:0)
您可以使用嵌入式solr在eclipse项目中编写Junit测试。这使调试更容易。您需要做的就是为您的测试资源目录创建solr-core的配置文件(solrconfig.xml,schema.xml等;您可以从solr安装中复制solr核心dir)并指向CoreContainer到该目录。此核心容器可用于获取配置的solr核心和搜索器。 JUnit和Solr-core是所需的依赖项。
以下是测试代码的示例:
/**
* This is a starting point for testing the component with embedded solr!
*/
public class SearchComponentTest
{
private static CoreContainer container;
private static SolrCore core;
private static final Logger logger = LoggerFactory.getLogger(DataImportRequestHandlerTest.class.getName());
/*
* PREPARE AND TEAR DOWN FOR TESTS
*/
@BeforeClass
public static void prepareClass() throws Exception
{
// create the coreContainer from conf dir in test resources
container = new CoreContainer(
DataImportRequestHandlerTest.class.getResource("/solrDir").getPath().substring(1));
container.load();
core = container.getCore("CORENAME");
logger.info("Solr core loaded!");
}
@AfterClass
public static void cleanUpClass()
{
core.close();
container.shutdown();
logger.info("Solr core shut down!");
}
/* TESTS TO RUN */
/**
* Test the search component here or just trigger it to debug
*/
@Test
public void testSearchComponent()
{
/* PREPARE */
SearchComponent mySearchComp = core.getSearchComponent("componentNameFromSolrConf");
/* RUN */
// do something with your search component
/* CHECK */
// check results with asserts :)
}
}