You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by Eric Pugh <ep...@opensourceconnections.com> on 2007/06/27 20:22:33 UTC

Running Unit Tests from inside Eclipse

Hi all,

I always run into path issues when running the unit tests from inside  
of Eclipse...

For example, when I run TestCSVLoader.java I get

java.lang.ExceptionInInitializerError
	at org.apache.solr.util.TestHarness.<init>(TestHarness.java:101)
	at org.apache.solr.util.AbstractSolrTestCase.setUp 
(AbstractSolrTestCase.java:102)
	at org.apache.solr.handler.TestCSVLoader.setUp(TestCSVLoader.java:43)
	at junit.framework.TestCase.runBare(TestCase.java:125)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at  
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run 
(JUnit3TestReference.java:128)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run 
(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests 
(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests 
(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run 
(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main 
(RemoteTestRunner.java:196)
Caused by: java.lang.RuntimeException: Error in solrconfig.xml
	at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:90)
	... 16 more
Caused by: java.lang.RuntimeException: Can't find resource  
'solrconfig.xml' in classpath or 'solr/conf/', cwd=/Users/eric/ 
Documents/code/oss/apache/solr/trunk
	at org.apache.solr.core.Config.openResource(Config.java:357)
	at org.apache.solr.core.SolrConfig.initConfig(SolrConfig.java:79)
	at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:87)
	... 16 more


I have a tweak that gives it an alternate path to look up the  
file...  Would that be of interest to anyone as a patch file?   Is  
there a specific way to config my Eclipse project to find the path?

Eric Pugh





-------------------------------------------------------
Principal
OpenSource Connections
Site: http://www.opensourceconnections.com
Blog: http://blog.opensourceconnections.com
Cell: 1-434-466-1467





Re: Running Unit Tests from inside Eclipse

Posted by Yonik Seeley <yo...@apache.org>.
On 6/28/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> > >  I have a PDF handler modeled on the CSVHandler that allows
> > > you to stream a PDF document to Solr and extract the text and store
> > > it.
> >
> > Cool!
> >
> > Any thoughts of a general framework for going from unstructured
> > document -> lucene document with fields?  It feels like utilizing
> > Apache Tika here would be the way to go (although it's in the really
> > early stages).
> >
> > -Yonik
> >
> Humm...  So I have a PDF, Word, Excel, and Powerpoint, all as seperate
> handlers.  And there is a lot of duplication between them...  I may
> try and pull out the common stuff into some sort of
> AbstractRichDocumentHandler, and then just add the special sauce for
> each one.   I am close to having the basic unit tests, modeled on
> CSVHandler, and will post a JIRA issue with it.

Another thing to consider is document type/charset/language detection.
People may not want to have to hit a different URL for each different
type of document.

> I looked for Tika, but didn't see it, what is the URL?

It's *really* early (entered the incubator in March)
http://incubator.apache.org/tika/
http://www.nabble.com/Apache-Tika---Development-f20913.html


-Yonik

Re: Running Unit Tests from inside Eclipse

Posted by Eric Pugh <ep...@opensourceconnections.com>.
>
> >  I have a PDF handler modeled on the CSVHandler that allows
> > you to stream a PDF document to Solr and extract the text and store
> > it.
>
> Cool!
>
> Any thoughts of a general framework for going from unstructured
> document -> lucene document with fields?  It feels like utilizing
> Apache Tika here would be the way to go (although it's in the really
> early stages).
>
> -Yonik
>
Humm...  So I have a PDF, Word, Excel, and Powerpoint, all as seperate
handlers.  And there is a lot of duplication between them...  I may
try and pull out the common stuff into some sort of
AbstractRichDocumentHandler, and then just add the special sauce for
each one.   I am close to having the basic unit tests, modeled on
CSVHandler, and will post a JIRA issue with it.

I looked for Tika, but didn't see it, what is the URL?

Re: Running Unit Tests from inside Eclipse

Posted by Yonik Seeley <yo...@apache.org>.
On 6/28/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> Sounds great to me!  In the future, should I be communicating via JIRA
> issues?

Code should go in JIRA issues, but you can discuss it before hand on
the dev list if you like.

>  I have a PDF handler modeled on the CSVHandler that allows
> you to stream a PDF document to Solr and extract the text and store
> it.

Cool!

Any thoughts of a general framework for going from unstructured
document -> lucene document with fields?  It feels like utilizing
Apache Tika here would be the way to go (although it's in the really
early stages).

-Yonik

Re: Running Unit Tests from inside Eclipse

Posted by Eric Pugh <ep...@opensourceconnections.com>.
On 6/28/07, Yonik Seeley <yo...@apache.org> wrote:
> On 6/28/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> > In the case of the unit tests and  though, it seems like a
> > simplification of the tests to make them not dependent on external
> > configuration that is provided via Ant or any other tool....
>
> Yes, I agree.
>
> Any objections to committing the setProperty part?
>
> -Yonik
>

Sounds great to me!  In the future, should I be communicating via JIRA
issues?  I have a PDF handler modeled on the CSVHandler that allows
you to stream a PDF document to Solr and extract the text and store
it.

Re: Running Unit Tests from inside Eclipse

Posted by Chris Hostetter <ho...@fucit.org>.
: > In the case of the unit tests and  though, it seems like a
: > simplification of the tests to make them not dependent on external
: > configuration that is provided via Ant or any other tool....
:
: Yes, I agree.
:
: Any objections to committing the setProperty part?

i'm still not sure what we're talking about exactly (am i the only one not
getting the attachments?) but i'm okay with changing tests to make them
run more universally ... i was just leary of some mentioned changes to
Config.java (not that i know what they were mind you .. jus that it seemed
odd to need to change the actual code to get the tests to run in an IDE).



-Hoss


Re: Running Unit Tests from inside Eclipse

Posted by Yonik Seeley <yo...@apache.org>.
On 6/28/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> In the case of the unit tests and  though, it seems like a
> simplification of the tests to make them not dependent on external
> configuration that is provided via Ant or any other tool....

Yes, I agree.

Any objections to committing the setProperty part?

-Yonik

Re: Running Unit Tests from inside Eclipse

Posted by Eric Pugh <ep...@opensourceconnections.com>.
I agree with the thought about bending your code to fit your IDE.

In the case of the unit tests and  though, it seems like a  
simplification of the tests to make them not dependent on external  
configuration that is provided via Ant or any other tool....   Coming  
from the "new to Solr and don't know the ins and outs" end of things!

Hence why I like defining the System properties inside the Java test  
code.

Eric Pugh


On Jun 27, 2007, at 4:11 PM, Chris Hostetter wrote:

> : the path in Config.java.  Attached is a patch file for these two
> : changes.....
>
> FYI; apache mailing lists strip most attachments ... i think it  
> works if
> hte mime-type is text/plain, but the simplest thing to do is just  
> include
> it inline in your message.
>
> (as a general philosophy, i'm opposed to code changes solely for the
> purpose of making IDEs happy ... IDEs should make developing code  
> easier,
> not hte other way arround)
>
>
>
> -Hoss
>

-------------------------------------------------------
Principal
OpenSource Connections
Site: http://www.opensourceconnections.com
Blog: http://blog.opensourceconnections.com
Cell: 1-434-466-1467





Re: Running Unit Tests from inside Eclipse

Posted by Chris Hostetter <ho...@fucit.org>.
: the path in Config.java.  Attached is a patch file for these two
: changes.....

FYI; apache mailing lists strip most attachments ... i think it works if
hte mime-type is text/plain, but the simplest thing to do is just include
it inline in your message.

(as a general philosophy, i'm opposed to code changes solely for the
purpose of making IDEs happy ... IDEs should make developing code easier,
not hte other way arround)



-Hoss


Re: Running Unit Tests from inside Eclipse

Posted by Ryan McKinley <ry...@gmail.com>.
You need to add something like:
"-Dsolr.test.sys.prop1=xxx -Dsolr.test.sys.prop2=xxx" to the VM 
arguments in the Run panel.

It is kind of annoying they are required for all tests...  ideally we 
would move the schema property testing to an independent test, but that 
has not happend yet.


Eric Pugh wrote:
> I was wondering about that, but also, how do you handle the two system 
> properties?
> 
> I added to   public TestHarness(String dataDirectory,
>                      String confFile,
>                      String schemaFile) {
> 
> these lines:
> 
> System.setProperty("solr.test.sys.prop1", "propone");
> System.setProperty("solr.test.sys.prop2", "proptwo");
> 
> Otherwise I always got an error about a missing system property.  
> Normally, via Ant, these are passed in via the JUnit test definition.  
> Would this change be worth an issue in Jira and a patch file?
> 
> Also, mucking around with working-directories didn't work, so I added 
> the path in Config.java.  Attached is a patch file for these two 
> changes.....
> 
> Eric
> 
> 
> 
> 
> On Jun 27, 2007, at 2:29 PM, Yonik Seeley wrote:
> 
>> I tell IntelliJ IDEA to set the working directory for all the tests to
>> F:\code\solr\src\test\test-files
>>
>> -Yonik
>>
>> On 6/27/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
>>> Hi all,
>>>
>>> I always run into path issues when running the unit tests from inside
>>> of Eclipse...
>>>
>>> For example, when I run TestCSVLoader.java I get
>>>
>>> java.lang.ExceptionInInitializerError
>>>         at org.apache.solr.util.TestHarness.<init>(TestHarness.java:101)
>>>         at org.apache.solr.util.AbstractSolrTestCase.setUp
>>> (AbstractSolrTestCase.java:102)
>>>         at 
>>> org.apache.solr.handler.TestCSVLoader.setUp(TestCSVLoader.java:43)
>>>         at junit.framework.TestCase.runBare(TestCase.java:125)
>>>         at junit.framework.TestResult$1.protect(TestResult.java:106)
>>>         at junit.framework.TestResult.runProtected(TestResult.java:124)
>>>         at junit.framework.TestResult.run(TestResult.java:109)
>>>         at junit.framework.TestCase.run(TestCase.java:118)
>>>         at junit.framework.TestSuite.runTest(TestSuite.java:208)
>>>         at junit.framework.TestSuite.run(TestSuite.java:203)
>>>         at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run
>>> (JUnit3TestReference.java:128)
>>>         at org.eclipse.jdt.internal.junit.runner.TestExecution.run
>>> (TestExecution.java:38)
>>>         at 
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
>>> (RemoteTestRunner.java:460)
>>>         at 
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
>>> (RemoteTestRunner.java:673)
>>>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
>>> (RemoteTestRunner.java:386)
>>>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
>>> (RemoteTestRunner.java:196)
>>> Caused by: java.lang.RuntimeException: Error in solrconfig.xml
>>>         at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:90)
>>>         ... 16 more
>>> Caused by: java.lang.RuntimeException: Can't find resource
>>> 'solrconfig.xml' in classpath or 'solr/conf/', cwd=/Users/eric/
>>> Documents/code/oss/apache/solr/trunk
>>>         at org.apache.solr.core.Config.openResource(Config.java:357)
>>>         at 
>>> org.apache.solr.core.SolrConfig.initConfig(SolrConfig.java:79)
>>>         at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:87)
>>>         ... 16 more
>>>
>>>
>>> I have a tweak that gives it an alternate path to look up the
>>> file...  Would that be of interest to anyone as a patch file?   Is
>>> there a specific way to config my Eclipse project to find the path?
>>>
>>> Eric Pugh
>>>
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------
>>> Principal
>>> OpenSource Connections
>>> Site: http://www.opensourceconnections.com
>>> Blog: http://blog.opensourceconnections.com
>>> Cell: 1-434-466-1467
>>>
>>>
>>>
>>>
>>>
> 
> -------------------------------------------------------
> Principal
> OpenSource Connections
> Site: http://www.opensourceconnections.com
> Blog: http://blog.opensourceconnections.com
> Cell: 1-434-466-1467
> 
> 
> 
> 


Re: Running Unit Tests from inside Eclipse

Posted by Yonik Seeley <yo...@apache.org>.
On 6/27/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> I added to   public TestHarness(String dataDirectory,
>                       String confFile,
>                       String schemaFile) {
>
> these lines:
>
> System.setProperty("solr.test.sys.prop1", "propone");
> System.setProperty("solr.test.sys.prop2", "proptwo");
>
> Otherwise I always got an error about a missing system property.
> Normally, via Ant, these are passed in via the JUnit test
> definition.  Would this change be worth an issue in Jira and a patch
> file?

Yes, either this, or make those specific tests use a separate config.

> Also, mucking around with working-directories didn't work, so I added
> the path in Config.java.  Attached is a patch file for these two
> changes.....

Hmmm, don't know why fixing the working directory wouldn't work for
you... anyone else use Eclipse?

-Yonik

Re: Running Unit Tests from inside Eclipse

Posted by Eric Pugh <ep...@opensourceconnections.com>.
I was wondering about that, but also, how do you handle the two  
system properties?

I added to   public TestHarness(String dataDirectory,
                      String confFile,
                      String schemaFile) {

these lines:

System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");

Otherwise I always got an error about a missing system property.   
Normally, via Ant, these are passed in via the JUnit test  
definition.  Would this change be worth an issue in Jira and a patch  
file?

Also, mucking around with working-directories didn't work, so I added  
the path in Config.java.  Attached is a patch file for these two  
changes.....

Eric

Re: Running Unit Tests from inside Eclipse

Posted by Yonik Seeley <yo...@apache.org>.
I tell IntelliJ IDEA to set the working directory for all the tests to
F:\code\solr\src\test\test-files

-Yonik

On 6/27/07, Eric Pugh <ep...@opensourceconnections.com> wrote:
> Hi all,
>
> I always run into path issues when running the unit tests from inside
> of Eclipse...
>
> For example, when I run TestCSVLoader.java I get
>
> java.lang.ExceptionInInitializerError
>         at org.apache.solr.util.TestHarness.<init>(TestHarness.java:101)
>         at org.apache.solr.util.AbstractSolrTestCase.setUp
> (AbstractSolrTestCase.java:102)
>         at org.apache.solr.handler.TestCSVLoader.setUp(TestCSVLoader.java:43)
>         at junit.framework.TestCase.runBare(TestCase.java:125)
>         at junit.framework.TestResult$1.protect(TestResult.java:106)
>         at junit.framework.TestResult.runProtected(TestResult.java:124)
>         at junit.framework.TestResult.run(TestResult.java:109)
>         at junit.framework.TestCase.run(TestCase.java:118)
>         at junit.framework.TestSuite.runTest(TestSuite.java:208)
>         at junit.framework.TestSuite.run(TestSuite.java:203)
>         at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run
> (JUnit3TestReference.java:128)
>         at org.eclipse.jdt.internal.junit.runner.TestExecution.run
> (TestExecution.java:38)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRunner.java:460)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRunner.java:673)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
> (RemoteTestRunner.java:386)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
> (RemoteTestRunner.java:196)
> Caused by: java.lang.RuntimeException: Error in solrconfig.xml
>         at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:90)
>         ... 16 more
> Caused by: java.lang.RuntimeException: Can't find resource
> 'solrconfig.xml' in classpath or 'solr/conf/', cwd=/Users/eric/
> Documents/code/oss/apache/solr/trunk
>         at org.apache.solr.core.Config.openResource(Config.java:357)
>         at org.apache.solr.core.SolrConfig.initConfig(SolrConfig.java:79)
>         at org.apache.solr.core.SolrConfig.<clinit>(SolrConfig.java:87)
>         ... 16 more
>
>
> I have a tweak that gives it an alternate path to look up the
> file...  Would that be of interest to anyone as a patch file?   Is
> there a specific way to config my Eclipse project to find the path?
>
> Eric Pugh
>
>
>
>
>
> -------------------------------------------------------
> Principal
> OpenSource Connections
> Site: http://www.opensourceconnections.com
> Blog: http://blog.opensourceconnections.com
> Cell: 1-434-466-1467
>
>
>
>
>