commun bug
Your bug is very commun, and the official blog is explaining it clearly. Take care with Solr embedded Server, it's not recommanded by SOLR itself!!!
As said on the official solr embbeded uri:
The simplest, safest, way to use Solr is via Solr's standard HTTP
interfaces. Embedding Solr is less flexible, harder to support, not as
well tested, and should be reserved for special circumstances.
A question of choice : "Keep running unit test server" or run it "on the fly"
I suggest you to do the same thing as we are doing in order to unit test,
- run a dedicated solr server, or
- run one on the fly
To run a solr server inside the maven build, you can use CARGO:
- To launch the build and unit test we are using maven
- we lauch test automaticaly on Solr
- we lauch on startup of the test a solr instance "on the fly" and closes it using the conainMaven Cargo
- At the end of the junit we close Cargo ! :)
Easy and clean ! Enjoy :)
Exemple of cargo maven code :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.8</version>
<executions>
<execution>
<id>start-container</id>
<phase>process-test-resources</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<configuration>
<properties>
<cargo.servlet.port>8966</cargo.servlet.port>
</properties>
</configuration>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
<systemProperties>
<solr.solr.home>${basedir}/target/solr</solr.solr.home>
<!-- log4j.configuration>file://${basedir}/src/test/resources/log4j.properties</log4j.configuration -->
<log4j.debug>true</log4j.debug>
<net.sourceforge.cobertura.datafile>target/cobertura/cobertura.ser</net.sourceforge.cobertura.datafile>
</systemProperties>
<dependencies>
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
</dependencies>
</container>
<deployables>
<deployable>
<groupId>org.apache.solr</groupId>
<artifactId>solr</artifactId>
<type>war</type>
<properties>
<context>/solr</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>