Please note that I am not writing unit tests for testing classes in Solr. I need a temporary Solr index to test classes in my own application that needs a Solr index. I would like to use classes that are available in solr-core and solr-solrj jars. I could do this easily in solr-4.x versions using EmbeddedSolrServer. I prefer not to extend SolrTestCaseJ4 class. Also MiniSolrCloudCluster is not available in solr-core or solr-solrj jar.
What is the best way of doing this in Solr-6.x / Solr-7.0 ? -----Original Message----- From: Joe Lawson [mailto:jlaw...@opensourceconnections.com] Sent: 11 April 2016 17:31 To: solr-user@lucene.apache.org Subject: Re: EmbeddedSolr for unit tests in Solr 6 Check for example tests here too: https://github.com/apache/lucene-solr/tree/master/solr/core/src/test/org/apache/solr On Mon, Apr 11, 2016 at 12:24 PM, Shalin Shekhar Mangar < shalinman...@gmail.com> wrote: > Please use MiniSolrCloudCluster instead of EmbeddedSolrServer for > unit/integration tests. > > On Mon, Apr 11, 2016 at 2:26 PM, Rohana Rajapakse < > rohana.rajapa...@gossinteractive.com> wrote: > > > Thanks Shawn, > > > > I am now pointing solrHomeFolder to > > lucene-solr-master\solr\server\solr > > which contains the correct solr.xml file. > > Tried the following two ways to create an EmbeddedSolrServer: > > > > > > 1. CoreContainer corecon = > > CoreContainer.createAndLoad(Paths.get(solrHomeFolder)); > > corecon.load(); > > SolrClient svr = new EmbeddedSolrServer(corecon, > > corename); > > > > > > 2. SolrClient svr = new EmbeddedSolrServer(Paths.get(solrHomeFolder), > > corename); > > > > > > They both throws the same exception (java.lang.NoClassDefFoundError: > > Could not initialize class org.apache.solr.servlet.SolrRequestParsers). > > org.apache.solr.servlet.SolrRequestParsers class is present in the > > solr-core-7.0.0-SNAPSHOT.jar and this jar is present in the > > WEB-INF\lib folder (in solr server) and also included as a > > dependency jar in the pom.xml of the test project. > > > > Here is the full stack trace of the exception: > > > > java.lang.NoClassDefFoundError: Could not initialize class > > org.apache.solr.servlet.SolrRequestParsers > > at > > > org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(Embedd > edSolrServer.java:112) > > at > > > org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(Embedd > edSolrServer.java:70) > > at > > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSo > lrServer(DocPhraseUpdateProcessorTest.java:141) > > at > > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseU > pdateProcessorTest.java:99) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j > ava:62) > > at > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess > orImpl.java:43) > > at java.lang.reflect.Method.invoke(Method.java:497) > > at > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkM > ethod.java:44) > > at > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCall > able.java:15) > > at > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMet > hod.java:41) > > at > > > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.j > ava:27) > > at > > > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.jav > a:31) > > at > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn > er.java:73) > > at > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunn > er.java:46) > > at > > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) > > at > org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) > > at > org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) > > at > > > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.j > ava:28) > > at > > > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.jav > a:31) > > at org.junit.runners.ParentRunner.run(ParentRunner.java:220) > > at > > > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4T > estReference.java:50) > > at > > > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution. > java:38) > > at > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote > TestRunner.java:467) > > at > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote > TestRunner.java:683) > > at > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR > unner.java:390) > > at > > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTest > Runner.java:197) > > > > > > I have debugged this a bit and found that this exception is thrown > > on the following line in EmbeddedServer.class > > > > _parser = new SolrRequestParsers(null); > > > > Also, the coreContainer object has no cores at this point. > > > > > > Wonder if I should update my code from master (it is now about two > > weeks old). > > > > Thanks for any help. > > > > Rohana > > > > > > -----Original Message----- > > From: Shawn Heisey [mailto:apa...@elyograg.org] > > Sent: 08 April 2016 16:46 > > To: solr-user@lucene.apache.org > > Subject: Re: EmbeddedSolr for unit tests in Solr 6 > > > > On 4/8/2016 7:51 AM, Rohana Rajapakse wrote: > > > Thanks. I know it exists, but don't know how to use it. > > > > > > I am trying to use EmbeddedSolrServer(Path solrHome, String > > > defaultCoreName) > > > > > > What should be the "solrHome"? Should it be the actual solr home (i.e. > > lucene-solr-master\solr\server\solr) in the solr server, or can it > > be any temporary folder? > > > > > > I create it with: new EmbeddedSolrServer((new > > File("testdata/solr")).toPath(), "tmpcore"); and get the following > > Exception (I use solr-Solr-7.0.0): > > > > > > org.apache.solr.common.SolrException: Should not have found > > > solr/@persistent . Please upgrade your solr.xml: > > https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml > > > at > > org.apache.solr.core.SolrXmlConfig.failIfFound(SolrXmlConfig.java:16 > > 7) > > > at > > > org.apache.solr.core.SolrXmlConfig.checkForIllegalConfig(SolrXmlConfig > .java:149) > > > at > > org.apache.solr.core.SolrXmlConfig.fromConfig(SolrXmlConfig.java:61) > > > at > > > org.apache.solr.core.SolrXmlConfig.fromInputStream(SolrXmlConfig.java: > 129) > > > at > > org.apache.solr.core.SolrXmlConfig.fromFile(SolrXmlConfig.java:111) > > > at > > org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:1 > > 39) > > > at > > org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:1 > > 44) > > > at > > > org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(Embedd > edSolrServer.java:70) > > > at > > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSo > lrServer(DocPhraseUpdateProcessorTest.java:140) > > > at > > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhr > > > aseU > > > pdateProcessorTest.java:98) > > > > You said you were using EmbeddedSolrServer with 4.x, so I assumed > > you > knew > > what you were doing. > > > > You are getting that Exception because the solr home you pointed to > > contains a solr.xml file in the old solr.xml format. This format is > > supported by all of 4.x, but support was dropped in 5.0. The > > message is pretty clear -- it says that you need to upgrade your > > solr.xml, and even points at some documentation. Here's a wiki page > > about the old format, with a link to another page about the new format: > > > > http://wiki.apache.org/solr/Solr.xml%20%28supported%20through%204.x% > > 29 > > > > Suggestion: Rather than create a File object and convert it to a > > Path, > use > > NIO2 methods directly: > > > > Paths.get("testdata/solr") > > > > Thanks, > > Shawn > > > > > > > > Registered Office: 24 Darklake View, Estover, Plymouth, PL6 7TL. > > Company Registration No: 3553908 > > > > This email contains proprietary information, some or all of which > > may be legally privileged. It is for the intended recipient only. If > > an > addressing > > or transmission error has misdirected this email, please notify the > author > > by replying to this email. If you are not the intended recipient you > > may not use, disclose, distribute, copy, print or rely on this email. > > > > Email transmission cannot be guaranteed to be secure or error free, > > as information may be intercepted, corrupted, lost, destroyed, > > arrive late > or > > incomplete or contain viruses. This email and any files attached to > > it > have > > been checked with virus detection software before transmission. You > should > > nonetheless carry out your own virus check before opening any attachment. > > GOSS Interactive Ltd accepts no liability for any loss or damage > > that may be caused by software viruses. > > > > > > > > > -- > Regards, > Shalin Shekhar Mangar. >