You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Rohana Rajapakse <Ro...@gossinteractive.com> on 2016/04/08 10:35:05 UTC

EmbeddedSolr for unit tests in Solr 6

Hi,

Can someone please tell me how to create a temporary Solr server programmatically for the use of Unit Tests? I was using EmbeddedSolrServer in Solr 4.x. How do you do thi in Solr 6.x?

Thanks in advance for any help,

Rohana




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.



RE: EmbeddedSolr for unit tests in Solr 6

Posted by Rohana Rajapakse <Ro...@gossinteractive.com>.
Thanks Shalin,

I am now trying to use MiniSolrCloudCluster to create mini cluster in solr 6/7 as below:
 
MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(1, temp_folder_path, path_to_solr.xml, null);


It throws the following exception:

org.apache.zookeeper.KeeperException$NodeExistsException: KeeperErrorCode = NodeExists for /solr/solr.xml
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:119)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
	at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783)
	at org.apache.solr.common.cloud.SolrZkClient$10.execute(SolrZkClient.java:503)
	at org.apache.solr.common.cloud.ZkCmdExecutor.retryOperation(ZkCmdExecutor.java:60)
	at org.apache.solr.common.cloud.SolrZkClient.makePath(SolrZkClient.java:500)
	at org.apache.solr.common.cloud.SolrZkClient.makePath(SolrZkClient.java:458)
	at org.apache.solr.common.cloud.SolrZkClient.makePath(SolrZkClient.java:445)
	at org.apache.solr.common.cloud.SolrZkClient.makePath(SolrZkClient.java:432)
	at org.apache.solr.cloud.MiniSolrCloudCluster.<init>(MiniSolrCloudCluster.java:199)
	at org.apache.solr.cloud.MiniSolrCloudCluster.<init>(MiniSolrCloudCluster.java:168)
	at com.gossinteractive.solr.TestMiniSolrCloudCluster.setup(TestMiniSolrCloudCluster.java:52)
	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:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


This is a Zookeeper exception and I cannot figure out what is wrong. Can someone shed some light please?

Rohana


-----Original Message-----
From: Shalin Shekhar Mangar [mailto:shalinmangar@gmail.com] 
Sent: 12 April 2016 13:19
To: solr-user@lucene.apache.org
Subject: Re: EmbeddedSolr for unit tests in Solr 6

Rohana, as I said earlier, the MiniSolrCloudCluster is specifically made for your use-case i.e. where you want to quickly setup a SolrCloud cluster in your own application for testing. It is available in the solr-test-framework artifact.

On Tue, Apr 12, 2016 at 4:31 PM, Rohana Rajapakse < Rohana.Rajapakse@gossinteractive.com> wrote:

> 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:jlawson@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/o
> rg/apache/solr
>
> On Mon, Apr 11, 2016 at 12:24 PM, Shalin Shekhar Mangar < 
> shalinmangar@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.Rajapakse@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>(Embe
> > dd
> > edSolrServer.java:112)
> > >         at
> > >
> > org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(Embe
> > dd
> > edSolrServer.java:70)
> > >         at
> > >
> > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbedded
> > So
> > lrServer(DocPhraseUpdateProcessorTest.java:141)
> > >         at
> > >
> > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhras
> > eU
> > pdateProcessorTest.java:99)
> > >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >         at
> > >
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
> > .j
> > ava:62)
> > >         at
> > >
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
> > ss
> > orImpl.java:43)
> > >         at java.lang.reflect.Method.invoke(Method.java:497)
> > >         at
> > >
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framewor
> > kM
> > ethod.java:44)
> > >         at
> > >
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCa
> > ll
> > able.java:15)
> > >         at
> > >
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkM
> > et
> > hod.java:41)
> > >         at
> > >
> > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores
> > .j
> > ava:27)
> > >         at
> > >
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.j
> > av
> > a:31)
> > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > er.java:73)
> > >         at
> > >
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRu
> > nn
> > 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.j
> > av
> > a:31)
> > >         at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit
> > 4T
> > estReference.java:50)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.
> > java:38)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:467)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remo
> > te
> > TestRunner.java:683)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTes
> > tR
> > unner.java:390)
> > >         at
> > >
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTe
> > st
> > 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:apache@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.xm
> > > l
> > > >       at
> > > org.apache.solr.core.SolrXmlConfig.failIfFound(SolrXmlConfig.java:
> > > 16
> > > 7)
> > > >       at
> > >
> > org.apache.solr.core.SolrXmlConfig.checkForIllegalConfig(SolrXmlConf
> > ig
> > .java:149)
> > > >       at
> > > org.apache.solr.core.SolrXmlConfig.fromConfig(SolrXmlConfig.java:6
> > > 1)
> > > >       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>(Embe
> > dd
> > edSolrServer.java:70)
> > > >       at
> > >
> > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbedded
> > So
> > lrServer(DocPhraseUpdateProcessorTest.java:140)
> > > >       at
> > > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocP
> > > > hr
> > > > 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.
> >
>



