multithreading - Random Neo4j database location for Embedded Jersey Tests -
i'm using com.sun.jersey.test.framework.jerseytest create junit tests jersey application. application uses neo4j spring data load data , return via rest api.
the test starts embedded grizzly server jersey neo4j spring data webapp. after i'm able invoke rest requests , create nodes in neo4j database. unfortunately test fixed single neo4j database location since configured within applicationcontext.xml so:
<neo4j:config storedirectory="/tmp/myapp/neo4jdb" />
my test fail if excute similar test @ same time because same directory used , 1 neo4j can obtain lock.
i know springjunit4classrunner can't use because have neo4j instance running within embedded server.
@contextconfiguration(locations = "classpath:/spring/applicationcontext.xml") @runwith(springjunit4classrunner.class) @transactional
the test should create neo4j database in random directory.
questions:
- is there way change storedirectory , clear neo4j database. changing storedirectory in setuponce well.
- is there way clear neo4j database. (i can't autowire in test because not part of spring context)
i'm using java-based bean configuration:
package com.gentics.sandboxmanager.service; import java.io.file; import java.io.ioexception; import java.nio.file.files; import org.neo4j.kernel.embeddedgraphdatabase; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.data.neo4j.config.enableneo4jrepositories; import org.springframework.data.neo4j.config.jtatransactionmanagerfactorybean; import org.springframework.data.neo4j.config.neo4jconfiguration; import org.springframework.data.neo4j.support.neo4jexceptiontranslator; import org.springframework.data.neo4j.support.neo4jtemplate; import org.springframework.data.neo4j.support.mapping.neo4jmappingcontext; @enableneo4jrepositories(basepackages = "com.gentics.sandboxmanager.repository") @configuration public class neo4jconfig extends neo4jconfiguration { private static file databaselocation; private static embeddedgraphdatabase neo4jdb; /** * returns neo4j database * * @return */ public static embeddedgraphdatabase getneo4jdatabase() { return neo4jdb; } @bean public embeddedgraphdatabase graphdatabaseservice() throws ioexception { // todo use properties app not use temp dir databaselocation = files.createtempdirectory("neo4j").tofile(); databaselocation.deleteonexit(); neo4jdb = new embeddedgraphdatabase(databaselocation.getabsolutepath()); return neo4jdb; } @bean public neo4jtemplate neo4jtemplate() throws ioexception { return new neo4jtemplate(graphdatabaseservice()); } @bean public neo4jmappingcontext neo4jmappingcontext() { return new neo4jmappingcontext(); } @bean public jtatransactionmanagerfactorybean transactionmanager() throws exception { return new jtatransactionmanagerfactorybean(graphdatabaseservice()); } @bean public neo4jexceptiontranslator exceptiontranslator() { return new neo4jexceptiontranslator(); } }
each jerseytest testcase restart webapp. neo4j therefore use empty neo4j database.
additonal links:
Comments
Post a Comment