--
Regards,
Shalin Shekhar Mangar.

Re: EmbeddedSolr for unit tests in Solr 6

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Rohana, as I said earlier, the MiniSolrCloudCluster is specifically made
for your use-case i.e. where you want to quickly setup a SolrCloud cluster
in your own application for testing. It is available in
the solr-test-framework artifact.

On Tue, Apr 12, 2016 at 4:31 PM, Rohana Rajapakse <
Rohana.Rajapakse@gossinteractive.com> wrote:

> 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:jlawson@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 <
> shalinmangar@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.Rajapakse@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:apache@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.
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

RE: EmbeddedSolr for unit tests in Solr 6

Posted by Rohana Rajapakse <Ro...@gossinteractive.com>.
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:jlawson@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 < shalinmangar@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.Rajapakse@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:apache@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.
>

Re: EmbeddedSolr for unit tests in Solr 6

Posted by Joe Lawson <jl...@opensourceconnections.com>.
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 <
shalinmangar@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.Rajapakse@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>(EmbeddedSolrServer.java:112)
> >         at
> >
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
> >         at
> >
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:141)
> >         at
> >
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.java:99)
> >         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:497)
> >         at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> >         at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> >         at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> >         at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> >         at
> >
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.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.java:28)
> >         at
> >
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> >         at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> >         at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.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:apache@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:167)
> > >       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:139)
> > >       at
> > org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
> > >       at
> >
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
> > >       at
> >
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
> > >       at
> > > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseU
> > > 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.
>

Re: EmbeddedSolr for unit tests in Solr 6

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Please use MiniSolrCloudCluster instead of EmbeddedSolrServer for
unit/integration tests.

On Mon, Apr 11, 2016 at 2:26 PM, Rohana Rajapakse <
Rohana.Rajapakse@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>(EmbeddedSolrServer.java:112)
>         at
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
>         at
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:141)
>         at
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.java:99)
>         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:497)
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>         at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
>         at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.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.java:28)
>         at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.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:apache@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:167)
> >       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:139)
> >       at
> org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
> >       at
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
> >       at
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
> >       at
> > com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseU
> > 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.

RE: EmbeddedSolr for unit tests in Solr 6

Posted by Rohana Rajapakse <Ro...@gossinteractive.com>.
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>(EmbeddedSolrServer.java:112)
	at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:141)
	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.java:99)
	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:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.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.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.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:apache@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:167)
> 	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:139)
> 	at org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
> 	at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
> 	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
> 	at 
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseU
> 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.



Re: EmbeddedSolr for unit tests in Solr 6

Posted by Shawn Heisey <ap...@elyograg.org>.
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:167)
> 	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:139)
> 	at org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
> 	at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
> 	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
> 	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.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


RE: EmbeddedSolr for unit tests in Solr 6

Posted by Rohana Rajapakse <Ro...@gossinteractive.com>.
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:167)
	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:139)
	at org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
	at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
	at com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.java:98)
                ...


-----Original Message-----
From: Shawn Heisey [mailto:apache@elyograg.org] 
Sent: 08 April 2016 14:35
To: solr-user@lucene.apache.org
Subject: Re: EmbeddedSolr for unit tests in Solr 6

On 4/8/2016 2:35 AM, Rohana Rajapakse wrote:
> Can someone please tell me how to create a temporary Solr server programmatically for the use of Unit Tests? I was using EmbeddedSolrServer in Solr 4.x. How do you do thi in Solr 6.x?

EmbeddedSolrServer still exists in 6.x.

There may be *minor* differences in usage -- you are upgrading two major releases -- but if there are, they shouldn't be too hard to figure out.

https://www.dropbox.com/s/iokyb3wijtaz7xg/embeddedsolrserver.png?dl=0
https://lucene.apache.org/solr/6_0_0/solr-core/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.html

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.



Re: EmbeddedSolr for unit tests in Solr 6

Posted by Shawn Heisey <ap...@elyograg.org>.
On 4/8/2016 2:35 AM, Rohana Rajapakse wrote:
> Can someone please tell me how to create a temporary Solr server programmatically for the use of Unit Tests? I was using EmbeddedSolrServer in Solr 4.x. How do you do thi in Solr 6.x?

EmbeddedSolrServer still exists in 6.x.

There may be *minor* differences in usage -- you are upgrading two major
releases -- but if there are, they shouldn't be too hard to figure out.

https://www.dropbox.com/s/iokyb3wijtaz7xg/embeddedsolrserver.png?dl=0
https://lucene.apache.org/solr/6_0_0/solr-core/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.html

Thanks,
Shawn